Skip to content

Commit

Permalink
fix default param assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jivey committed Dec 11, 2024
1 parent 23077ff commit 1db1217
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/mailers/newflow_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 23 additions & 13 deletions spec/mailers/newflow_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: <b id='pin'>#{pin}</b>")
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('<a href="http://localhost:2999/i/verify_email_by_code/1234"')
expect(mail.body.encoded).to include('use your pin: <b id=\'pin\'>123456</b>')
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: <b id='pin'>#{pin}</b>")
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('<a href="http://localhost:2999/i/verify_email_by_code/1234"')
expect(mail.body.encoded).not_to include('use your pin: <b id=\'pin\'>123456</b>')
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: <b id='pin'>#{pin}</b>")
end
end
end
end
Expand Down

0 comments on commit 1db1217

Please sign in to comment.