gitlab-org--gitlab-foss/spec/services/ci/send_pipeline_notification_...

49 lines
1.2 KiB
Ruby
Raw Normal View History

2016-09-13 13:10:58 -04:00
require 'spec_helper'
describe Ci::SendPipelineNotificationService, services: true do
2016-09-23 07:45:48 -04:00
let(:pipeline) do
2016-09-23 09:43:40 -04:00
create(:ci_pipeline,
project: project,
sha: project.commit('master').sha,
user: user,
status: status)
2016-09-23 07:45:48 -04:00
end
let(:project) { create(:project) }
2016-09-13 13:10:58 -04:00
let(:user) { create(:user) }
2016-09-13 13:10:58 -04:00
subject{ described_class.new(pipeline) }
describe '#execute' do
2016-09-23 08:27:20 -04:00
before do
reset_delivered_emails!
end
2016-09-13 13:10:58 -04:00
shared_examples 'sending emails' do
it 'sends an email to pipeline user' do
perform_enqueued_jobs do
subject.execute([user.email])
2016-09-13 13:10:58 -04:00
end
email = ActionMailer::Base.deliveries.last
expect(email.subject).to include(email_subject)
expect(email.to).to eq([user.email])
end
end
context 'with success pipeline' do
let(:status) { 'success' }
2016-10-08 03:31:26 -04:00
let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
2016-09-13 13:10:58 -04:00
it_behaves_like 'sending emails'
end
context 'with failed pipeline' do
let(:status) { 'failed' }
2016-10-08 03:31:26 -04:00
let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
2016-09-13 13:10:58 -04:00
it_behaves_like 'sending emails'
end
end
end