Fix CI build specs after adding retry ability check

This commit is contained in:
Grzegorz Bizon 2017-02-13 13:01:52 +01:00
parent db09d10599
commit c5e7880841
3 changed files with 35 additions and 23 deletions

View file

@ -62,8 +62,8 @@ module Ci
new_build.save new_build.save
end end
def retry(build, user = nil) def retry(build, current_user)
Ci::RetryBuildService.new(build, user).retry! Ci::RetryBuildService.new(build, current_user).retry!
end end
end end
@ -111,7 +111,7 @@ module Ci
project.builds_enabled? && commands.present? && manual? && skipped? project.builds_enabled? && commands.present? && manual? && skipped?
end end
def play(current_user = nil) def play(current_user)
# Try to queue a current build # Try to queue a current build
if self.enqueue if self.enqueue
self.update(user: current_user) self.update(user: current_user)

View file

@ -1,6 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Ci::Build, :models do describe Ci::Build, :models do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let(:test_trace) { 'This is a test' } let(:test_trace) { 'This is a test' }
@ -207,14 +208,16 @@ describe Ci::Build, :models do
end end
it 'expects to have retried builds instead the original ones' do it 'expects to have retried builds instead the original ones' do
retried_rspec = Ci::Build.retry(rspec_test) project.team << [user, :developer]
expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, retried_rspec.id, rubocop_test.id)
retried_rspec = Ci::Build.retry(rspec_test, user)
expect(staging.depends_on_builds.map(&:id))
.to contain_exactly(build.id, retried_rspec.id, rubocop_test.id)
end end
end end
describe '#detailed_status' do describe '#detailed_status' do
let(:user) { create(:user) }
it 'returns a detailed status' do it 'returns a detailed status' do
expect(build.detailed_status(user)) expect(build.detailed_status(user))
.to be_a Gitlab::Ci::Status::Build::Cancelable .to be_a Gitlab::Ci::Status::Build::Cancelable
@ -813,12 +816,16 @@ describe Ci::Build, :models do
subject { build.other_actions } subject { build.other_actions }
before do
project.team << [user, :developer]
end
it 'returns other actions' do it 'returns other actions' do
is_expected.to contain_exactly(other_build) is_expected.to contain_exactly(other_build)
end end
context 'when build is retried' do context 'when build is retried' do
let!(:new_build) { Ci::Build.retry(build) } let!(:new_build) { Ci::Build.retry(build, user) }
it 'does not return any of them' do it 'does not return any of them' do
is_expected.not_to include(build, new_build) is_expected.not_to include(build, new_build)
@ -826,7 +833,7 @@ describe Ci::Build, :models do
end end
context 'when other build is retried' do context 'when other build is retried' do
let!(:retried_build) { Ci::Build.retry(other_build) } let!(:retried_build) { Ci::Build.retry(other_build, user) }
it 'returns a retried build' do it 'returns a retried build' do
is_expected.to contain_exactly(retried_build) is_expected.to contain_exactly(retried_build)
@ -857,21 +864,29 @@ describe Ci::Build, :models do
describe '#play' do describe '#play' do
let(:build) { create(:ci_build, :manual, pipeline: pipeline) } let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
subject { build.play } before do
project.team << [user, :developer]
it 'enqueues a build' do
is_expected.to be_pending
is_expected.to eq(build)
end end
context 'for successful build' do context 'when build is manual' do
it 'enqueues a build' do
new_build = build.play(user)
expect(new_build).to be_pending
expect(new_build).to eq(build)
end
end
context 'when build is passed' do
before do before do
build.update(status: 'success') build.update(status: 'success')
end end
it 'creates a new build' do it 'creates a new build' do
is_expected.to be_pending new_build = build.play(user)
is_expected.not_to eq(build)
expect(new_build).to be_pending
expect(new_build).not_to eq(build)
end end
end end
end end
@ -1246,12 +1261,9 @@ describe Ci::Build, :models do
end end
context 'when build has user' do context 'when build has user' do
let(:user) { create(:user, username: 'starter') }
let(:user_variables) do let(:user_variables) do
[ [ { key: 'GITLAB_USER_ID', value: user.id.to_s, public: true },
{ key: 'GITLAB_USER_ID', value: user.id.to_s, public: true }, { key: 'GITLAB_USER_EMAIL', value: user.email, public: true } ]
{ key: 'GITLAB_USER_EMAIL', value: user.email, public: true }
]
end end
before do before do

View file

@ -27,7 +27,7 @@ describe Ci::RetryBuildService, :services do
end end
it 'resolves todos for old build that failed' do it 'resolves todos for old build that failed' do
expect(MergeRequests::AddTodoWhenBuildFailsService) expect(MergeRequests::AddTodoWhenBuildFailsService)
.to receive_message_chain(:new, :close) .to receive_message_chain(:new, :close)
service.retry! service.retry!