Commit 9875d44a authored by Sean McGivern's avatar Sean McGivern

Merge branch '6117-unify-preview-mailer' into 'master'

Resolve "Extract EE specific files/lines for spec/mailers, app/mailers/preview"

Closes #6117

See merge request gitlab-org/gitlab-ee!6442
parents 5455f905 72899b87
class NotifyPreview < ActionMailer::Preview
prepend EE::Preview::NotifyPreview
def note_merge_request_email_for_individual_note
note_email(:note_merge_request_email) do
note = <<-MD.strip_heredoc
......@@ -123,52 +125,6 @@ class NotifyPreview < ActionMailer::Preview
Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email))
end
# EE-specific start
def add_merge_request_approver_email
Notify.add_merge_request_approver_email(user.id, merge_request.id, user.id).message
end
def issues_csv_email
Notify.issues_csv_email(user, project, '1997,Ford,E350', { truncated: false, rows_expected: 3, rows_written: 3 }).message
end
def approved_merge_request_email
Notify.approved_merge_request_email(user.id, merge_request.id, approver.id).message
end
def unapproved_merge_request_email
Notify.unapproved_merge_request_email(user.id, merge_request.id, approver.id).message
end
def mirror_was_hard_failed_email
Notify.mirror_was_hard_failed_email(project.id, user.id).message
end
def project_mirror_user_changed_email
Notify.project_mirror_user_changed_email(user.id, 'deleted_user_name', project.id).message
end
def send_admin_notification
Notify.send_admin_notification(user.id, 'Email subject from admin', 'Email body from admin').message
end
def send_unsubscribed_notification
Notify.send_unsubscribed_notification(user.id).message
end
def service_desk_new_note_email
cleanup do
note = create_note(noteable_type: 'Issue', noteable_id: issue.id, note: 'Issue note content')
Notify.service_desk_new_note_email(issue.id, note.id).message
end
end
def service_desk_thank_you_email
Notify.service_desk_thank_you_email(issue.id).message
end
# EE-specific end
private
def project
......@@ -213,10 +169,4 @@ class NotifyPreview < ActionMailer::Preview
email
end
# EE-specific start
def approver
@user ||= User.first
end
# EE-specific end
end
module EE
module Preview
module NotifyPreview
extend ActiveSupport::Concern
# We need to define the methods on the prepender directly because:
# https://github.com/rails/rails/blob/3faf7485623da55215d6d7f3dcb2eed92c59c699/actionmailer/lib/action_mailer/preview.rb#L73
prepended do
def add_merge_request_approver_email
::Notify.add_merge_request_approver_email(user.id, merge_request.id, user.id).message
end
def issues_csv_email
::Notify.issues_csv_email(user, project, '1997,Ford,E350', { truncated: false, rows_expected: 3, rows_written: 3 }).message
end
def approved_merge_request_email
::Notify.approved_merge_request_email(user.id, merge_request.id, approver.id).message
end
def unapproved_merge_request_email
::Notify.unapproved_merge_request_email(user.id, merge_request.id, approver.id).message
end
def mirror_was_hard_failed_email
::Notify.mirror_was_hard_failed_email(project.id, user.id).message
end
def project_mirror_user_changed_email
::Notify.project_mirror_user_changed_email(user.id, 'deleted_user_name', project.id).message
end
def send_admin_notification
::Notify.send_admin_notification(user.id, 'Email subject from admin', 'Email body from admin').message
end
def send_unsubscribed_notification
::Notify.send_unsubscribed_notification(user.id).message
end
def service_desk_new_note_email
cleanup do
note = create_note(noteable_type: 'Issue', noteable_id: issue.id, note: 'Issue note content')
::Notify.service_desk_new_note_email(issue.id, note.id).message
end
end
def service_desk_thank_you_email
::Notify.service_desk_thank_you_email(issue.id).message
end
end
private
def approver
@user ||= ::User.first
end
end
end
end
......@@ -195,4 +195,63 @@ describe Notify do
end
end
end
describe 'mirror was hard failed' do
let(:project) { create(:project, :mirror, :import_hard_failed) }
subject { described_class.mirror_was_hard_failed_email(project.id, user.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject and body' do
is_expected.to have_subject("#{project.name} | Repository mirroring paused")
is_expected.to have_body_text(project.full_path)
is_expected.to have_body_text(project_settings_repository_url(project))
end
end
describe 'mirror user changed' do
let(:mirror_user) { create(:user) }
let(:project) { create(:project, :mirror, mirror_user_id: mirror_user.id) }
let(:new_mirror_user) { project.team.owners.first }
subject { described_class.project_mirror_user_changed_email(new_mirror_user.id, mirror_user.name, project.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject and body' do
is_expected.to have_subject("#{project.name} | Mirror user changed")
is_expected.to have_body_text(project.full_path)
end
end
describe 'admin notification' do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
subject { @email = described_class.send_admin_notification(user.id, 'Admin announcement', 'Text') }
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq("GitLab")
expect(sender.address).to eq(gitlab_sender)
end
it 'is sent to recipient' do
is_expected.to deliver_to user.email
end
it 'has the correct subject' do
is_expected.to have_subject 'Admin announcement'
end
it 'includes unsubscribe link' do
unsubscribe_link = "http://localhost/unsubscribes/#{Base64.urlsafe_encode64(user.email)}"
is_expected.to have_body_text(unsubscribe_link)
end
end
end
......@@ -1359,65 +1359,6 @@ describe Notify do
end
end
describe 'mirror was hard failed' do
let(:project) { create(:project, :mirror, :import_hard_failed) }
subject { described_class.mirror_was_hard_failed_email(project.id, user.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject and body' do
is_expected.to have_subject("#{project.name} | Repository mirroring paused")
is_expected.to have_body_text(project.full_path)
is_expected.to have_body_text(project_settings_repository_url(project))
end
end
describe 'mirror user changed' do
let(:mirror_user) { create(:user) }
let(:project) { create(:project, :mirror, mirror_user_id: mirror_user.id) }
let(:new_mirror_user) { project.team.owners.first }
subject { described_class.project_mirror_user_changed_email(new_mirror_user.id, mirror_user.name, project.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject and body' do
is_expected.to have_subject("#{project.name} | Mirror user changed")
is_expected.to have_body_text(project.full_path)
end
end
describe 'admin notification' do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
subject { @email = described_class.send_admin_notification(user.id, 'Admin announcement', 'Text') }
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq("GitLab")
expect(sender.address).to eq(gitlab_sender)
end
it 'is sent to recipient' do
is_expected.to deliver_to user.email
end
it 'has the correct subject' do
is_expected.to have_subject 'Admin announcement'
end
it 'includes unsubscribe link' do
unsubscribe_link = "http://localhost/unsubscribes/#{Base64.urlsafe_encode64(user.email)}"
is_expected.to have_body_text(unsubscribe_link)
end
end
describe 'HTML emails setting' do
let(:multipart_mail) { described_class.project_was_moved_email(project.id, user.id, "gitlab/gitlab") }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment