Skip to content

Commit ea71a61

Browse files
Test forgot password flow stricter
Previously we tested nothing in the email, not even the subject. This means a broken implementation that always would send "can't change password" would not have been discovered. The new test checks the subject (comparable to the other test cases in the same file) and also does not simply assume that the mail will contain the correct link, but rather uses the link from the mail.
1 parent e400fd7 commit ea71a61

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spec/features/auth/lost_password_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@
5252

5353
perform_enqueued_jobs
5454
expect(ActionMailer::Base.deliveries.size).to be 1
55+
mail = ActionMailer::Base.deliveries.first
56+
expect(mail.subject).to eq I18n.t("mail_subject_lost_password", value: Setting.app_title)
5557

5658
# mimic the user clicking on the link in the mail
5759
token = Token::Recovery.first
58-
visit account_lost_password_path(token: token.value)
60+
mail_body = mail.body.parts.find { |p| p.mime_type == "text/html" }.body.to_s
61+
mail_document = Capybara::Node::Simple.new(mail_body)
62+
visit mail_document.find("a")["href"]
5963

6064
fill_in "New password", with: new_password
6165
fill_in "Confirmation", with: new_password

0 commit comments

Comments
 (0)