multi_mail 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a14ecc758499e8df176c767f62299f37df33cb18
4
- data.tar.gz: 32b938fec60cb8e6ae4b458bc5e88ccdcfd5237f
3
+ metadata.gz: 325f587b59afe15568ffa2098f5a17cb6cb9bc08
4
+ data.tar.gz: 3bfb48a0e0277863b7d86c2856af60d2db492647
5
5
  SHA512:
6
- metadata.gz: 00473360787d54704565c3c4be5c25af31e27254fc64495ea229e59d934a64f8a645bd43b0687a39ebba94f5b488a0aa76192aee6c6b24b5384a79c4d501fa10
7
- data.tar.gz: 7b43f573c40d70d6eab2f2a5f5fc2456f3b3cff2941701f2ec748ee1a8b509806a8828f230ae2dfaddc93da0f9e777487bad7da586084c685c0e3078d419ee6e
6
+ metadata.gz: 00e6624230f8adc6a1e86eaa400968a6ac5fc809bb19ba1480e3dfd94de45348dabc3a1018b9453a5d88393ea3a7d3d189299099f3b1284cea6b6e2138684c7c
7
+ data.tar.gz: 1241e28407f57bf8270424db4495df3109d081ebd1c32e6d529c197f31734d1ab5d9a3462b03de4c530df2959858bb1a7c6cae8ed79dfe527cc9f4294c52c4bf
data/README.md CHANGED
@@ -96,20 +96,20 @@ end
96
96
  First, add the delivery method to ActionMailer:
97
97
 
98
98
  ```
99
- ActionMailer::Base.add_delivery_method :postmark, MultiMail::Sender::Postmark, :api_key => 'your-api-key'
99
+ ActionMailer::Base.add_delivery_method :mandrill, MultiMail::Sender::Mandrill, :api_key => 'your-api-key'
100
100
  ```
101
101
 
102
102
  Set the default delivery method for all ActionMailer classes in `config/environments/<ENV>.rb`:
103
103
 
104
104
  ```
105
- config.action_mailer.delivery_method = :postmark
105
+ config.action_mailer.delivery_method = :mandrill
106
106
  ```
107
107
 
108
108
  Or, set the delivery method in an ActionMailer class:
109
109
 
110
110
  ```
111
111
  class UserMailer < ActionMailer::Base
112
- default :delivery_method => :postmark
112
+ default :delivery_method => :mandrill
113
113
  end
114
114
  ```
115
115
 
@@ -121,7 +121,7 @@ class UserMailer < ActionMailer::Base
121
121
  mail({
122
122
  :to => user.email,
123
123
  :subject => 'Welcome to My Awesome Site',
124
- :delivery_method => :postmark,
124
+ :delivery_method => :mandrill,
125
125
  })
126
126
  end
127
127
  end
@@ -130,7 +130,7 @@ end
130
130
  Set the delivery method's default options for all ActionMailer classes in `config/environments/<ENV>.rb`:
131
131
 
132
132
  ```
133
- config.action_mailer.postmark_settings = {:api_key => 'your-api-key'}
133
+ config.action_mailer.mandrill_settings = {:api_key => 'your-api-key', :template_name => 'default'}
134
134
  ```
135
135
 
136
136
  Or, set the delivery method's options in an ActionMailer method:
@@ -141,7 +141,7 @@ class UserMailer < ActionMailer::Base
141
141
  mail({
142
142
  :to => user.email,
143
143
  :subject => 'Welcome to My Awesome Site',
144
- :delivery_method_options => {:api_key => 'your-api-key'},
144
+ :delivery_method_options => {:template_name => 'default'},
145
145
  })
146
146
  end
147
147
  end
@@ -151,14 +151,14 @@ Or, set the delivery method's options in an ActionMailer action:
151
151
 
152
152
  ```
153
153
  class UserMailer < ActionMailer::Base
154
- after_action :set_delivery_method_options
154
+ before_action :set_delivery_method_options
155
155
 
156
156
  ...
157
157
 
158
158
  private
159
159
 
160
160
  def set_delivery_method_options
161
- mail.delivery_method.settings.merge!({:api_key => 'your-api-key'})
161
+ mail.delivery_method.template_name = 'default'
162
162
  end
163
163
  end
164
164
  ```
@@ -6,7 +6,9 @@ module MultiMail
6
6
 
7
7
  requires :api_key
8
8
 
9
- attr_reader :api_key, :async, :ip_pool, :send_at, :template_name, :template_content
9
+ attr_reader :api_key, :async, :ip_pool, :send_at
10
+
11
+ attr_accessor :template_name, :template_content
10
12
 
11
13
  # Initializes a Mandrill outgoing email sender.
12
14
  #
@@ -16,12 +18,12 @@ module MultiMail
16
18
  # mode optimized for bulk sending
17
19
  # @option options [String] :ip_pool the name of the dedicated IP pool that
18
20
  # should be used to send the message
21
+ # @option options [Time,String] :send_at when this message should be sent
19
22
  # @option options [String] :template_name the slug or name of a template
20
23
  # that exists in the user's Mandrill account
21
24
  # @option options [Array<Hash>] :template_content an array of hashes, each
22
25
  # with a `"name"` key for the editable region to inject into and a
23
26
  # `"content"` key for the content to inject
24
- # @option options [Time,String] :send_at when this message should be sent
25
27
  # @see https://mandrillapp.com/api/docs/index.ruby.html
26
28
  # @see https://mandrillapp.com/api/docs/messages.JSON.html#method-send
27
29
  def initialize(options = {})
@@ -67,9 +69,6 @@ module MultiMail
67
69
  # @see https://bitbucket.org/mailchimp/mandrill-api-ruby/src/d0950a6f9c4fac1dd2d5198a4f72c12c626ab149/lib/mandrill/api.rb?at=master#cl-738
68
70
  # @see https://bitbucket.org/mailchimp/mandrill-api-ruby/src/d0950a6f9c4fac1dd2d5198a4f72c12c626ab149/lib/mandrill.rb?at=master#cl-32
69
71
  def deliver!(mail)
70
- @template_name = settings.delete(:template_name)
71
- @template_content = settings.delete(:template_content)
72
-
73
72
  message = MultiMail::Message::Mandrill.new(mail).to_mandrill_hash.merge(parameters)
74
73
 
75
74
  api_params = {
@@ -1,3 +1,3 @@
1
1
  module MultiMail
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/multi_mail.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_runtime_dependency('rack', '~> 1.5')
21
21
 
22
22
  # For testing
23
+ s.add_development_dependency('actionmailer', '~> 4.2.1')
23
24
  s.add_development_dependency('coveralls')
24
25
  s.add_development_dependency('rake')
25
26
  s.add_development_dependency('rspec', '~> 2.10')
@@ -0,0 +1 @@
1
+ Anonymous mailer body
@@ -14,6 +14,75 @@ describe MultiMail::Sender::Mandrill do
14
14
  Mail.new
15
15
  end
16
16
 
17
+ let :mailer do
18
+ Class.new(ActionMailer::Base) do
19
+ def welcome
20
+ mail
21
+ end
22
+ end
23
+ end
24
+
25
+ let :mailer_with_delivery_method_set_by_class do
26
+ Class.new(ActionMailer::Base) do
27
+ default :delivery_method => :mandrill
28
+
29
+ def welcome
30
+ mail
31
+ end
32
+ end
33
+ end
34
+
35
+ let :mailer_with_delivery_method_set_by_method do
36
+ Class.new(ActionMailer::Base) do
37
+ def welcome
38
+ mail(:delivery_method => :mandrill)
39
+ end
40
+ end
41
+ end
42
+
43
+ let :mailer_with_delivery_method_options_set_by_method do
44
+ Class.new(ActionMailer::Base) do
45
+ def welcome
46
+ mail(:delivery_method_options => {:template_name => 'default'})
47
+ end
48
+ end
49
+ end
50
+
51
+ let :mailer_with_delivery_method_options_set_by_action do
52
+ Class.new(ActionMailer::Base) do
53
+ before_action :set_delivery_method_options
54
+
55
+ def welcome
56
+ mail
57
+ end
58
+
59
+ private
60
+
61
+ def set_delivery_method_options
62
+ mail.delivery_method.template_name = 'default'
63
+ end
64
+ end
65
+ end
66
+
67
+ shared_examples 'a sender' do
68
+ it 'should send a message' do
69
+ results = message.deliver!
70
+ results.size.should == 1
71
+
72
+ result = results.first
73
+ result.size.should == 4
74
+
75
+ result['reject_reason'].should == nil
76
+ result['status'].should == 'sent'
77
+ result['email'].should == 'bit-bucket@test.smtp.org'
78
+ result['_id'].should match(/\A[0-9a-f]{32}\z/)
79
+ end
80
+
81
+ it 'should not send an empty message' do
82
+ empty_message.deliver!.should == [] # response not saved
83
+ end
84
+ end
85
+
17
86
  describe '#initialize' do
18
87
  it 'should raise an error if :api_key is missing' do
19
88
  expect{
@@ -133,48 +202,107 @@ describe MultiMail::Sender::Mandrill do
133
202
 
134
203
  describe '#deliver!' do
135
204
  context 'when :template_name is set' do
136
- before do
205
+ before :all do
137
206
  Mail.defaults do
138
207
  delivery_method MultiMail::Sender::Mandrill, :api_key => ENV['MANDRILL_API_KEY'], :return_response => true, :template_name => 'default'
139
208
  end
140
209
  end
141
210
 
142
- it 'should send a mandrill template' do
143
- results = message.deliver!
144
- results.size.should == 1
145
-
146
- result = results.first
147
- result.size.should == 4
148
-
149
- result['reject_reason'].should == nil
150
- result['status'].should == 'sent'
151
- result['email'].should == 'bit-bucket@test.smtp.org'
152
- result['_id'].should match(/\A[0-9a-f]{32}\z/)
153
- end
211
+ it_behaves_like 'a sender'
154
212
  end
155
213
 
156
214
  context 'when :template_name is not set' do
157
- before do
215
+ before :all do
158
216
  Mail.defaults do
159
217
  delivery_method MultiMail::Sender::Mandrill, :api_key => ENV['MANDRILL_API_KEY'], :return_response => true
160
218
  end
161
219
  end
162
220
 
163
- it 'should send a message' do
164
- results = message.deliver!
165
- results.size.should == 1
221
+ it_behaves_like 'a sender'
222
+ end
223
+ end
166
224
 
167
- result = results.first
168
- result.size.should == 4
225
+ # @see https://github.com/rails/rails/blob/3e36db4406beea32772b1db1e9a16cc1e8aea14c/actionmailer/test/delivery_methods_test.rb
226
+ context 'with ActionMailer' do
227
+ before :all do
228
+ ActionMailer::Base.view_paths = File.expand_path('../../fixtures', __FILE__)
229
+ ActionMailer::Base.add_delivery_method :mandrill, MultiMail::Sender::Mandrill, :api_key => ENV['MANDRILL_API_KEY']
230
+ end
231
+
232
+ context 'when setting delivery method' do
233
+ context 'with delivery method set globally' do
234
+ it 'should send a message' do
235
+ ActionMailer::Base.delivery_method = :mandrill
169
236
 
170
- result['reject_reason'].should == nil
171
- result['status'].should == 'sent'
172
- result['email'].should == 'bit-bucket@test.smtp.org'
173
- result['_id'].should match(/\A[0-9a-f]{32}\z/)
237
+ email = mailer.welcome.deliver_now
238
+ email.delivery_method.should be_a(MultiMail::Sender::Mandrill)
239
+
240
+ ActionMailer::Base.delivery_method = :smtp
241
+ end
174
242
  end
175
243
 
176
- it 'should not send an empty message' do
177
- empty_message.deliver!.should == [] # response not saved
244
+ context 'with delivery method set by a class' do
245
+ it 'should send a message' do
246
+ Mail::SMTP.any_instance.stub(:deliver!)
247
+ email = mailer.welcome.deliver_now
248
+ email.delivery_method.should be_a(Mail::SMTP)
249
+
250
+ email = mailer_with_delivery_method_set_by_class.welcome.deliver_now
251
+ email.delivery_method.should be_a(MultiMail::Sender::Mandrill)
252
+ end
253
+ end
254
+
255
+ context 'with delivery method set by a method' do
256
+ it 'should send a message' do
257
+ Mail::SMTP.any_instance.stub(:deliver!)
258
+ email = mailer.welcome.deliver_now
259
+ email.delivery_method.should be_a(Mail::SMTP)
260
+
261
+ email = mailer_with_delivery_method_set_by_method.welcome.deliver_now
262
+ email.delivery_method.should be_a(MultiMail::Sender::Mandrill)
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'when setting delivery method options' do
268
+ before :all do
269
+ ActionMailer::Base.delivery_method = :mandrill
270
+ end
271
+
272
+ context 'with delivery method options set globally' do
273
+ it 'should send a message' do
274
+ old_settings = ActionMailer::Base.mandrill_settings
275
+
276
+ email = mailer.welcome.deliver_now
277
+ email.delivery_method.template_name.should == nil
278
+
279
+ ActionMailer::Base.mandrill_settings = old_settings.merge(:template_name => 'default')
280
+
281
+ email = mailer.welcome.deliver_now
282
+ email.delivery_method.template_name.should == 'default'
283
+
284
+ ActionMailer::Base.mandrill_settings = old_settings
285
+ end
286
+ end
287
+
288
+ context 'with delivery method options set by a method' do
289
+ it 'should send a message' do
290
+ email = mailer.welcome.deliver_now
291
+ email.delivery_method.template_name.should == nil
292
+
293
+ email = mailer_with_delivery_method_options_set_by_method.welcome.deliver_now
294
+ email.delivery_method.template_name.should == 'default'
295
+ end
296
+ end
297
+
298
+ context 'with delivery method options set by an action' do
299
+ it 'should send a message' do
300
+ email = mailer.welcome.deliver_now
301
+ email.delivery_method.template_name.should == nil
302
+
303
+ email = mailer_with_delivery_method_options_set_by_action.welcome.deliver_now
304
+ email.delivery_method.template_name.should == 'default'
305
+ end
178
306
  end
179
307
  end
180
308
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ require 'digest/sha1'
11
11
  require 'net/http'
12
12
  require 'yaml'
13
13
 
14
+ require 'action_mailer'
14
15
  require 'rspec'
15
16
  require 'rack'
16
17
  require File.dirname(__FILE__) + '/../lib/multi_mail'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James McKinney
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionmailer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: coveralls
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,7 @@ files:
178
192
  - lib/multi_mail/version.rb
179
193
  - multi_mail.gemspec
180
194
  - spec/cloudmailin/receiver_spec.rb
195
+ - spec/fixtures/anonymous/welcome.erb
181
196
  - spec/fixtures/cloudmailin/json/attachment_store.txt
182
197
  - spec/fixtures/cloudmailin/json/spam.txt
183
198
  - spec/fixtures/cloudmailin/json/valid.txt
@@ -257,6 +272,7 @@ specification_version: 4
257
272
  summary: Easily switch between email APIs
258
273
  test_files:
259
274
  - spec/cloudmailin/receiver_spec.rb
275
+ - spec/fixtures/anonymous/welcome.erb
260
276
  - spec/fixtures/cloudmailin/json/attachment_store.txt
261
277
  - spec/fixtures/cloudmailin/json/spam.txt
262
278
  - spec/fixtures/cloudmailin/json/valid.txt