From 3ec8c12899b5ed5d9aa5d43e83b7399edd7b7266 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 8 Oct 2018 20:41:59 +0100 Subject: [PATCH 1/2] Update account setting spec for updating email address --- spec/features/consumer/account/settings_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index 383d03a4be..64cdff0f05 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -18,7 +18,12 @@ feature "Account Settings", js: true do expect(page).to have_content I18n.t('spree.users.form.account_settings') fill_in 'user_email', with: 'new@email.com' - click_button I18n.t(:update) + expect do + click_button I18n.t(:update) + end.to send_confirmation_instructions + + sent_mail = ActionMailer::Base.deliveries.last + expect(sent_mail.to).to eq ['new@email.com'] expect(find(".alert-box.success").text.strip).to eq "#{I18n.t(:account_updated)} ×" user.reload From 8f5fd41c8bf2dd2bd7f1d963e9ce9006e633d3f5 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 8 Oct 2018 21:30:49 +0100 Subject: [PATCH 2/2] Update email confirmation address --- app/mailers/spree/user_mailer_decorator.rb | 8 +++++++- spec/models/spree/user_spec.rb | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb index 3921d3c648..dced31e7fd 100644 --- a/app/mailers/spree/user_mailer_decorator.rb +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -13,8 +13,14 @@ Spree::UserMailer.class_eval do @contact = ContentConfig.footer_email subject = t('spree.user_mailer.confirmation_instructions.subject') - mail(to: user.email, + mail(to: confirmation_email_address, from: from_address, subject: subject) end + + private + + def confirmation_email_address + @user.pending_reconfirmation? ? @user.unconfirmed_email : @user.email + end end diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index db0af97d15..ae54a9eca0 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -75,8 +75,11 @@ describe Spree.user_class do create(:mail_method) expect do - create(:user, confirmation_sent_at: nil, confirmed_at: nil) + create(:user, email: 'new_user@example.com', confirmation_sent_at: nil, confirmed_at: nil) end.to send_confirmation_instructions + + sent_mail = ActionMailer::Base.deliveries.last + expect(sent_mail.to).to eq ['new_user@example.com'] end context "with the the same email as existing customers" do