Permalink
Browse files

Allowing people to choose to use_erb at the class-level.

  • Loading branch information...
1 parent fd80c9b commit e1f3a7f40beca62a8bab485f578f3e2e698d79e8 @redsquirrel committed May 7, 2010
@@ -40,7 +40,7 @@ def unconfirmed(value = nil)
end
module ClassMethods
- attr_accessor :method_prefix
+ attr_accessor :method_prefix, :use_erb
def method_missing(method_symbol, *parameters)
if method_prefix && method_symbol.id2name.match(/^deliver_(#{method_prefix}_[_a-z]\w*)/)
@@ -56,7 +56,7 @@ def deliver_mimi_mail(method, *parameters)
mail = new
mail.__send__(method, *parameters)
- if mail.use_erb
+ if use_erb?(mail)
mail.create!(method, *parameters)
end
@@ -90,7 +90,7 @@ def call_api!(mail, method)
params['unconfirmed'] = '1' if mail.unconfirmed
- if mail.use_erb
+ if use_erb?(mail)
if mail.parts.any?
params['raw_plain_text'] = content_for(mail, "text/plain")
params['raw_html'] = content_for(mail, "text/html") { |html| validate(html.body) }
@@ -154,6 +154,10 @@ def serialize(recipients)
raise "Please provide a String or an Array for recipients or bcc."
end
end
+
+ def use_erb?(mail)
+ mail.use_erb || use_erb
+ end
end
end
@@ -5,7 +5,7 @@
require "mad_mimi_mailable"
class MadMimiMailer < ActionMailer::Base
- VERSION = '0.1.1'
+ VERSION = '0.1.2'
@@api_settings = {}
cattr_accessor :api_settings
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{mad_mimi_mailer}
- s.version = "0.1.1"
+ s.version = "0.1.2"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Dave Hoover"]
@@ -13,9 +13,10 @@ def hola(greeting)
end
end
-class ChocolateMailer < ActionMailer::Base
+class ChocolateErbMailer < ActionMailer::Base
include MadMimiMailable
self.method_prefix = "sugary"
+ self.use_erb = true
self.template_root = File.dirname(__FILE__) + '/templates/'
@@ -53,7 +54,7 @@ def test_typical_request
VanillaMailer.deliver_hola("welcome to mad mimi")
end
- def test_request_with_custom_method_prefix
+ def test_erb_request_with_custom_method_prefix
mock_request = mock("request")
mock_request.expects(:set_form_data).with(
'username' => "testy@mctestin.com",
@@ -63,12 +64,13 @@ def test_request_with_custom_method_prefix
'subject' => "welcome to mad mimi",
'bcc' => nil,
'from' => "dave@obtiva.com",
- 'body' => "--- \nmessage: welcome to mad mimi\n",
+ 'raw_html' => "hi there, welcome to mad mimi [[peek_image]]",
+ 'raw_plain_text' => nil,
'hidden' => nil
)
- ChocolateMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)
+ ChocolateErbMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)
- ChocolateMailer.deliver_sugary_hola("welcome to mad mimi")
+ ChocolateErbMailer.deliver_sugary_hola("welcome to mad mimi")
end
end
@@ -0,0 +1 @@
+hi there, welcome to mad mimi [[peek_image]]

0 comments on commit e1f3a7f

Please sign in to comment.