提交 5720bce1 编写于 作者: L Lin Jen-Shin

Also treat newlines as separator, as people would do that

Before this fix, I don't know if those emails would work
having newlines in them.
上级 46bdcd64
...@@ -80,6 +80,6 @@ class PipelinesEmailService < Service ...@@ -80,6 +80,6 @@ class PipelinesEmailService < Service
end end
def retrieve_recipients(data) def retrieve_recipients(data)
recipients.to_s.split(',').reject(&:blank?) recipients.to_s.split(/[,(?:\r?\n) ]+/).reject(&:empty?)
end end
end end
...@@ -6,7 +6,8 @@ describe PipelinesEmailService, :mailer do ...@@ -6,7 +6,8 @@ describe PipelinesEmailService, :mailer do
end end
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:recipient) { 'test@gitlab.com' } let(:recipients) { 'test@gitlab.com' }
let(:receivers) { [recipients] }
let(:data) do let(:data) do
Gitlab::DataBuilder::Pipeline.build(pipeline) Gitlab::DataBuilder::Pipeline.build(pipeline)
...@@ -48,18 +49,24 @@ describe PipelinesEmailService, :mailer do ...@@ -48,18 +49,24 @@ describe PipelinesEmailService, :mailer do
shared_examples 'sending email' do shared_examples 'sending email' do
before do before do
subject.recipients = recipients
perform_enqueued_jobs do perform_enqueued_jobs do
run run
end end
end end
it 'sends email' do it 'sends email' do
should_only_email(double(notification_email: recipient), kind: :bcc) emails = receivers.map { |r| double(notification_email: r) }
should_only_email(*emails, kind: :bcc)
end end
end end
shared_examples 'not sending email' do shared_examples 'not sending email' do
before do before do
subject.recipients = recipients
perform_enqueued_jobs do perform_enqueued_jobs do
run run
end end
...@@ -75,10 +82,6 @@ describe PipelinesEmailService, :mailer do ...@@ -75,10 +82,6 @@ describe PipelinesEmailService, :mailer do
subject.test(data) subject.test(data)
end end
before do
subject.recipients = recipient
end
context 'when pipeline is failed' do context 'when pipeline is failed' do
before do before do
data[:object_attributes][:status] = 'failed' data[:object_attributes][:status] = 'failed'
...@@ -104,10 +107,6 @@ describe PipelinesEmailService, :mailer do ...@@ -104,10 +107,6 @@ describe PipelinesEmailService, :mailer do
end end
context 'with recipients' do context 'with recipients' do
before do
subject.recipients = recipient
end
context 'with failed pipeline' do context 'with failed pipeline' do
before do before do
data[:object_attributes][:status] = 'failed' data[:object_attributes][:status] = 'failed'
...@@ -152,17 +151,29 @@ describe PipelinesEmailService, :mailer do ...@@ -152,17 +151,29 @@ describe PipelinesEmailService, :mailer do
end end
context 'with empty recipients list' do context 'with empty recipients list' do
let(:recipients) { ' ,, ' }
context 'with failed pipeline' do
before do before do
subject.recipients = ' ,, ' data[:object_attributes][:status] = 'failed'
pipeline.update(status: 'failed')
end
it_behaves_like 'not sending email'
end
end end
context 'with recipients list separating with newlines' do
let(:recipients) { "\ntest@gitlab.com, \r\nexample@gitlab.com" }
let(:receivers) { %w[test@gitlab.com example@gitlab.com] }
context 'with failed pipeline' do context 'with failed pipeline' do
before do before do
data[:object_attributes][:status] = 'failed' data[:object_attributes][:status] = 'failed'
pipeline.update(status: 'failed') pipeline.update(status: 'failed')
end end
it_behaves_like 'not sending email' it_behaves_like 'sending email'
end end
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册