Skip to content

Commit

Permalink
Sends recover email to main email address & fallback
Browse files Browse the repository at this point in the history
Issue on production with user not recieving email on their main email address,
only getting sent to the fallback email. Decided to just send one email with
both address (doubt why, should just be the email used in recovery).
MacTwister committed Dec 19, 2023
1 parent aea5c09 commit 6b5ba5c
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -65,9 +65,7 @@ def account_recovery_instructions user_id
@user = User.find(user_id)
emails = [@user.email_string, @user.email_fallback].reject(&:blank?)

emails.each do |email|
mail(to: email, from: "FabLabs.io <[email protected]>", subject: "Account Recovery Instructions")
end
mail(to: emails, from: "FabLabs.io <[email protected]>", subject: "Account Recovery Instructions")
rescue ActiveRecord::RecordNotFound
end
end
13 changes: 11 additions & 2 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@

describe UserMailer, type: :mailer do

let(:user_emails) { ['[email protected]', '[email protected]'] }

let(:lab) { FactoryBot.create(:lab) }
let(:user) { FactoryBot.create(:user) }
let(:user) { FactoryBot.create(:user, email: user_emails[0], email_fallback: user_emails[1]) }
let(:employee) { FactoryBot.create(:employee, user: user, lab: lab) }

%w(
@@ -57,9 +59,16 @@
recovery = FactoryBot.create(:recovery, user: user, email_or_username: [user.email, user.username].sample)
mail = UserMailer.account_recovery_instructions(user.id)
expect(mail.subject).to match("Account Recovery Instructions")
expect(mail.to).to eq([user.email])
expect(mail.to).to eq(['email@bitsushi.com', '[email protected]'])
expect(mail.from).to eq(["[email protected]"])
expect(mail.body.encoded).to match( recovery_url(user.recovery_key) )
end

it "account_recovery_instructions_single" do
simpleuser = FactoryBot.create(:user, email: '[email protected]')
recovery = FactoryBot.create(:recovery, user: simpleuser, email_or_username: [simpleuser.email, simpleuser.username].sample)
mail = UserMailer.account_recovery_instructions(simpleuser.id)
expect(mail.to).to eq(['[email protected]'])
end

end

0 comments on commit 6b5ba5c

Please sign in to comment.