gitlab-org--gitlab-foss/spec/support/helpers/email_helpers.rb
Patrick Derichs 5dad9a306a Fix unexpected extra notification mails
Using custom_action and recipient filtering

Add more generic filtering to user_ids_notifiable_on

Add changelog entry

Remove commented class

Method is no longer needed

Overloading no longer required

Filter by action just in case of custom notification level

Add participant check

Fix unexpected extra notification mails

Using custom_action and recipient filtering

Add more generic filtering to user_ids_notifiable_on

Add changelog entry

Remove commented class

Method is no longer needed

Overloading no longer required

Filter by action just in case of custom notification level

Fix comment

Add repond_to? checks

Reverted custom_action filtering

Enhanced output of should_email helper

Changed :watch to :participating for custom notifiable users

Change spec variable name

Enhanced participating check

These conditions are no longer needed

Fix custom notification handling for participating type

Participating level should include maintainers

Fixed add_guest notification

Fix successful pipeline notification

Refactoring: Use maintainer? method on team instead

Add spec for new_issue: true for a custom group setting
which should have lower prio than an available project setting

Clean up specs
2019-04-17 09:10:42 +00:00

48 lines
1.5 KiB
Ruby

module EmailHelpers
def sent_to_user(user, recipients: email_recipients)
recipients.count { |to| to == user.notification_email }
end
def reset_delivered_emails!
ActionMailer::Base.deliveries.clear
end
def should_only_email(*users, kind: :to)
recipients = email_recipients(kind: kind)
users.each { |user| should_email(user, recipients: recipients) }
expect(recipients.count).to eq(users.count)
end
def should_email(user, times: 1, recipients: email_recipients)
amount = sent_to_user(user, recipients: recipients)
failed_message = lambda { "User #{user.username} (#{user.id}): email test failed (expected #{times}, got #{amount})" }
expect(amount).to eq(times), failed_message
end
def should_not_email(user, recipients: email_recipients)
should_email(user, times: 0, recipients: recipients)
end
def should_not_email_anyone
expect(ActionMailer::Base.deliveries).to be_empty
end
def email_recipients(kind: :to)
ActionMailer::Base.deliveries.flat_map(&kind)
end
def find_email_for(user)
ActionMailer::Base.deliveries.find { |d| d.to.include?(user.notification_email) }
end
def have_referable_subject(referable, include_project: true, reply: false)
prefix = (include_project && referable.project ? "#{referable.project.name} | " : '').freeze
prefix = "Re: #{prefix}" if reply
suffix = "#{referable.title} (#{referable.to_reference})"
have_subject [prefix, suffix].compact.join
end
end