From 2e6bf60f1549e5c1f1cfea2d614f978bea17b8a2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 27 Oct 2023 11:33:52 -0400 Subject: [PATCH] Use `deliveries.size` in mailer-related examples in controller specs (#27589) --- .../admin/disputes/appeals_controller_spec.rb | 12 ++++++------ spec/controllers/auth/sessions_controller_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/controllers/admin/disputes/appeals_controller_spec.rb b/spec/controllers/admin/disputes/appeals_controller_spec.rb index 3f4175a281..4581d00d6f 100644 --- a/spec/controllers/admin/disputes/appeals_controller_spec.rb +++ b/spec/controllers/admin/disputes/appeals_controller_spec.rb @@ -33,8 +33,6 @@ RSpec.describe Admin::Disputes::AppealsController do let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } before do - allow(UserMailer).to receive(:appeal_approved) - .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil)) post :approve, params: { id: appeal.id } end @@ -47,7 +45,9 @@ RSpec.describe Admin::Disputes::AppealsController do end it 'notifies target account about approved appeal' do - expect(UserMailer).to have_received(:appeal_approved).with(target_account.user, appeal) + expect(UserMailer.deliveries.size).to eq(1) + expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email) + expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))) end end @@ -55,8 +55,6 @@ RSpec.describe Admin::Disputes::AppealsController do let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } before do - allow(UserMailer).to receive(:appeal_rejected) - .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil)) post :reject, params: { id: appeal.id } end @@ -65,7 +63,9 @@ RSpec.describe Admin::Disputes::AppealsController do end it 'notifies target account about rejected appeal' do - expect(UserMailer).to have_received(:appeal_rejected).with(target_account.user, appeal) + expect(UserMailer.deliveries.size).to eq(1) + expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email) + expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))) end end end diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index c727a76333..3ff9b15007 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -127,8 +127,6 @@ RSpec.describe Auth::SessionsController do before do allow_any_instance_of(ActionDispatch::Request).to receive(:remote_ip).and_return(current_ip) - allow(UserMailer).to receive(:suspicious_sign_in) - .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later!: nil)) user.update(current_sign_in_at: 1.month.ago) post :create, params: { user: { email: user.email, password: user.password } } end @@ -142,7 +140,9 @@ RSpec.describe Auth::SessionsController do end it 'sends a suspicious sign-in mail' do - expect(UserMailer).to have_received(:suspicious_sign_in).with(user, current_ip, anything, anything) + expect(UserMailer.deliveries.size).to eq(1) + expect(UserMailer.deliveries.first.to.first).to eq(user.email) + expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.suspicious_sign_in.subject')) end end