Commit 53b5346d authored by Shinya Maeda's avatar Shinya Maeda

Fix spec on egister_job_service_spec.rb

parent 50b9aeb4
...@@ -4,7 +4,7 @@ module Ci ...@@ -4,7 +4,7 @@ module Ci
describe RegisterJobService do describe RegisterJobService do
let!(:project) { FactoryGirl.create :project, shared_runners_enabled: false } let!(:project) { FactoryGirl.create :project, shared_runners_enabled: false }
let!(:pipeline) { FactoryGirl.create :ci_pipeline, project: project } let!(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
let!(:pending_build) { FactoryGirl.create :ci_build, pipeline: pipeline } let!(:pending_job) { FactoryGirl.create :ci_build, pipeline: pipeline }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
...@@ -15,32 +15,32 @@ module Ci ...@@ -15,32 +15,32 @@ module Ci
describe '#execute' do describe '#execute' do
context 'runner follow tag list' do context 'runner follow tag list' do
it "picks build with the same tag" do it "picks build with the same tag" do
pending_build.tag_list = ["linux"] pending_job.tag_list = ["linux"]
pending_build.save pending_job.save
specific_runner.tag_list = ["linux"] specific_runner.tag_list = ["linux"]
expect(execute(specific_runner)).to eq(pending_build) expect(execute(specific_runner)).to eq(pending_job)
end end
it "does not pick build with different tag" do it "does not pick build with different tag" do
pending_build.tag_list = ["linux"] pending_job.tag_list = ["linux"]
pending_build.save pending_job.save
specific_runner.tag_list = ["win32"] specific_runner.tag_list = ["win32"]
expect(execute(specific_runner)).to be_falsey expect(execute(specific_runner)).to be_falsey
end end
it "picks build without tag" do it "picks build without tag" do
expect(execute(specific_runner)).to eq(pending_build) expect(execute(specific_runner)).to eq(pending_job)
end end
it "does not pick build with tag" do it "does not pick build with tag" do
pending_build.tag_list = ["linux"] pending_job.tag_list = ["linux"]
pending_build.save pending_job.save
expect(execute(specific_runner)).to be_falsey expect(execute(specific_runner)).to be_falsey
end end
it "pick build without tag" do it "pick build without tag" do
specific_runner.tag_list = ["win32"] specific_runner.tag_list = ["win32"]
expect(execute(specific_runner)).to eq(pending_build) expect(execute(specific_runner)).to eq(pending_job)
end end
end end
...@@ -76,7 +76,7 @@ module Ci ...@@ -76,7 +76,7 @@ module Ci
let!(:pipeline2) { create :ci_pipeline, project: project2 } let!(:pipeline2) { create :ci_pipeline, project: project2 }
let!(:project3) { create :project, shared_runners_enabled: true } let!(:project3) { create :project, shared_runners_enabled: true }
let!(:pipeline3) { create :ci_pipeline, project: project3 } let!(:pipeline3) { create :ci_pipeline, project: project3 }
let!(:build1_project1) { pending_build } let!(:build1_project1) { pending_job }
let!(:build2_project1) { FactoryGirl.create :ci_build, pipeline: pipeline } let!(:build2_project1) { FactoryGirl.create :ci_build, pipeline: pipeline }
let!(:build3_project1) { FactoryGirl.create :ci_build, pipeline: pipeline } let!(:build3_project1) { FactoryGirl.create :ci_build, pipeline: pipeline }
let!(:build1_project2) { FactoryGirl.create :ci_build, pipeline: pipeline2 } let!(:build1_project2) { FactoryGirl.create :ci_build, pipeline: pipeline2 }
...@@ -172,7 +172,7 @@ module Ci ...@@ -172,7 +172,7 @@ module Ci
context 'when first build is stalled' do context 'when first build is stalled' do
before do before do
pending_build.lock_version = 10 pending_job.lock_version = 10
end end
subject { described_class.new(specific_runner).execute } subject { described_class.new(specific_runner).execute }
...@@ -182,7 +182,7 @@ module Ci ...@@ -182,7 +182,7 @@ module Ci
before do before do
allow_any_instance_of(Ci::RegisterJobService).to receive(:builds_for_specific_runner) allow_any_instance_of(Ci::RegisterJobService).to receive(:builds_for_specific_runner)
.and_return([pending_build, other_build]) .and_return([pending_job, other_build])
end end
it "receives second build from the queue" do it "receives second build from the queue" do
...@@ -194,7 +194,7 @@ module Ci ...@@ -194,7 +194,7 @@ module Ci
context 'when single build is in queue' do context 'when single build is in queue' do
before do before do
allow_any_instance_of(Ci::RegisterJobService).to receive(:builds_for_specific_runner) allow_any_instance_of(Ci::RegisterJobService).to receive(:builds_for_specific_runner)
.and_return([pending_build]) .and_return([pending_job])
end end
it "does not receive any valid result" do it "does not receive any valid result" do
...@@ -219,30 +219,30 @@ module Ci ...@@ -219,30 +219,30 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :specific) } let!(:specific_runner) { create(:ci_runner, :specific) }
context 'when a job is protected' do context 'when a job is protected' do
let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do it 'picks the job' do
expect(execute(specific_runner)).to eq(protected_job) expect(execute(specific_runner)).to eq(pending_job)
end end
end end
context 'when a job is unprotected' do context 'when a job is unprotected' do
let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, pipeline: pipeline) }
it 'picks the unprotected job' do it 'picks the job' do
expect(execute(specific_runner)).to eq(unprotected_job) expect(execute(specific_runner)).to eq(pending_job)
end end
end end
context 'when protected attribute of a job is nil' do context 'when protected attribute of a job is nil' do
let!(:legacy_job) { create(:ci_build, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, pipeline: pipeline) }
before do before do
legacy_job.update_attribute(:protected, nil) pending_job.update_attribute(:protected, nil)
end end
it 'picks the legacy job' do it 'picks the job' do
expect(execute(specific_runner)).to eq(legacy_job) expect(execute(specific_runner)).to eq(pending_job)
end end
end end
end end
...@@ -251,29 +251,29 @@ module Ci ...@@ -251,29 +251,29 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) } let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) }
context 'when a job is protected' do context 'when a job is protected' do
let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do it 'picks the job' do
expect(execute(specific_runner)).to eq(protected_job) expect(execute(specific_runner)).to eq(pending_job)
end end
end end
context 'when a job is unprotected' do context 'when a job is unprotected' do
let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, pipeline: pipeline) }
it 'does not pick the unprotected job' do it 'does not pick the job' do
expect(execute(specific_runner)).to be_nil expect(execute(specific_runner)).to be_nil
end end
end end
context 'when protected attribute of a job is nil' do context 'when protected attribute of a job is nil' do
let!(:legacy_job) { create(:ci_build, pipeline: pipeline) } let!(:pending_job) { create(:ci_build, pipeline: pipeline) }
before do before do
legacy_job.update_attribute(:protected, nil) pending_job.update_attribute(:protected, nil)
end end
it 'does not pick the legacy job' do it 'does not pick the job' do
expect(execute(specific_runner)).to be_nil expect(execute(specific_runner)).to be_nil
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment