Permalink
Browse files

Move cached_deliveries method

The new API is RedisCacheMailerDelivery::Deliveries.all so that we don't
have to open ActionMailer::Base
  • Loading branch information...
ywen2 committed Mar 21, 2012
1 parent 5709e76 commit 1050a55032e5d19c1f1349262413a0d005278ac3
View
2 .rvmrc
@@ -1 +1 @@
-rvm 1.9.3@redis_cache_mailer_delivery
+rvm ree@redis_cache_mailer_delivery
@@ -1,7 +1,7 @@
require 'action_mailer'
require 'redis_cache_mailer_delivery/version'
require 'redis_cache_mailer_delivery/mail/cache_delivery'
-require 'redis_cache_mailer_delivery/action_mailer/base'
+require 'redis_cache_mailer_delivery/deliveries'
module RedisCacheMailerDelivery
class << self
@@ -1,26 +0,0 @@
-module ActionMailer
- class Base
- class << self
-
- #
- # Returns an array of delivered mails.
- #
- # @return [Array] array of mails (each mail is an instance of Mail.)
- #
- def cached_deliveries
- list = Redis::List.new redis_cache_settings[:redis_key_name], :marshal => true
- list.values.map{|m|Marshal.load(m)}
- end
-
- #
- # Clears delivered mails.
- #
- # It also cleans ActionMailer::Base.deliveries
- #
- def clear_cache
- $redis.del redis_cache_settings[:redis_key_name]
- end
-
- end # << self
- end # Base
-end # ActionMailer
@@ -0,0 +1,19 @@
+require 'redis'
+require 'redis/objects'
+require 'redis/list'
+module RedisCacheMailerDelivery
+ module Deliveries
+ class << self
+
+ #
+ # Returns an array of delivered mails.
+ #
+ # @return [Array] array of mails (each mail is an instance of Mail.)
+ #
+ def all
+ list = Redis::List.new ActionMailer::Base.redis_cache_settings[:redis_key_name], :marshal => true
+ list.values
+ end
+ end
+ end
+end
@@ -0,0 +1,30 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+
+module RedisCacheMailerDelivery
+ describe Deliveries do
+ before(:each) do
+ RedisCacheMailerDelivery.install
+ Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
+ end
+
+ describe ".all" do
+ let(:object) { Mail::Message.new}
+ before(:each) do
+ list = Redis::List.new "redis_cache_mailer_delivery:mail_messages", :marshal => true
+ list << object
+ end
+
+ after(:each) do
+ Redis.current.del "redis_cache_mailer_delivery:mail_messages"
+ end
+
+ it "fetches all contents from redis" do
+ described_class.all.size.should eq(1)
+ end
+
+ it "deserizlize the data" do
+ described_class.all[0].should eq(object)
+ end
+ end
+ end
+end

0 comments on commit 1050a55

Please sign in to comment.