Permalink
Browse files

added the cache delivery module

  • Loading branch information...
1 parent 9dfa83c commit ed2097886a8d25f2ef736225bcfaaf06ba11bbcd @liangzan committed Aug 20, 2009
Showing with 24 additions and 4 deletions.
  1. +24 −4 lib/email_spec/deliveries.rb
@@ -1,22 +1,40 @@
module EmailSpec
- module TestDeliveries
+ module CacheDeliveries
def all_emails
- ActionMailer::Base.deliveries
+ ActionMailer::Base.cached_deliveries
end
def last_email_sent
ActionMailer::Base.cached_deliveries.last || raise("No email has been sent!")
end
def reset_mailer
- ActionMailer::Base.cached_deliveries.clear
+ ActionMailer::Base.clear_cache
end
def mailbox_for(address)
ActionMailer::Base.cached_deliveries.select { |m| m.to.include?(address) || (m.bcc && m.bcc.include?(address)) || (m.cc && m.cc.include?(address)) }
end
end
+ module TestDeliveries
+ def all_emails
+ ActionMailer::Base.deliveries
+ end
+
+ def last_email_sent
+ ActionMailer::Base.deliveries.last || raise("No email has been sent!")
+ end
+
+ def reset_mailer
+ ActionMailer::Base.deliveries.clear
+ end
+
+ def mailbox_for(address)
+ ActionMailer::Base.deliveries.select { |m| m.to.include?(address) || (m.bcc && m.bcc.include?(address)) || (m.cc && m.cc.include?(address)) }
+ end
+ end
+
module ARMailerDeliveries
def all_emails
Email.all.map{ |email| parse_to_tmail(email) }
@@ -46,8 +64,10 @@ def parse_to_tmail(email)
module Deliveries
if ActionMailer::Base.delivery_method == :activerecord
include EmailSpec::ARMailerDeliveries
- else
+ elsif ActionMailer::Base.delivery_method == :test
include EmailSpec::TestDeliveries
+ elsif ActionMailer::Base.delivery_method == :cache
+ include EmailSpec::CacheDeliveries
end
end
end

1 comment on commit ed20978

bmabey commented on ed20978 Aug 20, 2009

I've been meaning to do this, thanks! Does this change work for you?

Please sign in to comment.