2011-03-11 16:08:41 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Repository do
|
2013-04-24 11:41:43 +01:00
|
|
|
before { stub_symlink_methods }
|
|
|
|
|
2014-03-18 21:12:39 +00:00
|
|
|
let(:repository) { FactoryGirl.create(:repository) }
|
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
context 'ensures that validations and associations exist' do
|
2014-03-18 21:12:39 +00:00
|
|
|
|
|
|
|
it 'is valid given valid attributes' do
|
2015-02-19 01:12:08 +00:00
|
|
|
repository.should be_truthy
|
2013-04-24 11:41:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { should belong_to(:platform) }
|
|
|
|
it { should have_many(:project_to_repositories).validate(true) }
|
|
|
|
it { should have_many(:projects).through(:project_to_repositories) }
|
|
|
|
|
|
|
|
it { should validate_presence_of(:name) }
|
2014-03-18 21:12:39 +00:00
|
|
|
|
|
|
|
context 'uniqueness' do
|
|
|
|
before { repository }
|
|
|
|
it { should validate_uniqueness_of(:name).case_insensitive.scoped_to(:platform_id) }
|
|
|
|
end
|
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
it { should allow_value('basic_repository-name-1234').for(:name) }
|
|
|
|
it { should_not allow_value('.!').for(:name) }
|
|
|
|
it { should_not allow_value('Main').for(:name) }
|
|
|
|
it { should_not allow_value("!!\nbang_bang\n!!").for(:name) }
|
|
|
|
it { should validate_presence_of(:description) }
|
|
|
|
|
|
|
|
it { should have_readonly_attribute(:name) }
|
|
|
|
it { should have_readonly_attribute(:platform_id) }
|
|
|
|
|
|
|
|
it { should_not allow_mass_assignment_of(:platform) }
|
|
|
|
it { should_not allow_mass_assignment_of(:platform_id) }
|
|
|
|
|
|
|
|
end
|
2011-12-08 14:03:56 +00:00
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
context '#sync_lock_file_exists?, #add_sync_lock_file, #remove_sync_lock_file, #add_repo_lock_file, #remove_repo_lock_file' do
|
2014-03-18 21:12:39 +00:00
|
|
|
let(:repository) { FactoryGirl.build(:repository) }
|
2013-07-29 11:46:49 +01:00
|
|
|
let(:path) { "#{repository.platform.path}/repository/SRPMS/#{repository.name}" }
|
|
|
|
before { FileUtils.mkdir_p path }
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #sync_lock_file_exists? returns false if .sync.lock file does not exist' do
|
2015-02-19 01:12:08 +00:00
|
|
|
repository.sync_lock_file_exists?.should be_falsy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #sync_lock_file_exists? returns true if .sync.lock file does exist' do
|
2013-07-29 11:46:49 +01:00
|
|
|
FileUtils.touch "#{path}/.sync.lock"
|
2015-02-19 01:12:08 +00:00
|
|
|
repository.sync_lock_file_exists?.should be_truthy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #add_sync_lock_file creates .sync.lock file' do
|
|
|
|
repository.add_sync_lock_file
|
2015-02-19 01:12:08 +00:00
|
|
|
File.exist?("#{path}/.sync.lock").should be_truthy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #remove_sync_lock_file removes .sync.lock file' do
|
2013-07-29 11:46:49 +01:00
|
|
|
FileUtils.touch "#{path}/.sync.lock"
|
2013-07-29 13:24:41 +01:00
|
|
|
repository.remove_sync_lock_file
|
2015-02-19 01:12:08 +00:00
|
|
|
File.exist?("#{path}/.sync.lock").should be_falsy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #add_repo_lock_file creates .repo.lock file' do
|
|
|
|
repository.add_repo_lock_file
|
2015-02-19 01:12:08 +00:00
|
|
|
File.exist?("#{path}/.repo.lock").should be_truthy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
it 'ensures that #remove_repo_lock_file removes .repo.lock file' do
|
2013-07-29 11:46:49 +01:00
|
|
|
FileUtils.touch "#{path}/.repo.lock"
|
2013-07-29 13:24:41 +01:00
|
|
|
repository.remove_repo_lock_file
|
2015-02-19 01:12:08 +00:00
|
|
|
File.exist?("#{path}/.repo.lock").should be_falsy
|
2013-07-29 11:46:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-12-08 14:03:56 +00:00
|
|
|
|
|
|
|
context 'when create with same owner that platform' do
|
2013-04-24 11:41:43 +01:00
|
|
|
before do
|
2012-03-29 21:34:22 +01:00
|
|
|
@platform = FactoryGirl.create(:platform)
|
2014-01-21 04:51:49 +00:00
|
|
|
@params = {name: 'tst_platform', description: 'test platform'}
|
2011-12-08 14:03:56 +00:00
|
|
|
end
|
|
|
|
|
2012-02-20 23:13:05 +00:00
|
|
|
it 'it should increase Repository.count by 1' do
|
|
|
|
rep = Repository.create(@params) {|r| r.platform = @platform}
|
|
|
|
@platform.repositories.count.should eql(1)
|
2011-12-08 14:03:56 +00:00
|
|
|
end
|
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
context 'ensures that folder of repository will be removed after destroy' do
|
|
|
|
let(:arch) { FactoryGirl.create(:arch) }
|
|
|
|
let(:types) { ['SRPM', arch.name] }
|
|
|
|
|
|
|
|
it "repository of main platform" do
|
|
|
|
FactoryGirl.create(:arch)
|
|
|
|
r = FactoryGirl.create(:repository)
|
|
|
|
paths = types.
|
|
|
|
map{ |type| "#{r.platform.path}/repository/#{type}/#{r.name}" }.
|
|
|
|
each{ |path| FileUtils.mkdir_p path }
|
|
|
|
r.destroy
|
2015-02-19 01:12:08 +00:00
|
|
|
paths.each{ |path| Dir.exists?(path).should be_falsy }
|
2013-04-24 11:41:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "repository of personal platform" do
|
|
|
|
FactoryGirl.create(:arch)
|
|
|
|
main_platform = FactoryGirl.create(:platform)
|
|
|
|
r = FactoryGirl.create(:personal_repository)
|
|
|
|
paths = types.
|
|
|
|
map{ |type| "#{r.platform.path}/repository/#{main_platform.name}/#{type}/#{r.name}" }.
|
|
|
|
each{ |path| FileUtils.mkdir_p path }
|
|
|
|
r.destroy
|
2015-02-19 01:12:08 +00:00
|
|
|
paths.each{ |path| Dir.exists?(path).should be_falsy }
|
2013-04-24 11:41:43 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-11-12 12:24:25 +00:00
|
|
|
context '#add_projects' do
|
|
|
|
it 'user has ability to read of adding project' do
|
|
|
|
repository = FactoryGirl.create(:repository)
|
|
|
|
project = FactoryGirl.create(:project)
|
2014-03-19 07:11:16 +00:00
|
|
|
repository.add_projects(project.name_with_owner, FactoryGirl.create(:user))
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(repository.projects.count).to eq 1
|
2013-11-12 12:24:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'user has no ability to read of adding project' do
|
|
|
|
repository = FactoryGirl.create(:repository)
|
2014-01-21 04:51:49 +00:00
|
|
|
project = FactoryGirl.create(:project, visibility: 'hidden')
|
2014-03-19 07:11:16 +00:00
|
|
|
repository.add_projects(project.name_with_owner, FactoryGirl.create(:user))
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(repository.projects.count).to eq 0
|
2013-11-12 12:24:25 +00:00
|
|
|
end
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-11-12 12:24:25 +00:00
|
|
|
it '#remove_projects' do
|
|
|
|
repository = FactoryGirl.create(:repository)
|
|
|
|
project = FactoryGirl.create(:project)
|
|
|
|
repository.projects << project
|
|
|
|
repository.remove_projects(project.name)
|
|
|
|
repository.reload
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(repository.projects.count).to eq 0
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|