From e8d2c2579383897a1dd7f9debd359abe8ae8373d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 20 Jul 2021 09:55:51 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-1-stable-ee --- spec/mailers/emails/admin_notification_spec.rb | 11 ++++++++ spec/mailers/emails/releases_spec.rb | 2 +- spec/mailers/emails/service_desk_spec.rb | 14 +-------- spec/mailers/notify_spec.rb | 39 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 spec/mailers/emails/admin_notification_spec.rb (limited to 'spec/mailers') diff --git a/spec/mailers/emails/admin_notification_spec.rb b/spec/mailers/emails/admin_notification_spec.rb new file mode 100644 index 00000000000..90381eb8ffd --- /dev/null +++ b/spec/mailers/emails/admin_notification_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Emails::AdminNotification do + it 'adds email methods to Notify' do + subject.instance_methods.each do |email_method| + expect(Notify).to be_respond_to(email_method) + end + end +end diff --git a/spec/mailers/emails/releases_spec.rb b/spec/mailers/emails/releases_spec.rb index 287971d35a8..d1d7f5e6d6a 100644 --- a/spec/mailers/emails/releases_spec.rb +++ b/spec/mailers/emails/releases_spec.rb @@ -56,7 +56,7 @@ RSpec.describe Emails::Releases do let(:release) { create(:release, project: project, description: "Attachment: [Test file](#{upload_path})") } it 'renders absolute links' do - is_expected.to have_body_text(%Q(Test file)) + is_expected.to have_body_text(%Q(Test file)) end end end diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index 995e6c006cd..28011456a66 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -115,16 +115,6 @@ RSpec.describe Emails::ServiceDesk do end end - shared_examples 'notification with metric event' do |event_type| - it 'adds metric event' do - metric_transaction = double('Gitlab::Metrics::WebTransaction', increment: true, observe: true) - allow(::Gitlab::Metrics::BackgroundTransaction).to receive(:current).and_return(metric_transaction) - expect(metric_transaction).to receive(:add_event).with(event_type) - - subject.content_type - end - end - describe '.service_desk_thank_you_email' do let_it_be(:reply_in_subject) { true } let_it_be(:default_text) do @@ -134,7 +124,6 @@ RSpec.describe Emails::ServiceDesk do subject { ServiceEmailClass.service_desk_thank_you_email(issue.id) } it_behaves_like 'read template from repository', 'thank_you' - it_behaves_like 'notification with metric event', :service_desk_thank_you_email context 'handling template markdown' do context 'with a simple text' do @@ -175,7 +164,6 @@ RSpec.describe Emails::ServiceDesk do subject { ServiceEmailClass.service_desk_new_note_email(issue.id, note.id, email) } it_behaves_like 'read template from repository', 'new_note' - it_behaves_like 'notification with metric event', :service_desk_new_note_email context 'handling template markdown' do context 'with a simple text' do @@ -211,7 +199,7 @@ RSpec.describe Emails::ServiceDesk do let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [file](#{upload_path})") } let(:template_content) { 'some text %{ NOTE_TEXT }' } - let(:expected_body) { %Q(some text a new comment with file) } + let(:expected_body) { %Q(some text a new comment with file) } it_behaves_like 'handle template content', 'new_note' end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 8ee88776107..ae956adf563 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1609,6 +1609,32 @@ RSpec.describe Notify do end 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 describe 'confirmation if email changed' do @@ -1969,6 +1995,19 @@ RSpec.describe Notify do end end + describe 'in product marketing', :mailer do + let_it_be(:group) { create(:group) } + + let(:mail) { ActionMailer::Base.deliveries.last } + + it 'does not raise error' do + described_class.in_product_marketing_email(user.id, group.id, :trial, 0).deliver + + expect(mail.subject).to eq('Go farther with GitLab') + 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 + def expect_sender(user) sender = subject.header[:from].addrs[0] expect(sender.display_name).to eq("#{user.name} (@#{user.username})") -- cgit v1.2.3