Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit e1f3a7f40beca62a8bab485f578f3e2e698d79e8 1 parent fd80c9b
Dave Hoover authored May 07, 2010
10  lib/mad_mimi_mailable.rb
@@ -40,7 +40,7 @@ def unconfirmed(value = nil)
40 40
   end
41 41
 
42 42
   module ClassMethods
43  
-    attr_accessor :method_prefix
  43
+    attr_accessor :method_prefix, :use_erb
44 44
     
45 45
     def method_missing(method_symbol, *parameters)
46 46
       if method_prefix && method_symbol.id2name.match(/^deliver_(#{method_prefix}_[_a-z]\w*)/)
@@ -56,7 +56,7 @@ def deliver_mimi_mail(method, *parameters)
56 56
       mail = new
57 57
       mail.__send__(method, *parameters)
58 58
 
59  
-      if mail.use_erb
  59
+      if use_erb?(mail)
60 60
         mail.create!(method, *parameters)
61 61
       end
62 62
 
@@ -90,7 +90,7 @@ def call_api!(mail, method)
90 90
 
91 91
       params['unconfirmed'] = '1' if mail.unconfirmed
92 92
 
93  
-      if mail.use_erb
  93
+      if use_erb?(mail)
94 94
         if mail.parts.any?
95 95
           params['raw_plain_text'] = content_for(mail, "text/plain")
96 96
           params['raw_html'] = content_for(mail, "text/html") { |html| validate(html.body) }
@@ -154,6 +154,10 @@ def serialize(recipients)
154 154
         raise "Please provide a String or an Array for recipients or bcc."
155 155
       end
156 156
     end
  157
+    
  158
+    def use_erb?(mail)
  159
+      mail.use_erb || use_erb
  160
+    end
157 161
   end
158 162
 
159 163
 end
2  lib/mad_mimi_mailer.rb
@@ -5,7 +5,7 @@
5 5
 require "mad_mimi_mailable"
6 6
 
7 7
 class MadMimiMailer < ActionMailer::Base
8  
-  VERSION = '0.1.1'
  8
+  VERSION = '0.1.2'
9 9
 
10 10
   @@api_settings = {}
11 11
   cattr_accessor :api_settings
2  mad_mimi_mailer.gemspec
@@ -2,7 +2,7 @@
2 2
  
3 3
 Gem::Specification.new do |s|
4 4
   s.name = %q{mad_mimi_mailer}
5  
-  s.version = "0.1.1"
  5
+  s.version = "0.1.2"
6 6
  
7 7
   s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8 8
   s.authors = ["Dave Hoover"]
12  test/mad_mimi_mailable_test.rb
@@ -13,9 +13,10 @@ def hola(greeting)
13 13
   end
14 14
 end
15 15
 
16  
-class ChocolateMailer < ActionMailer::Base
  16
+class ChocolateErbMailer < ActionMailer::Base
17 17
   include MadMimiMailable
18 18
   self.method_prefix = "sugary"
  19
+  self.use_erb = true
19 20
 
20 21
   self.template_root = File.dirname(__FILE__) + '/templates/'
21 22
   
@@ -53,7 +54,7 @@ def test_typical_request
53 54
     VanillaMailer.deliver_hola("welcome to mad mimi")
54 55
   end
55 56
 
56  
-  def test_request_with_custom_method_prefix
  57
+  def test_erb_request_with_custom_method_prefix
57 58
     mock_request = mock("request")
58 59
     mock_request.expects(:set_form_data).with(
59 60
       'username' => "testy@mctestin.com",
@@ -63,12 +64,13 @@ def test_request_with_custom_method_prefix
63 64
       'subject' =>        "welcome to mad mimi",
64 65
       'bcc' =>            nil,
65 66
       'from' =>           "dave@obtiva.com",
66  
-      'body' =>           "--- \nmessage: welcome to mad mimi\n",
  67
+      'raw_html' =>       "hi there, welcome to mad mimi [[peek_image]]",
  68
+      'raw_plain_text' =>     nil,
67 69
       'hidden' =>         nil
68 70
     )
69  
-    ChocolateMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)
  71
+    ChocolateErbMailer.expects(:post_request).yields(mock_request).returns(@ok_reponse)
70 72
 
71  
-    ChocolateMailer.deliver_sugary_hola("welcome to mad mimi")
  73
+    ChocolateErbMailer.deliver_sugary_hola("welcome to mad mimi")
72 74
   end
73 75
 
74 76
 end
1  test/templates/chocolate_erb_mailer/sugary_hola.text.html.erb
... ...
@@ -0,0 +1 @@
  1
+hi there, welcome to mad mimi [[peek_image]]

0 notes on commit e1f3a7f

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