diff --git a/app/mailers/newflow_mailer.rb b/app/mailers/newflow_mailer.rb
index 2b1d439d3..47afe9c9b 100644
--- a/app/mailers/newflow_mailer.rb
+++ b/app/mailers/newflow_mailer.rb
@@ -16,7 +16,8 @@ def reset_password_email(user:, email_address:)
end
def signup_email_confirmation(email_address:, show_pin: true)
- @should_show_pin = show_pin && ConfirmByPin.sequential_failure_for(email_address).attempts_remaining?
+ @should_show_pin = show_pin != false &&
+ ConfirmByPin.sequential_failure_for(email_address).attempts_remaining?
@email_value = email_address.value
@confirmation_pin = email_address.confirmation_pin
@confirmation_code = email_address.confirmation_code
diff --git a/spec/mailers/newflow_mailer_spec.rb b/spec/mailers/newflow_mailer_spec.rb
index bfd88ea73..07dffce9f 100644
--- a/spec/mailers/newflow_mailer_spec.rb
+++ b/spec/mailers/newflow_mailer_spec.rb
@@ -15,24 +15,34 @@ module Newflow
expect(mail.body.encoded).to include("Welcome to OpenStax!")
end
- it "has PIN info" do
- allow(ConfirmByPin).to receive(:sequential_failure_for) { Hashie::Mash.new('attempts_remaining?' => true)}
+ context 'when show_pin is not sent' do
+ it 'includes PIN info in the email' do
+ mail = NewflowMailer.signup_email_confirmation(email_address: email)
+
+ expect(mail.subject).to eq("[OpenStax] Your OpenStax account PIN has arrived: #{pin}")
+ expect(mail.body.encoded).to include(confirmation_url)
+ expect(mail.body.encoded).to include("use your pin: #{pin}")
+ end
+ end
- mail = NewflowMailer.signup_email_confirmation email_address: email
+ context 'when show_pin is nil' do
+ it 'includes PIN info in the email' do
+ mail = NewflowMailer.signup_email_confirmation(email_address: email, show_pin: nil)
- expect(mail.subject).to eq("[OpenStax] Your OpenStax account PIN has arrived: 123456")
- expect(mail.body.encoded).to include('123456')
+ expect(mail.subject).to eq("[OpenStax] Your OpenStax account PIN has arrived: #{pin}")
+ expect(mail.body.encoded).to include(confirmation_url)
+ expect(mail.body.encoded).to include("use your pin: #{pin}")
+ end
end
- it "excludes pin code" do
- allow(ConfirmByPin).to receive(:sequential_failure_for) { Hashie::Mash.new('attempts_remaining?' => true)}
-
- mail = NewflowMailer.signup_email_confirmation email_address: email, show_pin: false
+ context 'when show_pin is false' do
+ it 'excludes the pin code from the email' do
+ mail = NewflowMailer.signup_email_confirmation(email_address: email, show_pin: false)
- expect(mail.subject).to eq("[OpenStax] Confirm your email address")
- expect(mail.body.encoded).to include('123456')
+ expect(mail.subject).to eq("[OpenStax] Confirm your email address")
+ expect(mail.body.encoded).to include(confirmation_url)
+ expect(mail.body.encoded).not_to include("use your pin: #{pin}")
+ end
end
end
end