2016-01-14 18:37:52 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BuildsEmailService do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:data) { Gitlab::BuildDataBuilder.build(create(:ci_build)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
describe 'Validations' do
|
|
|
|
context 'when service is active' do
|
|
|
|
before { subject.active = true }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:recipients) }
|
|
|
|
|
|
|
|
context 'when pusher is added' do
|
|
|
|
before { subject.add_pusher = true }
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:recipients) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service is inactive' do
|
|
|
|
before { subject.active = false }
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:recipients) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'sends email' do
|
|
|
|
subject.recipients = 'test@gitlab.com'
|
2016-01-14 18:37:52 +05:30
|
|
|
data[:build_status] = 'failed'
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
expect(BuildEmailWorker).to receive(:perform_async)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
subject.execute(data)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'does not send email with succeeded build and notify_only_broken_builds on' do
|
|
|
|
expect(subject).to receive(:notify_only_broken_builds).and_return(true)
|
|
|
|
data[:build_status] = 'success'
|
|
|
|
|
|
|
|
expect(BuildEmailWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
subject.execute(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not send email with failed build and build_allow_failure is true' do
|
2016-01-14 18:37:52 +05:30
|
|
|
data[:build_status] = 'failed'
|
|
|
|
data[:build_allow_failure] = true
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
expect(BuildEmailWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
subject.execute(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not send email with unknown build status' do
|
|
|
|
data[:build_status] = 'foo'
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
expect(BuildEmailWorker).not_to receive(:perform_async)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
subject.execute(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not send email when recipients list is empty' do
|
|
|
|
subject.recipients = ' ,, '
|
|
|
|
data[:build_status] = 'failed'
|
|
|
|
|
|
|
|
expect(BuildEmailWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
subject.execute(data)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|