Commit 06ec4f22 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix-unlocking-artifacts-for-wrong-ci-ref' into 'master'

Fix bug that unlocked artifacts for the wrong CI ref

See merge request gitlab-org/gitlab!40082
parents 2a20cad4 7f5f452b
...@@ -10,7 +10,7 @@ module Ci ...@@ -10,7 +10,7 @@ module Ci
def perform(project_id, user_id, ref_path) def perform(project_id, user_id, ref_path)
::Project.find_by_id(project_id).try do |project| ::Project.find_by_id(project_id).try do |project|
::User.find_by_id(user_id).try do |user| ::User.find_by_id(user_id).try do |user|
::Ci::Ref.find_by_ref_path(ref_path).try do |ci_ref| project.ci_refs.find_by_ref_path(ref_path).try do |ci_ref|
::Ci::UnlockArtifactsService ::Ci::UnlockArtifactsService
.new(project, user) .new(project, user)
.execute(ci_ref) .execute(ci_ref)
......
...@@ -29,10 +29,8 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do ...@@ -29,10 +29,8 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do
context 'when user exists' do context 'when user exists' do
let(:user_id) { project.creator.id } let(:user_id) { project.creator.id }
context 'when ci ref exists' do context 'when ci ref exists for project' do
before do let!(:ci_ref) { create(:ci_ref, ref_path: ref, project: project) }
create(:ci_ref, ref_path: ref)
end
it 'calls the service' do it 'calls the service' do
service = spy(Ci::UnlockArtifactsService) service = spy(Ci::UnlockArtifactsService)
...@@ -40,17 +38,33 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do ...@@ -40,17 +38,33 @@ RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do
perform perform
expect(service).to have_received(:execute) expect(service).to have_received(:execute).with(ci_ref)
end end
end end
context 'when ci ref does not exist' do context 'when ci ref does not exist for the given project' do
let!(:another_ci_ref) { create(:ci_ref, ref_path: ref) }
it 'does not call the service' do it 'does not call the service' do
expect(Ci::UnlockArtifactsService).not_to receive(:new) expect(Ci::UnlockArtifactsService).not_to receive(:new)
perform perform
end end
end end
context 'when same ref path exists for a different project' do
let!(:another_ci_ref) { create(:ci_ref, ref_path: ref) }
let!(:ci_ref) { create(:ci_ref, ref_path: ref, project: project) }
it 'calls the service with the correct ref_id' do
service = spy(Ci::UnlockArtifactsService)
expect(Ci::UnlockArtifactsService).to receive(:new).and_return(service)
perform
expect(service).to have_received(:execute).with(ci_ref)
end
end
end end
context 'when user does not exist' do context 'when user does not exist' do
......
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