Commit 9457904b authored by James Lopez's avatar James Lopez

Merge branch 'pl-spec-worker-hardcoded-ids' into 'master'

Prefer non_existing_record_id helper over hardcoded ids

See merge request gitlab-org/gitlab!41733
parents 223b51be 632bd367
...@@ -10,13 +10,13 @@ RSpec.describe NewEpicWorker do ...@@ -10,13 +10,13 @@ RSpec.describe NewEpicWorker do
it 'does not call Services' do it 'does not call Services' do
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(99, create(:user).id) worker.perform(non_existing_record_id, create(:user).id)
end end
it 'logs an error' do it 'logs an error' do
expect(Gitlab::AppLogger).to receive(:error).with('NewEpicWorker: couldn\'t find Epic with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewEpicWorker: couldn't find Epic with ID=#{non_existing_record_id}, skipping job")
worker.perform(99, create(:user).id) worker.perform(non_existing_record_id, create(:user).id)
end end
end end
...@@ -24,13 +24,13 @@ RSpec.describe NewEpicWorker do ...@@ -24,13 +24,13 @@ RSpec.describe NewEpicWorker do
it 'does not call Services' do it 'does not call Services' do
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(create(:epic).id, 99) worker.perform(create(:epic).id, non_existing_record_id)
end end
it 'logs an error' do it 'logs an error' do
expect(Gitlab::AppLogger).to receive(:error).with('NewEpicWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewEpicWorker: couldn't find User with ID=#{non_existing_record_id}, skipping job")
worker.perform(create(:epic).id, 99) worker.perform(create(:epic).id, non_existing_record_id)
end end
end end
......
...@@ -9,7 +9,7 @@ RSpec.describe CreatePipelineWorker do ...@@ -9,7 +9,7 @@ RSpec.describe CreatePipelineWorker do
context 'when a project not found' do context 'when a project not found' do
it 'does not call the Service' do it 'does not call the Service' do
expect(Ci::CreatePipelineService).not_to receive(:new) expect(Ci::CreatePipelineService).not_to receive(:new)
expect { worker.perform(99, create(:user).id, 'master', :web) }.to raise_error(ActiveRecord::RecordNotFound) expect { worker.perform(non_existing_record_id, create(:user).id, 'master', :web) }.to raise_error(ActiveRecord::RecordNotFound)
end end
end end
...@@ -18,7 +18,7 @@ RSpec.describe CreatePipelineWorker do ...@@ -18,7 +18,7 @@ RSpec.describe CreatePipelineWorker do
it 'does not call the Service' do it 'does not call the Service' do
expect(Ci::CreatePipelineService).not_to receive(:new) expect(Ci::CreatePipelineService).not_to receive(:new)
expect { worker.perform(project.id, 99, project.default_branch, :web) }.to raise_error(ActiveRecord::RecordNotFound) expect { worker.perform(project.id, non_existing_record_id, project.default_branch, :web) }.to raise_error(ActiveRecord::RecordNotFound)
end end
end end
......
...@@ -11,13 +11,13 @@ RSpec.describe NewIssueWorker do ...@@ -11,13 +11,13 @@ RSpec.describe NewIssueWorker do
expect(EventCreateService).not_to receive(:new) expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(99, create(:user).id) worker.perform(non_existing_record_id, create(:user).id)
end end
it 'logs an error' do it 'logs an error' do
expect(Gitlab::AppLogger).to receive(:error).with('NewIssueWorker: couldn\'t find Issue with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewIssueWorker: couldn't find Issue with ID=#{non_existing_record_id}, skipping job")
worker.perform(99, create(:user).id) worker.perform(non_existing_record_id, create(:user).id)
end end
end end
...@@ -26,15 +26,15 @@ RSpec.describe NewIssueWorker do ...@@ -26,15 +26,15 @@ RSpec.describe NewIssueWorker do
expect(EventCreateService).not_to receive(:new) expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(create(:issue).id, 99) worker.perform(create(:issue).id, non_existing_record_id)
end end
it 'logs an error' do it 'logs an error' do
issue = create(:issue) issue = create(:issue)
expect(Gitlab::AppLogger).to receive(:error).with('NewIssueWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewIssueWorker: couldn't find User with ID=#{non_existing_record_id}, skipping job")
worker.perform(issue.id, 99) worker.perform(issue.id, non_existing_record_id)
end end
end end
...@@ -50,7 +50,7 @@ RSpec.describe NewIssueWorker do ...@@ -50,7 +50,7 @@ RSpec.describe NewIssueWorker do
it 'creates a notification for the mentioned user' do it 'creates a notification for the mentioned user' do
expect(Notify).to receive(:new_issue_email).with(mentioned.id, issue.id, NotificationReason::MENTIONED) expect(Notify).to receive(:new_issue_email).with(mentioned.id, issue.id, NotificationReason::MENTIONED)
.and_return(double(deliver_later: true)) .and_return(double(deliver_later: true))
worker.perform(issue.id, user.id) worker.perform(issue.id, user.id)
end end
......
...@@ -11,15 +11,15 @@ RSpec.describe NewMergeRequestWorker do ...@@ -11,15 +11,15 @@ RSpec.describe NewMergeRequestWorker do
expect(EventCreateService).not_to receive(:new) expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(99, create(:user).id) worker.perform(non_existing_record_id, create(:user).id)
end end
it 'logs an error' do it 'logs an error' do
user = create(:user) user = create(:user)
expect(Gitlab::AppLogger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find MergeRequest with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewMergeRequestWorker: couldn't find MergeRequest with ID=#{non_existing_record_id}, skipping job")
worker.perform(99, user.id) worker.perform(non_existing_record_id, user.id)
end end
end end
...@@ -28,15 +28,15 @@ RSpec.describe NewMergeRequestWorker do ...@@ -28,15 +28,15 @@ RSpec.describe NewMergeRequestWorker do
expect(EventCreateService).not_to receive(:new) expect(EventCreateService).not_to receive(:new)
expect(NotificationService).not_to receive(:new) expect(NotificationService).not_to receive(:new)
worker.perform(create(:merge_request).id, 99) worker.perform(create(:merge_request).id, non_existing_record_id)
end end
it 'logs an error' do it 'logs an error' do
merge_request = create(:merge_request) merge_request = create(:merge_request)
expect(Gitlab::AppLogger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find User with ID=99, skipping job') expect(Gitlab::AppLogger).to receive(:error).with("NewMergeRequestWorker: couldn't find User with ID=#{non_existing_record_id}, skipping job")
worker.perform(merge_request.id, 99) worker.perform(merge_request.id, non_existing_record_id)
end end
end end
...@@ -54,8 +54,8 @@ RSpec.describe NewMergeRequestWorker do ...@@ -54,8 +54,8 @@ RSpec.describe NewMergeRequestWorker do
it 'creates a notification for the mentioned user' do it 'creates a notification for the mentioned user' do
expect(Notify).to receive(:new_merge_request_email) expect(Notify).to receive(:new_merge_request_email)
.with(mentioned.id, merge_request.id, NotificationReason::MENTIONED) .with(mentioned.id, merge_request.id, NotificationReason::MENTIONED)
.and_return(double(deliver_later: true)) .and_return(double(deliver_later: true))
worker.perform(merge_request.id, user.id) worker.perform(merge_request.id, user.id)
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