Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-14 21:08:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-14 21:08:53 +0300
commit5b62f8e3ee531f63ce3c49cae03e2a618ba51615 (patch)
tree2d2553232fe0663957ee4d1054211cc71cb07679 /spec/mailers
parentcdb41961fd2bc233d36c5b30f89d087c2efa9818 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/notify_spec.rb110
1 files changed, 83 insertions, 27 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 38b83a1bb64..eb681846e82 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -143,6 +143,8 @@ RSpec.describe Notify do
it_behaves_like 'an unsubscribeable thread'
it_behaves_like 'appearance header and footer enabled'
it_behaves_like 'appearance header and footer not enabled'
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
it 'is sent as the author' do
expect_sender(current_user)
@@ -152,11 +154,7 @@ RSpec.describe Notify do
aggregate_failures do
is_expected.to have_referable_subject(issue, reply: true)
is_expected.to have_body_text("Assignee changed from <strong>#{previous_assignee.name}</strong> to <strong>#{assignee.name}</strong>")
- is_expected.to have_body_text(%(<a href="#{project_issue_url(project, issue)}">view it on GitLab</a>))
- is_expected.to have_body_text("You're receiving this email because of your account")
is_expected.to have_plain_text_content("Assignee changed from #{previous_assignee.name} to #{assignee.name}")
- is_expected.to have_plain_text_content("view it on GitLab: #{project_issue_url(project, issue)}")
- is_expected.to have_plain_text_content("You're receiving this email because of your account")
end
end
@@ -165,26 +163,24 @@ RSpec.describe Notify do
issue.update!(assignees: [])
end
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
+
it 'uses "Unassigned" placeholder' do
is_expected.to have_body_text("Assignee changed from <strong>#{previous_assignee.name}</strong> to <strong>Unassigned</strong>")
- is_expected.to have_body_text(%(<a href="#{project_issue_url(project, issue)}">view it on GitLab</a>))
- is_expected.to have_body_text("You're receiving this email because of your account")
is_expected.to have_plain_text_content("Assignee changed from #{previous_assignee.name} to Unassigned")
- is_expected.to have_plain_text_content("view it on GitLab: #{project_issue_url(project, issue)}")
- is_expected.to have_plain_text_content("You're receiving this email because of your account")
end
end
context 'without previous assignees' do
subject { described_class.reassigned_issue_email(recipient.id, issue.id, [], current_user.id) }
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
+
it 'uses short text' do
is_expected.to have_body_text("Assignee changed to <strong>#{assignee.name}</strong>")
- is_expected.to have_body_text(%(<a href="#{project_issue_url(project, issue)}">view it on GitLab</a>))
- is_expected.to have_body_text("You're receiving this email because of your account")
is_expected.to have_plain_text_content("Assignee changed to #{assignee.name}")
- is_expected.to have_plain_text_content("view it on GitLab: #{project_issue_url(project, issue)}")
- is_expected.to have_plain_text_content("You're receiving this email because of your account")
end
end
@@ -301,6 +297,81 @@ RSpec.describe Notify do
end
end
+ describe 'closed' do
+ subject { described_class.closed_issue_email(recipient.id, issue.id, current_user.id) }
+
+ it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
+ let(:model) { issue }
+ end
+
+ it_behaves_like 'it should show Gmail Actions View Issue link'
+ it_behaves_like 'an unsubscribeable thread'
+ it_behaves_like 'appearance header and footer enabled'
+ it_behaves_like 'appearance header and footer not enabled'
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
+
+ it 'is sent as the author' do
+ expect_sender(current_user)
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, reply: true)
+ is_expected.to have_body_text("Issue was closed by #{current_user_sanitized}")
+ is_expected.to have_plain_text_content("Issue was closed by #{current_user_sanitized}")
+ end
+ end
+
+ context 'via commit' do
+ let(:closing_commit) { project.commit }
+
+ subject { described_class.closed_issue_email(recipient.id, issue.id, current_user.id, closed_via: closing_commit.id) }
+
+ before do
+ allow(Ability).to receive(:allowed?).with(recipient, :mark_note_as_internal, anything).and_return(true)
+ allow(Ability).to receive(:allowed?).with(recipient, :download_code, project).and_return(true)
+ end
+
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, reply: true)
+ is_expected.to have_body_text("Issue was closed by #{current_user_sanitized} via #{closing_commit.id}")
+ is_expected.to have_plain_text_content("Issue was closed by #{current_user_sanitized} via #{closing_commit.id}")
+ end
+ end
+ end
+
+ context 'via merge request' do
+ let(:closing_merge_request) { merge_request }
+
+ subject { described_class.closed_issue_email(recipient.id, issue.id, current_user.id, closed_via: closing_merge_request) }
+
+ before do
+ allow(Ability).to receive(:allowed?).with(recipient, :read_cross_project, :global).and_return(true)
+ allow(Ability).to receive(:allowed?).with(recipient, :mark_note_as_internal, anything).and_return(true)
+ allow(Ability).to receive(:allowed?).with(recipient, :read_merge_request, anything).and_return(true)
+ end
+
+ it_behaves_like 'email with default notification reason'
+ it_behaves_like 'email with link to issue'
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ url = project_merge_request_url(project, closing_merge_request)
+ is_expected.to have_referable_subject(issue, reply: true)
+ is_expected.to have_body_text("Issue was closed by #{current_user_sanitized} via merge request " +
+ %(<a href="#{url}">#{closing_merge_request.to_reference}</a>))
+ is_expected.to have_plain_text_content("Issue was closed by #{current_user_sanitized} via merge request " \
+ "#{closing_merge_request.to_reference} (#{url})")
+ end
+ end
+ end
+ end
+
describe 'moved to another project' do
let(:new_issue) { create(:issue) }
@@ -2380,19 +2451,4 @@ RSpec.describe Notify do
expect(mail.body.parts.first.to_s).to include('Start a GitLab Ultimate trial today in less than one minute, no credit card required.')
end
end
-
- # can be replaced with https://github.com/email-spec/email-spec/pull/196 in the future
- RSpec::Matchers.define :have_plain_text_content do |expected_text|
- match do |actual_email|
- plain_text_body(actual_email).include? expected_text
- end
-
- failure_message do |actual_email|
- "Expected email\n#{plain_text_body(actual_email).indent(2)}\nto contain\n#{expected_text.indent(2)}"
- end
-
- def plain_text_body(email)
- email.text_part.body.to_s
- end
- end
end