From 16e2a9ceaf46539d4a33b8d0ffaa1b189b7a7d79 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Mon, 2 Sep 2024 10:23:21 +0100 Subject: [PATCH] [issue-4351] add test cases to both UserInfoChangedMailerWorker and UserInfoChangedMailer --- spec/mailers/user_info_changed_mailer_spec.rb | 7 ++++++- .../workers/user_info_changed_mailer_worker_spec.rb | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/mailers/user_info_changed_mailer_spec.rb b/spec/mailers/user_info_changed_mailer_spec.rb index 614a28ccd..420e1db33 100644 --- a/spec/mailers/user_info_changed_mailer_spec.rb +++ b/spec/mailers/user_info_changed_mailer_spec.rb @@ -21,10 +21,15 @@ end context "email address was changed" do - let(:mail) { UserInfoChangedMailer.user_info_changed(user, "email")} + prev_email = 'prev@example.com' + let(:mail) { UserInfoChangedMailer.user_info_changed(user, "email", prev_email)} it 'should have the correct subject' do expect(mail.subject).to eq("Your Zooniverse email address has been changed") end + + it 'should notify the previous mail' do + expect(mail.to).to include(prev_email) + end end end end diff --git a/spec/workers/user_info_changed_mailer_worker_spec.rb b/spec/workers/user_info_changed_mailer_worker_spec.rb index 7643ad8e9..c06667649 100644 --- a/spec/workers/user_info_changed_mailer_worker_spec.rb +++ b/spec/workers/user_info_changed_mailer_worker_spec.rb @@ -4,8 +4,17 @@ let(:project) { create(:project) } let(:user) { create(:user) } - it 'should deliver the mail' do - expect{ subject.perform(user.id, "password") }.to change{ ActionMailer::Base.deliveries.count }.by(1) + context 'email delivery' do + it 'should deliver the mail' do + expect{ subject.perform(user.id, "password") }.to change{ ActionMailer::Base.deliveries.count }.by(1) + end + + it 'should deliver to the right recipients' do + prev_pass = 'oldpassword@example.com' + subject.perform(user.id, "email", prev_pass) + mail = ActionMailer::Base.deliveries.last + expect(mail.to).to eq([user.email, prev_pass]) + end end context "without a user" do