From 6b21bbdf746f3d8d2f460d863207c01463e39745 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 12 Nov 2014 12:30:32 +1100 Subject: [PATCH] Reconfirmation email sends to the right address --- app/mailers/enterprise_mailer.rb | 2 +- spec/mailers/enterprise_mailer_spec.rb | 28 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index 2e6e83d92c..7504597589 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -15,7 +15,7 @@ class EnterpriseMailer < Spree::BaseMailer find_enterprise(record) opts = { subject: "Please confirm your email for #{@enterprise.name}", - to: @enterprise.email, + to: ( @enterprise.unconfirmed_email || @enterprise.email ), from: from_address, } devise_mail(record, :confirmation_instructions, opts) diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 5797fcbbb1..65480ccdad 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -7,11 +7,29 @@ describe EnterpriseMailer do ActionMailer::Base.deliveries = [] end - it "should send an email confirmation when given an enterprise" do - EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver - ActionMailer::Base.deliveries.count.should == 1 - mail = ActionMailer::Base.deliveries.first - expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}" + context "when given an enterprise without an unconfirmed_email" do + it "should send an email confirmation to email" do + EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver + ActionMailer::Base.deliveries.count.should == 1 + mail = ActionMailer::Base.deliveries.first + expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}" + expect(mail.to).to include enterprise.email + end + end + + context "when given an enterprise with an unconfirmed_email" do + before do + enterprise.unconfirmed_email = "unconfirmed@email.com" + enterprise.save! + end + + it "should send an email confirmation to unconfirmed_email" do + EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver + ActionMailer::Base.deliveries.count.should == 1 + mail = ActionMailer::Base.deliveries.first + expect(mail.subject).to eq "Please confirm your email for #{enterprise.name}" + expect(mail.to).to include enterprise.unconfirmed_email + end end it "should send a welcome email when given an enterprise" do