-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-4351] add logic to notify old user email of email change (#4374)
* [issue-4351] add logic to notify old user email of email change * [issue-4351] hound cleanups * [issue-4351] move UserInfoChangedMailer call outside super to prevent race condition * [issue-4351] edit test case to reflect old mail sent * [issue-4351] add test cases to both UserInfoChangedMailerWorker and UserInfoChangedMailer * [issue-4351] hound cleanups * [issue-4351] hound cleanups * [issue-4351] renaming test variables
- Loading branch information
Showing
6 changed files
with
35 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
class UserInfoChangedMailer < ApplicationMailer | ||
layout false | ||
|
||
def user_info_changed(user, info) | ||
def user_info_changed(user, info, previous_email=nil) | ||
@user = user | ||
@email_to = user.email | ||
@recipient_emails = [user.email] | ||
|
||
case info | ||
when "email" | ||
subject = "Your Zooniverse email address has been changed" | ||
template = "email_changed" | ||
@recipient_emails << previous_email if previous_email | ||
when "password" | ||
subject = "Your Zooniverse password has been changed" | ||
template = "password_changed" | ||
end | ||
|
||
mail(to: @email_to, subject: subject, :template_name => template ) | ||
mail(to: @recipient_emails, subject: subject, template_name: template) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,13 +473,14 @@ def update_request | |
|
||
context "when changing email" do | ||
let(:put_operations) { {users: {email: "[email protected]"}} } | ||
let!(:user_email) { user.email } | ||
|
||
after(:each) do | ||
update_request | ||
end | ||
|
||
it "sends an email to the new address if user is valid" do | ||
expect(UserInfoChangedMailerWorker).to receive(:perform_async).with(user.id, "email") | ||
it "sends an email to the new and old address if user is valid" do | ||
expect(UserInfoChangedMailerWorker).to receive(:perform_async).with(user.id, "email", user_email) | ||
end | ||
|
||
it "sets valid_email parameter to true" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,16 @@ | |
end | ||
|
||
context "email address was changed" do | ||
let(:mail) { UserInfoChangedMailer.user_info_changed(user, "email")} | ||
prev_email = '[email protected]' | ||
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 'notifies the previous mail' do | ||
expect(mail.to).to include(prev_email) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,18 @@ | |
RSpec.describe UserInfoChangedMailerWorker do | ||
let(:project) { create(:project) } | ||
let(:user) { create(:user) } | ||
let(:prev_email) { '[email protected]' } | ||
|
||
it 'should deliver the mail' do | ||
expect{ subject.perform(user.id, "password") }.to change{ ActionMailer::Base.deliveries.count }.by(1) | ||
context 'when delivering an email' do | ||
it 'delivers the mail' do | ||
expect { subject.perform(user.id, 'password') }.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
|
||
it 'delivers to the right recipients' do | ||
subject.perform(user.id, 'email', prev_email) | ||
mail = ActionMailer::Base.deliveries.last | ||
expect(mail.to).to eq([user.email, prev_email]) | ||
end | ||
end | ||
|
||
context "without a user" do | ||
|