Skip to content
Browse files

Fix a bug

One have to set the whole settings in the client or CacheDelivery will
not work properly since some settings could be missing
  • Loading branch information...
1 parent b9f09ec commit c4fba3668fd9734f20615d5d6c9ec891df3a721c @ywen2 ywen2 committed Mar 26, 2012
View
5 lib/redis_cache_mailer_delivery.rb
@@ -1,5 +1,6 @@
require 'action_mailer'
require 'redis_cache_mailer_delivery/version'
+require 'redis_cache_mailer_delivery/settings'
require 'redis_cache_mailer_delivery/marshallable_converter_setting'
require 'redis_cache_mailer_delivery/cache_delivery'
require 'redis_cache_mailer_delivery/converters/sequel_marshallable_mail_message'
@@ -9,10 +10,8 @@ module RedisCacheMailerDelivery
class << self
def install
ActionMailer::Base.add_delivery_method :redis_cache, RedisCacheMailerDelivery::CacheDelivery,
- :redis_key_name => "redis_cache_mailer_delivery:mail_messages",
- :marshallable_converters => []
+ Settings.default_values
end
-
end # << self
end # RedisCacheMailerDelivery
require 'redis_cache_mailer_delivery/railtie'
View
10 lib/redis_cache_mailer_delivery/cache_delivery.rb
@@ -6,18 +6,18 @@ module RedisCacheMailerDelivery
#
class CacheDelivery
- # @attr [Hash] settings Settings for CacheDelivery
- attr_accessor :settings
+ attr_reader :settings
+ private :settings
# @api private
def initialize(settings)
- @settings = settings
+ @settings = Settings.new(settings)
end
# @api private
def deliver!(mail)
- list = Redis::List.new settings[:redis_key_name], :marshal => true
- settings[:marshallable_converters].each do |setting|
+ list = Redis::List.new settings.redis_key_name, :marshal => true
+ settings.marshallable_converters.each do |setting|
mail = MarshallableConverterSetting.new(setting).marshallable_class.marshallable(mail)
end
list << mail
View
15 lib/redis_cache_mailer_delivery/settings.rb
@@ -0,0 +1,15 @@
+module RedisCacheMailerDelivery
+ class Settings
+ class << self
+ def default_values
+ {:redis_key_name => "redis_cache_mailer_delivery:mail_messages",
+ :marshallable_converters => []}
+ end
+ end
+ def initialize(settings)
+ self.class.default_values.merge(settings).each do |key, value|
+ self.class.send(:define_method, key) {value}
+ end
+ end
+ end
+end
View
2 lib/redis_cache_mailer_delivery/version.rb
@@ -1,3 +1,3 @@
module RedisCacheMailerDelivery
- VERSION = "0.0.5"
+ VERSION = "0.0.6"
end
View
2 spec/redis_cache_mailer_delivery/cache_delivery_spec.rb
@@ -2,8 +2,8 @@
module RedisCacheMailerDelivery
describe CacheDelivery do
- subject {described_class.new :redis_key_name => "a-name", :marshallable_converters => []}
describe "#deliver!" do
+ subject {described_class.new :redis_key_name => "a-name", :marshallable_converters => []}
let(:object) {Mail::Message.new}
after(:each) do
View
37 spec/redis_cache_mailer_delivery/settings_spec.rb
@@ -0,0 +1,37 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+
+module RedisCacheMailerDelivery
+ describe Settings do
+ describe ".default_values" do
+ {:redis_key_name => "redis_cache_mailer_delivery:mail_messages",
+ :marshallable_converters => []}.each do |key, value|
+ it "includes #{key} and its default value to #{value}" do
+ described_class.default_values.should include(key => value)
+ end
+ end
+ end
+
+ describe ".new" do
+ context "when a value that is a key in default_values hash being passed in" do
+ subject {described_class.new :redis_key_name => "a-new-name"}
+ it "generates a method and return the value being passed in" do
+ subject.redis_key_name.should eq("a-new-name")
+ end
+ end
+ context "when a value that is not a key in default_values hash being passed in" do
+ subject {described_class.new :something_else => "a-new-name"}
+ it "generates a method and return the value being passed in" do
+ subject.something_else.should eq("a-new-name")
+ end
+ end
+ Settings.default_values.each do |key, value|
+ context "when #{key} is not passed in" do
+ subject {described_class.new({})}
+ it "generates a method #{key} and return the value defined in the default_values array" do
+ subject.send(key).should eq(value)
+ end
+ end
+ end
+ end
+ end
+end

0 comments on commit c4fba36

Please sign in to comment.
Something went wrong with that request. Please try again.