2011-04-11 09:35:08 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Product do
|
2014-03-18 20:26:58 +00:00
|
|
|
let(:product) { FactoryGirl.create(:product) }
|
|
|
|
before { stub_symlink_methods }
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2014-03-18 20:26:58 +00:00
|
|
|
context 'ensures that validations and associations exist' do
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2014-03-18 20:26:58 +00:00
|
|
|
it 'is valid given valid attributes' do
|
|
|
|
# arch = FactoryGirl.create(:arch, name: 'x86_64')
|
|
|
|
# allow(Arch).to receive(:find_by).with(name: 'x86_64').and_return(arch)
|
2015-02-19 01:12:08 +00:00
|
|
|
FactoryGirl.create(:product).should be_truthy
|
2014-03-18 20:26:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { should belong_to(:platform) }
|
|
|
|
it { should have_many(:product_build_lists)}
|
|
|
|
|
|
|
|
it { should validate_presence_of(:name)}
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2014-03-18 20:26:58 +00:00
|
|
|
context 'uniqueness' do
|
|
|
|
before { product }
|
|
|
|
it { should validate_uniqueness_of(:name).scoped_to(:platform_id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should ensure_length_of(:main_script).is_at_most(255) }
|
|
|
|
it { should ensure_length_of(:params).is_at_most(255) }
|
2013-02-15 16:20:06 +00:00
|
|
|
|
2014-03-18 20:26:58 +00:00
|
|
|
it { should have_readonly_attribute(:platform_id) }
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2014-03-18 20:26:58 +00:00
|
|
|
it { should_not allow_mass_assignment_of(:platform) }
|
|
|
|
#it { should_not allow_mass_assignment_of(:platform_id) }
|
|
|
|
it { should_not allow_mass_assignment_of(:product_build_lists) }
|
|
|
|
end
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2013-03-25 14:12:15 +00:00
|
|
|
|
|
|
|
context '#autostart_iso_builds' do
|
2014-03-18 20:26:58 +00:00
|
|
|
before { product }
|
2013-03-25 14:12:15 +00:00
|
|
|
|
|
|
|
Product::HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
|
|
|
|
it "new product_build_lists should not be created if no products which should be autostarted #{human_autostart_status}" do
|
|
|
|
lambda { Product.autostart_iso_builds(autostart_status) }.should_not change{ ProductBuildList.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by autostart_status = once_a_12_hours' do
|
|
|
|
before do
|
2013-03-25 14:22:19 +00:00
|
|
|
stub_symlink_methods
|
2014-01-21 04:51:49 +00:00
|
|
|
params = {main_script: 'text.sh', project_version: product.project.default_branch}
|
|
|
|
product.update_attributes params.merge(autostart_status: Product::ONCE_A_12_HOURS)
|
|
|
|
FactoryGirl.create :product, params.merge(autostart_status: Product::ONCE_A_DAY)
|
2014-03-18 20:26:58 +00:00
|
|
|
FactoryGirl.create(:arch, name: 'x86_64')
|
2013-03-25 14:12:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be created only one product_build_list' do
|
|
|
|
lambda { Product.autostart_iso_builds(Product::ONCE_A_12_HOURS) }.should change{ ProductBuildList.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'product should has product_build_list' do
|
2013-03-25 14:22:19 +00:00
|
|
|
Product.autostart_iso_builds Product::ONCE_A_12_HOURS
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(product.product_build_lists.count).to eq 1
|
2013-03-25 14:12:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
end
|
|
|
|
|
2012-04-04 22:43:06 +01:00
|
|
|
end
|