Commit 0caf84e2 authored by Furkan Ayhan's avatar Furkan Ayhan

Merge branch 'ensure-play-build-updates-attributes' into 'master'

Ensure current user and variables are updated when playing a job

See merge request gitlab-org/gitlab!75657
parents e074344f 8b3ba6f3
......@@ -9,7 +9,7 @@ module Ci
#
if build.enqueue
build.tap do |build|
build.update(user: current_user, job_variables_attributes: job_variables_attributes || [])
build.update!(user: current_user, job_variables_attributes: job_variables_attributes || [])
AfterRequeueJobService.new(project, current_user).execute(build)
end
......
......@@ -79,12 +79,22 @@ RSpec.describe Ci::PlayBuildService, '#execute' do
{ key: 'second', secret_value: 'second' }]
end
subject { service.execute(build, job_variables) }
it 'assigns the variables to the build' do
service.execute(build, job_variables)
subject
expect(build.reload.job_variables.map(&:key)).to contain_exactly('first', 'second')
end
context 'when variables are invalid' do
let(:job_variables) { [{}] }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
end
end
context 'when user defined variables are restricted' do
before do
project.update!(restrict_user_defined_variables: true)
......@@ -96,7 +106,7 @@ RSpec.describe Ci::PlayBuildService, '#execute' do
end
it 'assigns the variables to the build' do
service.execute(build, job_variables)
subject
expect(build.reload.job_variables.map(&:key)).to contain_exactly('first', 'second')
end
......@@ -104,8 +114,7 @@ RSpec.describe Ci::PlayBuildService, '#execute' do
context 'when user is developer' do
it 'raises an error' do
expect { service.execute(build, job_variables) }
.to raise_error Gitlab::Access::AccessDeniedError
expect { subject }.to raise_error Gitlab::Access::AccessDeniedError
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