Module: MailerHelpers
- Defined in:
- lib/decidim/dev/test/rspec_support/action_mailer.rb
Overview
A set of helpers meant to make your life easier when testing emails, especially given the fact that ActionMailer’s API can be a bit inconsistent.
Instance Method Summary collapse
- #clear_emails ⇒ Object
- #email_body(email) ⇒ Object
- #emails ⇒ Object
- #last_email ⇒ Object
- #last_email_body ⇒ Object
- #last_email_first_link ⇒ Object
- #last_email_link ⇒ Object
Instance Method Details
#clear_emails ⇒ Object
17 18 19 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 17 def clear_emails ActionMailer::Base.deliveries.clear end |
#email_body(email) ⇒ Object
29 30 31 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 29 def email_body(email) (email.try(:html_part).try(:body) || email.try(:body))&.encoded end |
#emails ⇒ Object
13 14 15 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 13 def emails ActionMailer::Base.deliveries end |
#last_email ⇒ Object
21 22 23 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 21 def last_email emails.last end |
#last_email_body ⇒ Object
25 26 27 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 25 def last_email_body email_body(last_email) end |
#last_email_first_link ⇒ Object
37 38 39 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 37 def last_email_first_link Nokogiri::HTML(last_email_body).css("table.content a").first["href"] end |
#last_email_link ⇒ Object
33 34 35 |
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 33 def last_email_link Nokogiri::HTML(last_email_body).css("table.content a").last["href"] end |