Add coverage and use mailer callback to check functional user in notification mailer (#32055)
This commit is contained in:
		@@ -3,6 +3,17 @@
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe NotificationMailer do
 | 
			
		||||
  shared_examples 'delivery to non functional user' do
 | 
			
		||||
    context 'when user is not functional' do
 | 
			
		||||
      before { receiver.update(confirmed_at: nil) }
 | 
			
		||||
 | 
			
		||||
      it 'does not deliver mail' do
 | 
			
		||||
        emails = capture_emails { mail.deliver_now }
 | 
			
		||||
        expect(emails).to be_empty
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  let(:receiver)       { Fabricate(:user, account_attributes: { username: 'alice' }) }
 | 
			
		||||
  let(:sender)         { Fabricate(:account, username: 'bob') }
 | 
			
		||||
  let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') }
 | 
			
		||||
@@ -24,6 +35,8 @@ RSpec.describe NotificationMailer do
 | 
			
		||||
        .and have_thread_headers
 | 
			
		||||
        .and have_standard_headers('mention').for(receiver)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    include_examples 'delivery to non functional user'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'follow' do
 | 
			
		||||
@@ -40,6 +53,8 @@ RSpec.describe NotificationMailer do
 | 
			
		||||
        .and(have_body_text('bob is now following you'))
 | 
			
		||||
        .and have_standard_headers('follow').for(receiver)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    include_examples 'delivery to non functional user'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'favourite' do
 | 
			
		||||
@@ -58,6 +73,8 @@ RSpec.describe NotificationMailer do
 | 
			
		||||
        .and have_thread_headers
 | 
			
		||||
        .and have_standard_headers('favourite').for(receiver)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    include_examples 'delivery to non functional user'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'reblog' do
 | 
			
		||||
@@ -76,6 +93,8 @@ RSpec.describe NotificationMailer do
 | 
			
		||||
        .and have_thread_headers
 | 
			
		||||
        .and have_standard_headers('reblog').for(receiver)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    include_examples 'delivery to non functional user'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'follow_request' do
 | 
			
		||||
@@ -92,6 +111,8 @@ RSpec.describe NotificationMailer do
 | 
			
		||||
        .and(have_body_text('bob has requested to follow you'))
 | 
			
		||||
        .and have_standard_headers('follow_request').for(receiver)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    include_examples 'delivery to non functional user'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user