From 4dc0f0e5be2dc12276b00689b03e21a6f2ac2280 Mon Sep 17 00:00:00 2001 From: drummer83 Date: Tue, 26 Dec 2023 20:52:56 +0100 Subject: [PATCH 1/4] Create styled email for reset password instructions --- .../reset_password_instructions.html.haml | 15 +++++++++++++++ config/locales/en.yml | 1 + 2 files changed, 16 insertions(+) create mode 100644 app/views/spree/user_mailer/reset_password_instructions.html.haml diff --git a/app/views/spree/user_mailer/reset_password_instructions.html.haml b/app/views/spree/user_mailer/reset_password_instructions.html.haml new file mode 100644 index 00000000000..69a2f26f065 --- /dev/null +++ b/app/views/spree/user_mailer/reset_password_instructions.html.haml @@ -0,0 +1,15 @@ +%h3 + = t('.dear_customer') +%p + = t('.request_sent_text') + +%p.callout + = t('.link_text') + %br + %strong + = link_to @edit_password_reset_url, @edit_password_reset_url + +%p + = t('.issue_text') + += render 'shared/mailers/signoff' diff --git a/config/locales/en.yml b/config/locales/en.yml index c899680a2a0..6a1bf09e237 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4823,6 +4823,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using invoice_attached_text: Please find attached an invoice for your recent order from user_mailer: reset_password_instructions: + dear_customer: "Dear customer," request_sent_text: | A request to reset your password has been made. If you did not make this request, simply ignore this email. From c9f5dd2d0b3fdfe02d12728d1b5238d47b7fa2b1 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 18 Feb 2025 16:02:39 +1100 Subject: [PATCH 2/4] Refactor: rename subject to be consistent Hmm, in different specs it gets called 'mail', 'email', 'message'. The object is a Mail::Message object. The method to generate the object is called `mail`, so I went with that. --- spec/mailers/user_mailer_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 14dbb566f34..1d1e80e5076 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -35,15 +35,15 @@ describe "#confirmation_instructions" do let(:token) { "random" } - subject(:email) { Spree::UserMailer.confirmation_instructions(user, token) } + subject(:mail) { Spree::UserMailer.confirmation_instructions(user, token) } it "sends an email" do - expect { email.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { mail.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end context 'when the language is English' do it 'sends an email with the translated subject' do - email.deliver_now + mail.deliver_now expect(ActionMailer::Base.deliveries.first.subject).to include( "Please confirm your OFN account" @@ -55,7 +55,7 @@ let(:user) { build(:user, locale: 'es') } it 'sends an email with the translated subject' do - email.deliver_now + mail.deliver_now expect(ActionMailer::Base.deliveries.first.subject).to include( "Por favor, confirma tu cuenta de OFN" @@ -67,21 +67,21 @@ # adapted from https://github.com/spree/spree_auth_devise/blob/70737af/spec/mailers/user_mailer_spec.rb describe '#reset_password_instructions' do describe 'message contents' do - let(:message) { described_class.reset_password_instructions(user, nil).deliver_now } + subject(:mail) { described_class.reset_password_instructions(user, nil).deliver_now } context 'subject includes' do it 'translated devise instructions' do - expect(message.subject).to include "Reset password instructions" + expect(mail.subject).to include "Reset password instructions" end it 'Spree site name' do - expect(message.subject).to include Spree::Config[:site_name] + expect(mail.subject).to include Spree::Config[:site_name] end end context 'body includes' do it 'password reset url' do - expect(message.body.raw_source).to include spree.edit_spree_user_password_url + expect(mail.body.raw_source).to include spree.edit_spree_user_password_url end end @@ -90,12 +90,12 @@ it 'calls with_locale method with user selected locale' do expect(I18n).to receive(:with_locale).with('es') - message + mail end it 'calls devise reset_password_instructions subject' do expect(I18n).to receive(:t).with('spree.user_mailer.reset_password_instructions.subject') - message + mail end end end From 664119ddcf1931da04c69f58fc151a8876e80883 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 18 Feb 2025 16:15:04 +1100 Subject: [PATCH 3/4] Update test for multi-part email Now that it's a multi-part email, we have to select the html part for the test. Another option is to simply check mail.to_s, but this also includes mail headers so doesn't specifically test the body. --- spec/mailers/user_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 1d1e80e5076..7fb020f362e 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -81,7 +81,7 @@ context 'body includes' do it 'password reset url' do - expect(mail.body.raw_source).to include spree.edit_spree_user_password_url + expect(mail.html_part.body).to include spree.edit_spree_user_password_url end end From 859a20b7a74c3554847fbe9d1690eead254e82af Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 19 Feb 2025 14:20:28 +1100 Subject: [PATCH 4/4] Ensure both email formats contain url --- spec/mailers/user_mailer_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 7fb020f362e..9e9dc8e7adf 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -81,6 +81,7 @@ context 'body includes' do it 'password reset url' do + expect(mail.text_part.body).to include spree.edit_spree_user_password_url expect(mail.html_part.body).to include spree.edit_spree_user_password_url end end