rosa-build/spec/models/platform_spec.rb

73 lines
2.4 KiB
Ruby
Raw Normal View History

2011-03-09 17:38:21 +00:00
require 'spec_helper'
describe Platform do
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
it { should allow_value('Basic_platform-name-1234').for(:name) }
it { should_not allow_value('.!').for(:name) }
it { should validate_presence_of(:default_branch)}
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) }
['', 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) }
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) }
end
it 'ensures that folder of platform will be removed after destroy' do
platform = FactoryGirl.create :platform
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
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
end
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
platform.owner = FactoryGirl.create :user
2015-05-26 00:03:38 +01:00
expect(platform.save).to be_falsy
end
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
2011-03-09 17:38:21 +00:00
end