Module: EmailSpec::ARMailerDeliveries

Defined in:
lib/email_spec/deliveries.rb

Instance Method Summary collapse

Instance Method Details

#all_emailsObject



38
39
40
# File 'lib/email_spec/deliveries.rb', line 38

def all_emails
  Email.all.map{ |email| parse_to_mail(email) }
end

#last_email_sentObject



42
43
44
45
46
47
48
# File 'lib/email_spec/deliveries.rb', line 42

def last_email_sent
  if email = Email.last
    Mail.read(email.mail)
  else
    raise("No email has been sent!")
  end
end

#mailbox_for(address) ⇒ Object



54
55
56
57
58
59
# File 'lib/email_spec/deliveries.rb', line 54

def mailbox_for(address)
  Email.all.select { |email|
    (email.to && email.to.include?(address)) ||
    (email.bcc && email.bcc.include?(address)) ||
    (email.cc && email.cc.include?(address)) }.map{ |email| parse_to_mail(email) }
end

#parse_to_mail(email) ⇒ Object



61
62
63
# File 'lib/email_spec/deliveries.rb', line 61

def parse_to_mail(email)
  Mail.read(email.mail)
end

#reset_mailerObject



50
51
52
# File 'lib/email_spec/deliveries.rb', line 50

def reset_mailer
  Email.delete_all
end