#405: added specs for MassBuild and RunExtraMassBuildsJob

This commit is contained in:
Vokhmin Alexey V 2014-07-10 21:51:37 +04:00
parent bf8a4c858c
commit aec2c90b57
3 changed files with 77 additions and 1 deletions

View File

@ -86,7 +86,7 @@ class MassBuild < ActiveRecord::Base
)
def build_all
start
return unless start
# later with resque
arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all

View File

@ -0,0 +1,49 @@
require 'spec_helper'
describe RunExtraMassBuildsJob do
let(:mass_build1) { FactoryGirl.build(:mass_build, id: 123) }
let(:mass_build2) { FactoryGirl.build(:mass_build, id: 234, extra_mass_builds: [mass_build1.id]) }
let(:build_list) { FactoryGirl.build(:build_list, id: 345, mass_build: mass_build) }
let(:job) { RunExtraMassBuildsJob.new }
before do
stub_symlink_methods
MassBuild.stub_chain(:where, :find_each).and_yield(mass_build2)
MassBuild.stub_chain(:where, :to_a).and_return([mass_build1])
allow(job).to receive(:not_ready?).with(mass_build1).and_return(false)
allow(mass_build2).to receive(:build_all)
end
it 'ensures that not raises error' do
expect do
job.perform
end.to_not raise_exception
end
it 'ensures that calls #build_all' do
expect(mass_build2).to receive(:build_all)
job.perform
end
it 'ensures that do nothing when no extra_mass_builds' do
mass_build2.extra_mass_builds = []
expect(mass_build2).to_not receive(:build_all)
job.perform
end
it 'ensures that do nothing when extra mass build not ready' do
allow(job).to receive(:not_ready?).with(mass_build1).and_return(true)
expect(mass_build2).to_not receive(:build_all)
job.perform
end
it 'ensures that do nothing when some extra mass builds have no status SUCCESS' do
mass_build0 = FactoryGirl.build(:mass_build, id: 1)
mass_build2.extra_mass_builds = [mass_build0, mass_build1]
MassBuild.stub_chain(:where, :to_a).and_return([mass_build1])
expect(mass_build2).to_not receive(:build_all)
job.perform
end
end

View File

@ -77,4 +77,31 @@ describe MassBuild do
mb.send(:publish, user, [])
end
it 'ensures that calls #build_all on create' do
mass_build = FactoryGirl.build(:mass_build)
expect(mass_build).to receive(:build_all)
mass_build.save
end
it 'ensures that does not call #build_all on create if attached extra mass builds' do
mass_build = FactoryGirl.build(:mass_build, extra_mass_builds: [1])
expect(mass_build).to_not receive(:build_all)
mass_build.save
end
context '#build_all' do
let(:mass_build) { FactoryGirl.create(:mass_build, extra_mass_builds: [1]) }
it 'ensures that do nothing when build has status build_started' do
mass_build.start
expect(mass_build).to_not receive(:projects_list)
mass_build.build_all
end
it 'ensures that works when build has status build_pending' do
expect(mass_build).to receive(:projects_list).at_least(:once)
mass_build.build_all
end
end
end