summaryrefslogtreecommitdiff
path: root/spec/models/integrations/pipelines_email_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/integrations/pipelines_email_spec.rb')
-rw-r--r--spec/models/integrations/pipelines_email_spec.rb38
1 files changed, 37 insertions, 1 deletions
diff --git a/spec/models/integrations/pipelines_email_spec.rb b/spec/models/integrations/pipelines_email_spec.rb
index afd9d71ebc4..d70f104b965 100644
--- a/spec/models/integrations/pipelines_email_spec.rb
+++ b/spec/models/integrations/pipelines_email_spec.rb
@@ -35,6 +35,42 @@ RSpec.describe Integrations::PipelinesEmail, :mailer do
it { is_expected.not_to validate_presence_of(:recipients) }
end
+
+ describe 'validates number of recipients' do
+ before do
+ stub_const("#{described_class}::RECIPIENTS_LIMIT", 2)
+ end
+
+ subject(:integration) { described_class.new(project: project, recipients: recipients, active: true) }
+
+ context 'valid number of recipients' do
+ let(:recipients) { 'foo@bar.com, , ' }
+
+ it 'does not count empty emails' do
+ is_expected.to be_valid
+ end
+ end
+
+ context 'invalid number of recipients' do
+ let(:recipients) { 'foo@bar.com bar@foo.com bob@gitlab.com' }
+
+ it { is_expected.not_to be_valid }
+
+ it 'adds an error message' do
+ integration.valid?
+
+ expect(integration.errors).to contain_exactly('Recipients can\'t exceed 2')
+ end
+
+ context 'when integration is not active' do
+ before do
+ integration.active = false
+ end
+
+ it { is_expected.to be_valid }
+ end
+ end
+ end
end
shared_examples 'sending email' do |branches_to_be_notified: nil|
@@ -50,7 +86,7 @@ RSpec.describe Integrations::PipelinesEmail, :mailer do
it 'sends email' do
emails = receivers.map { |r| double(notification_email_or_default: r) }
- should_only_email(*emails, kind: :bcc)
+ should_only_email(*emails)
end
end