Extract `subject` from `User#mark_email_as_confirmed!` spec (#29231)

This commit is contained in:
Matt Jankowski 2024-02-16 08:01:04 -05:00 committed by GitHub
parent 1690fb39e6
commit 117b507df5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 14 deletions

View File

@ -451,35 +451,32 @@ RSpec.describe User do
end end
describe '#mark_email_as_confirmed!' do describe '#mark_email_as_confirmed!' do
subject(:user) { Fabricate(:user, confirmed_at: confirmed_at) } subject { user.mark_email_as_confirmed! }
before do let!(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
ActionMailer::Base.deliveries.clear
user.mark_email_as_confirmed! before { ActionMailer::Base.deliveries.clear }
end
after { ActionMailer::Base.deliveries.clear } after { ActionMailer::Base.deliveries.clear }
context 'when user is new' do context 'when user is new' do
let(:confirmed_at) { nil } let(:confirmed_at) { nil }
it 'confirms user' do it 'confirms user and delivers welcome email', :sidekiq_inline do
expect(user.confirmed_at).to be_present subject
end
it 'delivers mails', :sidekiq_inline do expect(user.confirmed_at).to be_present
expect(ActionMailer::Base.deliveries.count).to eq 2 expect(ActionMailer::Base.deliveries.count).to eq 1
end end
end end
context 'when user is not new' do context 'when user is not new' do
let(:confirmed_at) { Time.zone.now } let(:confirmed_at) { Time.zone.now }
it 'confirms user' do it 'confirms user but does not deliver welcome email' do
expect(user.confirmed_at).to be_present subject
end
it 'does not deliver mail' do expect(user.confirmed_at).to be_present
expect(ActionMailer::Base.deliveries.count).to eq 0 expect(ActionMailer::Base.deliveries.count).to eq 0
end end
end end