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

Instance Method Details

#clear_emailsObject



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

#emailsObject



13
14
15
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 13

def emails
  ActionMailer::Base.deliveries
end

#last_emailObject



21
22
23
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 21

def last_email
  emails.last
end

#last_email_bodyObject



25
26
27
# File 'lib/decidim/dev/test/rspec_support/action_mailer.rb', line 25

def last_email_body
  email_body(last_email)
end


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


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