Add email helper methods to spec helper #1306
Replies: 4 comments
-
|
I think it would be a nice addition if we added def open_latest_email_for(email_address)
@current_email = ActionMailer::Base.deliveries.reverse.detect do |email|
email.to.include?(email_address)
end
end
def current_email
@current_email ||= ActionMailer::Base.deliveries.last
end
def email_link(email, string)
document = Capybara.string(email.body.to_s)
link = document.find(:link, string)[:href]
localize_link(link)
end
private
def localize_link(link)
uri = URI.parse(link)
if uri.query
"#{uri.path}?#{uri.query}"
else
uri.path
end
end |
Beta Was this translation helpful? Give feedback.
-
|
This might be rendered obsolete thanks to |
Beta Was this translation helpful? Give feedback.
-
|
I've had good luck with this: class AttorneysTest < ApplicationSystemTestCase
include ActionMailer::TestHelper
test "creating an account" do
visit new_attorney_registration_path
email = capture_emails do
fill_in "Name", with: "Chuck McGill"
fill_in "Email", with: "chuck@hhm.com"
fill_in "Password", with: "password"
fill_in "Password confirmation", with: "password"
click_button "Sign up"
end
assert_text I18n.t("devise.registrations.signed_up_but_unconfirmed")
click_link(email.first, "Confirm my account")
assert_text I18n.t("devise.confirmations.confirmed")
end
def click_link(email, string)
document = Capybara.string(email.body.to_s)
link = document.find(:link, string)[:href]
visit localize_link(link)
end
def localize_link(link)
uri = URI.parse(link)
if uri.query
"#{uri.path}?#{uri.query}"
else
uri.path
end
end
end |
Beta Was this translation helpful? Give feedback.
-
|
The more I think about it, capybara-email might be a better option. Here's how I did it in Staples |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When writing integration and/or system tests, I want to be able to easily test mailer links so that my developer experience is improved.
Acceptance Criteria
Beta Was this translation helpful? Give feedback.
All reactions