2012-05-18 16:12:51 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MassBuild do
|
2013-06-21 11:39:03 +01:00
|
|
|
before { stub_symlink_methods }
|
|
|
|
|
|
|
|
context 'ensures that validations and associations exist' do
|
2014-03-18 20:22:28 +00:00
|
|
|
|
|
|
|
it 'is valid given valid attributes' do
|
|
|
|
FactoryGirl.create(:mass_build).should be_true
|
2013-06-21 11:39:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { should belong_to(:build_for_platform) }
|
|
|
|
it { should belong_to(:save_to_platform) }
|
|
|
|
it { should belong_to(:user) }
|
|
|
|
it { should have_many(:build_lists)}
|
|
|
|
|
|
|
|
it { should validate_presence_of(:save_to_platform_id)}
|
|
|
|
it { should validate_presence_of(:build_for_platform_id)}
|
|
|
|
it { should validate_presence_of(:user_id)}
|
|
|
|
it { should validate_presence_of(:arch_names)}
|
|
|
|
it { should validate_presence_of(:name)}
|
|
|
|
|
|
|
|
it { should validate_presence_of(:projects_list)}
|
|
|
|
it { should ensure_length_of(:projects_list).is_at_most(500_000) }
|
|
|
|
|
2014-06-26 22:21:31 +01:00
|
|
|
it { should ensure_length_of(:description).is_at_most(255) }
|
2013-06-21 11:39:03 +01:00
|
|
|
|
|
|
|
it { should_not allow_mass_assignment_of(:name) }
|
|
|
|
it { should_not allow_mass_assignment_of(:arch_names) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures that projects_list contains unique projects' do
|
|
|
|
projects_list = %(at
|
2014-01-21 04:51:49 +00:00
|
|
|
at
|
|
|
|
ab
|
2013-06-21 11:39:03 +01:00
|
|
|
)
|
2014-04-05 19:37:27 +01:00
|
|
|
mass_build = FactoryGirl.build(:mass_build, projects_list: projects_list)
|
|
|
|
mass_build.should be_valid
|
2013-06-21 11:39:03 +01:00
|
|
|
list = mass_build.projects_list.split(/[\r]*\n/)
|
|
|
|
list.should have(2).items
|
|
|
|
list.should include('at', 'ab')
|
|
|
|
end
|
2014-04-05 19:37:27 +01:00
|
|
|
|
|
|
|
it '#generate_list' do
|
|
|
|
mb = FactoryGirl.build(:mass_build)
|
|
|
|
bl = double(:build_list)
|
|
|
|
|
|
|
|
# allow(service).to receive(:already_pulled?).with(post.identifier).and_return(true)
|
|
|
|
# allow(BuildList).to receive(:find_each).and_yield(bl)
|
|
|
|
BuildList.stub_chain(:select, :where, :joins, :find_each).and_yield(bl)
|
|
|
|
expect(bl).to receive(:id)
|
|
|
|
expect(bl).to receive(:project_name)
|
|
|
|
expect(bl).to receive(:arch_name)
|
|
|
|
mb.send(:generate_list, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it '#publish' do
|
|
|
|
mb = FactoryGirl.build(:mass_build)
|
|
|
|
user = double(:user, id: 123)
|
|
|
|
|
|
|
|
bl1 = double(:build_list, can_publish?: true, has_new_packages?: true)
|
|
|
|
bl2 = double(:build_list, can_publish?: true, has_new_packages?: false)
|
|
|
|
bl3 = double(:build_list, can_publish?: false, has_new_packages?: true)
|
|
|
|
bl4 = double(:build_list, can_publish?: false, has_new_packages?: false)
|
|
|
|
|
|
|
|
finder = double(:finder)
|
|
|
|
allow(mb).to receive(:build_lists).and_return(finder)
|
|
|
|
allow(finder).to receive(:where).and_return(finder)
|
|
|
|
allow(finder).to receive(:find_each).and_yield(bl1).and_yield(bl2).and_yield(bl3).and_yield(bl4)
|
|
|
|
|
|
|
|
expect(finder).to receive(:update_all).with(publisher_id: user.id)
|
|
|
|
expect(bl1).to receive(:now_publish)
|
|
|
|
expect(bl2).to_not receive(:now_publish)
|
|
|
|
expect(bl3).to_not receive(:now_publish)
|
|
|
|
expect(bl4).to_not receive(:now_publish)
|
|
|
|
|
|
|
|
mb.send(:publish, user, [])
|
|
|
|
end
|
|
|
|
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|