2011-03-09 17:38:21 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Platform do
|
2013-04-24 11:41:43 +01:00
|
|
|
before { stub_symlink_methods }
|
|
|
|
|
|
|
|
context 'ensures that validations and associations exist' do
|
|
|
|
it { should belong_to(:owner) }
|
|
|
|
it { should have_many(:members)}
|
|
|
|
it { should have_many(:repositories)}
|
|
|
|
it { should have_many(:products)}
|
|
|
|
|
|
|
|
it { should validate_presence_of(:name)}
|
2015-02-19 01:12:08 +00:00
|
|
|
|
|
|
|
context 'validates uniqueness' do
|
|
|
|
before { FactoryGirl.create(:platform) }
|
|
|
|
it { should validate_uniqueness_of(:name).case_insensitive }
|
|
|
|
end
|
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
it { should allow_value('Basic_platform-name-1234').for(:name) }
|
|
|
|
it { should_not allow_value('.!').for(:name) }
|
2015-02-17 22:33:58 +00:00
|
|
|
it { should validate_presence_of(:default_branch)}
|
2013-04-24 11:41:43 +01:00
|
|
|
it { should validate_presence_of(:description) }
|
|
|
|
it { should validate_presence_of(:distrib_type) }
|
|
|
|
it { should validate_presence_of(:visibility) }
|
|
|
|
|
|
|
|
Platform::VISIBILITIES.each do |value|
|
|
|
|
it {should allow_value(value).for(:visibility)}
|
|
|
|
end
|
2015-02-19 01:12:08 +00:00
|
|
|
it { should_not allow_value('custom_status').for(:visibility) }
|
2013-04-24 11:41:43 +01:00
|
|
|
|
2014-02-11 20:23:34 +00:00
|
|
|
['', nil] + Platform::AUTOMATIC_METADATA_REGENERATIONS.each do |value|
|
|
|
|
it {should allow_value(value).for(:automatic_metadata_regeneration)}
|
|
|
|
end
|
2015-02-19 01:12:08 +00:00
|
|
|
it { should_not allow_value('custom_status').for(:visibility) }
|
2014-02-11 20:23:34 +00:00
|
|
|
|
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
it { should have_readonly_attribute(:name) }
|
|
|
|
it { should have_readonly_attribute(:distrib_type) }
|
|
|
|
it { should have_readonly_attribute(:parent_platform_id) }
|
|
|
|
it { should have_readonly_attribute(:platform_type) }
|
2011-03-17 14:47:16 +00:00
|
|
|
|
2015-05-26 00:03:38 +01:00
|
|
|
it { should_not allow_value("How do you do...\nmy_platform").for(:name) }
|
2012-04-01 16:19:54 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-04-24 11:41:43 +01:00
|
|
|
it 'ensures that folder of platform will be removed after destroy' do
|
2013-06-21 12:58:09 +01:00
|
|
|
platform = FactoryGirl.create :platform
|
2013-04-24 11:41:43 +01:00
|
|
|
FileUtils.mkdir_p platform.path
|
|
|
|
platform.destroy
|
2015-05-26 00:03:38 +01:00
|
|
|
expect(Dir.exists?(platform.path)).to be_falsy
|
2011-03-17 14:47:16 +00:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-06-21 12:58:09 +01:00
|
|
|
it 'ensures that owner of personal platform can not be changed' do
|
|
|
|
platform = FactoryGirl.create :personal_platform
|
|
|
|
owner = platform.owner
|
|
|
|
platform.owner = FactoryGirl.create :user
|
2015-05-26 00:03:38 +01:00
|
|
|
expect(platform.save).to be_falsy
|
2013-06-21 12:58:09 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-06-21 12:58:09 +01:00
|
|
|
it 'ensures that owner of platform of group can not be changed' do
|
|
|
|
group = FactoryGirl.create :group
|
2014-01-21 04:51:49 +00:00
|
|
|
platform = FactoryGirl.create :personal_platform, owner: group
|
2013-06-21 12:58:09 +01:00
|
|
|
platform.owner = FactoryGirl.create :user
|
2015-05-26 00:03:38 +01:00
|
|
|
expect(platform.save).to be_falsy
|
2013-06-21 12:58:09 +01:00
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2013-06-21 12:58:09 +01:00
|
|
|
it 'ensures that owner of main platform can be changed' do
|
|
|
|
platform = FactoryGirl.create :platform
|
|
|
|
platform.owner = FactoryGirl.create :user
|
2015-05-26 00:03:38 +01:00
|
|
|
expect(platform.save).to be_truthy
|
2011-03-17 14:47:16 +00:00
|
|
|
end
|
2013-06-21 12:58:09 +01:00
|
|
|
|
2011-03-09 17:38:21 +00:00
|
|
|
end
|