Added specs for MassBuild

This commit is contained in:
Vokhmin Alexey V 2014-04-05 22:37:27 +04:00
parent 164569b2ad
commit 3ad56638b7
2 changed files with 45 additions and 9 deletions

View File

@ -104,12 +104,10 @@ class MassBuild < ActiveRecord::Base
where(
status: status,
mass_build_id: self.id
).joins(:project, :arch).find_in_batches(batch_size: 100) do |build_lists|
build_lists.each do |build_list|
report << "ID: #{build_list.id}; "
report << "PROJECT_NAME: #{build_list.project_name}; "
report << "ARCH: #{build_list.arch_name}\n"
end
).joins(:project, :arch).find_each(batch_size: 100) do |build_list|
report << "ID: #{build_list.id}; "
report << "PROJECT_NAME: #{build_list.project_name}; "
report << "ARCH: #{build_list.arch_name}\n"
end
report
end
@ -117,8 +115,8 @@ class MassBuild < ActiveRecord::Base
def publish(user, *statuses)
builds = build_lists.where(status: statuses)
builds.update_all(publisher_id: user.id)
builds.order(:id).find_in_batches(batch_size: 50) do |bls|
bls.each{ |bl| bl.can_publish? && bl.has_new_packages? && bl.now_publish }
builds.find_each(batch_size: 50) do |bl|
bl.now_publish if bl.can_publish? && bl.has_new_packages?
end
end

View File

@ -33,9 +33,47 @@ describe MassBuild do
at
ab
)
mass_build = FactoryGirl.create(:mass_build, projects_list: projects_list)
mass_build = FactoryGirl.build(:mass_build, projects_list: projects_list)
mass_build.should be_valid
list = mass_build.projects_list.split(/[\r]*\n/)
list.should have(2).items
list.should include('at', 'ab')
end
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
end