summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/abuse_report_mailer_spec.rb2
-rw-r--r--spec/mailers/devise_mailer_spec.rb38
-rw-r--r--spec/mailers/email_rejection_mailer_spec.rb2
-rw-r--r--spec/mailers/emails/auto_devops_spec.rb2
-rw-r--r--spec/mailers/emails/groups_spec.rb2
-rw-r--r--spec/mailers/emails/issues_spec.rb2
-rw-r--r--spec/mailers/emails/merge_requests_spec.rb18
-rw-r--r--spec/mailers/emails/pages_domains_spec.rb2
-rw-r--r--spec/mailers/emails/pipelines_spec.rb2
-rw-r--r--spec/mailers/emails/profile_spec.rb2
-rw-r--r--spec/mailers/emails/projects_spec.rb2
-rw-r--r--spec/mailers/emails/releases_spec.rb2
-rw-r--r--spec/mailers/emails/service_desk_spec.rb188
-rw-r--r--spec/mailers/notify_spec.rb83
-rw-r--r--spec/mailers/repository_check_mailer_spec.rb2
15 files changed, 333 insertions, 16 deletions
diff --git a/spec/mailers/abuse_report_mailer_spec.rb b/spec/mailers/abuse_report_mailer_spec.rb
index fcbffb52849..4eb616722ac 100644
--- a/spec/mailers/abuse_report_mailer_spec.rb
+++ b/spec/mailers/abuse_report_mailer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AbuseReportMailer do
+RSpec.describe AbuseReportMailer do
include EmailSpec::Matchers
describe '.notify' do
diff --git a/spec/mailers/devise_mailer_spec.rb b/spec/mailers/devise_mailer_spec.rb
new file mode 100644
index 00000000000..4637df9c8a3
--- /dev/null
+++ b/spec/mailers/devise_mailer_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'email_spec'
+
+RSpec.describe DeviseMailer do
+ describe "#confirmation_instructions" do
+ subject { described_class.confirmation_instructions(user, 'faketoken', {}) }
+
+ context "when confirming a new account" do
+ let(:user) { build(:user, created_at: 1.minute.ago, unconfirmed_email: nil) }
+
+ it "shows the expected text" do
+ expect(subject.body.encoded).to have_text "Welcome"
+ expect(subject.body.encoded).not_to have_text user.email
+ end
+ end
+
+ context "when confirming the unconfirmed_email" do
+ let(:user) { build(:user, unconfirmed_email: 'jdoe@example.com') }
+
+ it "shows the expected text" do
+ expect(subject.body.encoded).not_to have_text "Welcome"
+ expect(subject.body.encoded).to have_text user.unconfirmed_email
+ expect(subject.body.encoded).not_to have_text user.email
+ end
+ end
+
+ context "when re-confirming the primary email after a security issue" do
+ let(:user) { build(:user, created_at: 10.days.ago, unconfirmed_email: nil) }
+
+ it "shows the expected text" do
+ expect(subject.body.encoded).not_to have_text "Welcome"
+ expect(subject.body.encoded).to have_text user.email
+ end
+ end
+ end
+end
diff --git a/spec/mailers/email_rejection_mailer_spec.rb b/spec/mailers/email_rejection_mailer_spec.rb
index 2ce2e3e1410..d28f034105a 100644
--- a/spec/mailers/email_rejection_mailer_spec.rb
+++ b/spec/mailers/email_rejection_mailer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe EmailRejectionMailer do
+RSpec.describe EmailRejectionMailer do
include EmailSpec::Matchers
describe '#rejection' do
diff --git a/spec/mailers/emails/auto_devops_spec.rb b/spec/mailers/emails/auto_devops_spec.rb
index dd7c12c3143..950fcfbf4df 100644
--- a/spec/mailers/emails/auto_devops_spec.rb
+++ b/spec/mailers/emails/auto_devops_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Emails::AutoDevops do
+RSpec.describe Emails::AutoDevops do
include EmailSpec::Matchers
describe '#auto_devops_disabled_email' do
diff --git a/spec/mailers/emails/groups_spec.rb b/spec/mailers/emails/groups_spec.rb
index b4746e120e0..01846172440 100644
--- a/spec/mailers/emails/groups_spec.rb
+++ b/spec/mailers/emails/groups_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Groups do
+RSpec.describe Emails::Groups do
include EmailSpec::Matchers
let(:group) { create(:group) }
diff --git a/spec/mailers/emails/issues_spec.rb b/spec/mailers/emails/issues_spec.rb
index dfd974aa5f3..21e07c0252d 100644
--- a/spec/mailers/emails/issues_spec.rb
+++ b/spec/mailers/emails/issues_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Issues do
+RSpec.describe Emails::Issues do
include EmailSpec::Matchers
it 'adds email methods to Notify' do
diff --git a/spec/mailers/emails/merge_requests_spec.rb b/spec/mailers/emails/merge_requests_spec.rb
index 541acc47172..477fb16400a 100644
--- a/spec/mailers/emails/merge_requests_spec.rb
+++ b/spec/mailers/emails/merge_requests_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::MergeRequests do
+RSpec.describe Emails::MergeRequests do
include EmailSpec::Matchers
describe "#resolved_all_discussions_email" do
@@ -17,4 +17,20 @@ describe Emails::MergeRequests do
expect(subject).to have_body_text current_user.name
end
end
+
+ describe "#merge_when_pipeline_succeeds_email" do
+ let(:user) { create(:user) }
+ let(:merge_request) { create(:merge_request) }
+ let(:current_user) { create(:user) }
+ let(:project) { create(:project, :repository) }
+ let(:title) { "Merge request #{merge_request.to_reference} was scheduled to merge after pipeline succeeds by #{current_user.name}" }
+
+ subject { Notify.merge_when_pipeline_succeeds_email(user.id, merge_request.id, current_user.id) }
+
+ it "has required details" do
+ expect(subject).to have_content title
+ expect(subject).to have_content merge_request.to_reference
+ expect(subject).to have_content current_user.name
+ end
+ end
end
diff --git a/spec/mailers/emails/pages_domains_spec.rb b/spec/mailers/emails/pages_domains_spec.rb
index 5029a17e4e5..cf17f2e5ebf 100644
--- a/spec/mailers/emails/pages_domains_spec.rb
+++ b/spec/mailers/emails/pages_domains_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::PagesDomains do
+RSpec.describe Emails::PagesDomains do
include EmailSpec::Matchers
include_context 'gitlab email notification'
diff --git a/spec/mailers/emails/pipelines_spec.rb b/spec/mailers/emails/pipelines_spec.rb
index cc901da98dc..f0f23fe2097 100644
--- a/spec/mailers/emails/pipelines_spec.rb
+++ b/spec/mailers/emails/pipelines_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Pipelines do
+RSpec.describe Emails::Pipelines do
include EmailSpec::Matchers
let_it_be(:project) { create(:project, :repository) }
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index cbf42da2085..ee91df360b6 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Profile do
+RSpec.describe Emails::Profile do
include EmailSpec::Matchers
include_context 'gitlab email notification'
diff --git a/spec/mailers/emails/projects_spec.rb b/spec/mailers/emails/projects_spec.rb
index 6c94ed0aa4d..599f62a8113 100644
--- a/spec/mailers/emails/projects_spec.rb
+++ b/spec/mailers/emails/projects_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Projects do
+RSpec.describe Emails::Projects do
include EmailSpec::Matchers
include_context 'gitlab email notification'
diff --git a/spec/mailers/emails/releases_spec.rb b/spec/mailers/emails/releases_spec.rb
index c614c009434..60e522c7cfa 100644
--- a/spec/mailers/emails/releases_spec.rb
+++ b/spec/mailers/emails/releases_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Emails::Releases do
+RSpec.describe Emails::Releases do
include EmailSpec::Matchers
include_context 'gitlab email notification'
diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb
new file mode 100644
index 00000000000..842f82539cb
--- /dev/null
+++ b/spec/mailers/emails/service_desk_spec.rb
@@ -0,0 +1,188 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'email_spec'
+
+RSpec.describe Emails::ServiceDesk do
+ include EmailSpec::Helpers
+ include EmailSpec::Matchers
+ include EmailHelpers
+
+ include_context 'gitlab email notification'
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let(:template) { double(content: template_content) }
+
+ before do
+ stub_const('ServiceEmailClass', Class.new(ApplicationMailer))
+
+ ServiceEmailClass.class_eval do
+ include GitlabRoutingHelper
+ include EmailsHelper
+ include Emails::ServiceDesk
+
+ helper GitlabRoutingHelper
+ helper EmailsHelper
+
+ # this method is implemented in Notify class, we don't need to test it
+ def reply_key
+ 'test-key'
+ end
+
+ # this method is implemented in Notify class, we don't need to test it
+ def sender(author_id, params = {})
+ author_id
+ end
+
+ # this method is implemented in Notify class
+ #
+ # We do not need to test the Notify method, it is already tested in notify_spec
+ def mail_new_thread(issue, options)
+ # we need to rewrite this in order to look up templates in the correct directory
+ self.class.mailer_name = 'notify'
+
+ # this is needed for default layout
+ @unsubscribe_url = 'http://unsubscribe.example.com'
+
+ mail(options)
+ end
+ alias_method :mail_answer_thread, :mail_new_thread
+ end
+ end
+
+ shared_examples 'handle template content' do |template_key|
+ before do
+ expect(Gitlab::Template::ServiceDeskTemplate).to receive(:find)
+ .with(template_key, issue.project)
+ .and_return(template)
+ end
+
+ it 'builds the email correctly' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, include_project: false, reply: reply_in_subject)
+ is_expected.to have_body_text(expected_body)
+ expect(subject.content_type).to include('text/html')
+ end
+ end
+ end
+
+ shared_examples 'read template from repository' do |template_key|
+ let(:template_content) { 'custom text' }
+ let(:issue) { create(:issue, project: project)}
+
+ context 'when a template is in the repository' do
+ let(:project) { create(:project, :custom_repo, files: { ".gitlab/service_desk_templates/#{template_key}.md" => template_content }) }
+
+ it 'uses the text template from the template' do
+ is_expected.to have_body_text(template_content)
+ end
+ end
+
+ context 'when the service_desk_templates directory does not contain correct template' do
+ let(:project) { create(:project, :custom_repo, files: { ".gitlab/service_desk_templates/another_file.md" => template_content }) }
+
+ it 'uses the default template' do
+ is_expected.to have_body_text(default_text)
+ end
+ end
+
+ context 'when the service_desk_templates directory does not exist' do
+ let(:project) { create(:project, :custom_repo, files: { "other_directory/another_file.md" => template_content }) }
+
+ it 'uses the default template' do
+ is_expected.to have_body_text(default_text)
+ end
+ end
+
+ context 'when the project does not have a repo' do
+ let(:project) { create(:project) }
+
+ it 'uses the default template' do
+ is_expected.to have_body_text(default_text)
+ end
+ end
+ end
+
+ describe '.service_desk_thank_you_email' do
+ let_it_be(:reply_in_subject) { true }
+ let_it_be(:default_text) do
+ "Thank you for your support request! We are tracking your request as ticket #{issue.to_reference}, and will respond as soon as we can."
+ end
+
+ subject { ServiceEmailClass.service_desk_thank_you_email(issue.id) }
+
+ it_behaves_like 'read template from repository', 'thank_you'
+
+ context 'handling template markdown' do
+ context 'with a simple text' do
+ let(:template_content) { 'thank you, **your new issue** has been created.' }
+ let(:expected_body) { 'thank you, <strong>your new issue</strong> has been created.' }
+
+ it_behaves_like 'handle template content', 'thank_you'
+ end
+
+ context 'with an issue id and issue path placeholders' do
+ let(:template_content) { 'thank you, **your new issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}' }
+ let(:expected_body) { "thank you, <strong>your new issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}" }
+
+ it_behaves_like 'handle template content', 'thank_you'
+ end
+
+ context 'with an issue id placeholder with whitespace' do
+ let(:template_content) { 'thank you, **your new issue:** %{ ISSUE_ID}' }
+ let(:expected_body) { "thank you, <strong>your new issue:</strong> ##{issue.iid}" }
+
+ it_behaves_like 'handle template content', 'thank_you'
+ end
+
+ context 'with unexpected placeholder' do
+ let(:template_content) { 'thank you, **your new issue:** %{this is issue}' }
+ let(:expected_body) { "thank you, <strong>your new issue:</strong> %{this is issue}" }
+
+ it_behaves_like 'handle template content', 'thank_you'
+ end
+ end
+ end
+
+ describe '.service_desk_new_note_email' do
+ let_it_be(:reply_in_subject) { false }
+ let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project) }
+ let_it_be(:default_text) { note.note }
+
+ subject { ServiceEmailClass.service_desk_new_note_email(issue.id, note.id) }
+
+ it_behaves_like 'read template from repository', 'new_note'
+
+ context 'handling template markdown' do
+ context 'with a simple text' do
+ let(:template_content) { 'thank you, **new note on issue** has been created.' }
+ let(:expected_body) { 'thank you, <strong>new note on issue</strong> has been created.' }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+
+ context 'with an issue id, issue path and note placeholders' do
+ let(:template_content) { 'thank you, **new note on issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}: %{NOTE_TEXT}' }
+ let(:expected_body) { "thank you, <strong>new note on issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}: #{note.note}" }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+
+ context 'with an issue id placeholder with whitespace' do
+ let(:template_content) { 'thank you, **new note on issue:** %{ ISSUE_ID}: %{ NOTE_TEXT }' }
+ let(:expected_body) { "thank you, <strong>new note on issue:</strong> ##{issue.iid}: #{note.note}" }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+
+ context 'with unexpected placeholder' do
+ let(:template_content) { 'thank you, **new note on issue:** %{this is issue}' }
+ let(:expected_body) { "thank you, <strong>new note on issue:</strong> %{this is issue}" }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+ end
+ end
+end
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 8b99cc41a53..e56cd488a52 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Notify do
+RSpec.describe Notify do
include EmailSpec::Helpers
include EmailSpec::Matchers
include EmailHelpers
@@ -105,6 +105,7 @@ describe Notify do
it 'contains a link to issue author' do
is_expected.to have_body_text(issue.author_name)
is_expected.to have_body_text 'created an issue'
+ is_expected.to have_link(issue.to_reference, href: project_issue_url(issue.project, issue))
end
it 'contains a link to the issue' do
@@ -467,6 +468,7 @@ describe Notify do
is_expected.to have_body_text(status)
is_expected.to have_body_text(current_user_sanitized)
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -497,6 +499,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text('merged')
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -534,6 +537,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
is_expected.to have_body_text('due to conflict.')
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -567,6 +571,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text("#{push_user.name} pushed new commits")
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -1175,9 +1180,7 @@ describe Notify do
context 'when note is not on text' do
before do
- allow_next_instance_of(DiffDiscussion) do |instance|
- allow(instance).to receive(:on_text?).and_return(false)
- end
+ allow(note.discussion).to receive(:on_text?).and_return(false)
end
it 'does not include diffs with character-level highlighting' do
@@ -1248,6 +1251,78 @@ describe Notify do
it_behaves_like 'appearance header and footer not enabled'
end
end
+
+ context 'for service desk issues' do
+ before do
+ issue.update!(service_desk_reply_to: 'service.desk@example.com')
+ end
+
+ def expect_sender(username)
+ sender = subject.header[:from].addrs[0]
+ expect(sender.display_name).to eq(username)
+ expect(sender.address).to eq(gitlab_sender)
+ end
+
+ describe 'thank you email' do
+ subject { described_class.service_desk_thank_you_email(issue.id) }
+
+ it_behaves_like 'an unsubscribeable thread'
+
+ it 'has the correct recipient' do
+ is_expected.to deliver_to('service.desk@example.com')
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, include_project: false, reply: true)
+ is_expected.to have_body_text("Thank you for your support request! We are tracking your request as ticket #{issue.to_reference}, and will respond as soon as we can.")
+ end
+ end
+
+ it 'uses service bot name by default' do
+ expect_sender(User.support_bot.name)
+ end
+
+ context 'when custom outgoing name is set' do
+ let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: 'some custom name') }
+
+ it 'uses custom name in "from" header' do
+ expect_sender('some custom name')
+ end
+ end
+
+ context 'when custom outgoing name is empty' do
+ let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: '') }
+
+ it 'uses service bot name' do
+ expect_sender(User.support_bot.name)
+ end
+ end
+ end
+
+ describe 'new note email' do
+ let_it_be(:first_note) { create(:discussion_note_on_issue, note: 'Hello world') }
+
+ subject { described_class.service_desk_new_note_email(issue.id, first_note.id) }
+
+ it_behaves_like 'an unsubscribeable thread'
+
+ it 'has the correct recipient' do
+ is_expected.to deliver_to('service.desk@example.com')
+ end
+
+ it 'uses author\'s name in "from" header' do
+ expect_sender(first_note.author.name)
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, include_project: false, reply: true)
+ is_expected.to have_body_text(first_note.note)
+ end
+ end
+ end
+ end
end
context 'for a group' do
diff --git a/spec/mailers/repository_check_mailer_spec.rb b/spec/mailers/repository_check_mailer_spec.rb
index 1fd4d28ca53..8b1bc33d8be 100644
--- a/spec/mailers/repository_check_mailer_spec.rb
+++ b/spec/mailers/repository_check_mailer_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe RepositoryCheckMailer do
+RSpec.describe RepositoryCheckMailer do
include EmailSpec::Matchers
describe '.notify' do