mandrill_mailer 1.1.0 → 1.2.0

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: 79a6370588ee165bd28e0b2610236fb3bf533417
4
- data.tar.gz: 52579261a95fc18eb4625cb41f9bb9c10fc09ad5
3
+ metadata.gz: a1044b6baf3d9a8f33f1cc09f86516c21d5228c4
4
+ data.tar.gz: ae3a798dacfe9294991ee3beb3755665558c26ea
5
5
  SHA512:
6
- metadata.gz: fd9651725cad09ddd52c4c796a14443ac7e91165b8da44be8e965f087989f74966310bd6d3cc72fcabc1bf90d817ed7d306030679804b1061880db80b6808e9f
7
- data.tar.gz: c281185967f50d1036ba767875e2321afe0ac79e33e42ee4ddd097b9a19075a9d2a892ba62086769696daf36412c7f4dcbe3c5efd9d48eedb490e7b834b4b83c
6
+ metadata.gz: 532a82b1c66cb927f5e36734c9fe7ec39ac040d4e976c15f3b76829745f36dee8255d48636b71b75c12b0d7497703a04a2cb74db4c29efb2f10e76221b88d24d
7
+ data.tar.gz: bb9e61792cffe0179339659bfdde72f87237bafe5097a4193646ffc018a309017b331ba39196b3d7938dae52bdb872d47b75e1212d0bf8f4b140619b00dbe361
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## 1.2.0 - 2015-12-22
6
+ ### Added
7
+ - Support for for deliver_later and deliver_now using ActiveJob. via @BenRuns
8
+
9
+
5
10
  ## 1.1.0 - 2015-10-02
6
11
  ### Added
7
12
  - Optional RSpec helper (`MandrillMailer::RSpecHelper`) with custom matchers
data/README.md CHANGED
@@ -39,6 +39,7 @@ ActionMailer::Base.delivery_method = :smtp
39
39
 
40
40
  MandrillMailer.configure do |config|
41
41
  config.api_key = ENV['MANDRILL_API_KEY']
42
+ config.config.deliver_later_queue_name = :default
42
43
  end
43
44
  ```
44
45
 
@@ -97,10 +98,10 @@ end
97
98
  ```
98
99
 
99
100
  * `#default:`
100
- * `:from` - set the default from email address for the mailer
101
+ * `:from` - set the default from email address for the mailer. Defaults to `'example@email.com'`.
101
102
  * `:from_name` - set the default from name for the mailer. If not set, defaults to from email address. Setting :from_name in the .mandrill_mail overrides the default.
102
103
  * `:merge_vars` - set some default `merge_vars` that will be sent with every mailer method (in `global_merge_vars` so there's no risk of collision with method-specific `merge_vars`.
103
- * `:view_content_link` - set a default to be able to access individual mailer messages in the Mandrill dashboard
104
+ * `:view_content_link` - set a default to be able to access individual mailer messages in the Mandrill dashboard. Defaults to `false`.
104
105
 
105
106
  * `.mandrill_mail`
106
107
  * `:template`(required) - Template slug from within Mandrill (for backwards-compatibility, the template name may also be used but the immutable slug is preferred)
@@ -216,7 +217,9 @@ end
216
217
 
217
218
  You can send the email by using the familiar syntax:
218
219
 
219
- `InvitationMailer.invite(invitation).deliver`
220
+ `InvitationMailer.invite(invitation).deliver_now`
221
+ `InvitationMailer.invite(invitation).deliver_later(wait: 1.hour)`
222
+ For deliver_later, Active Job will need to be configured
220
223
 
221
224
  ## Creating a test method
222
225
  When switching over to Mandrill for transactional emails we found that it was hard to setup a mailer in the console to send test emails easily (those darn designers), but really, you don't want to have to setup test objects everytime you want to send a test email. You can set up a testing 'mock' once and then call the `.test` method to send the test email.
@@ -1,4 +1,5 @@
1
1
  require 'action_view'
2
+ require 'active_job'
2
3
  require 'mandrill_mailer/railtie'
3
4
  require 'mandrill_mailer/mock'
4
5
  require 'mandrill_mailer/template_mailer'
@@ -216,7 +216,14 @@ module MandrillMailer
216
216
  def deliver
217
217
  raise NotImplementedError.new("#{self.class.name}#deliver is not implemented.")
218
218
  end
219
-
219
+
220
+ def deliver_now
221
+ raise NotImplementedError.new("#{self.class.name}#deliver_now is not implemented.")
222
+ end
223
+
224
+ def deliver_later
225
+ raise NotImplementedError.new("#{self.class.name}#deliver_later is not implemented.")
226
+ end
220
227
 
221
228
  def mandrill_mail_handler(args)
222
229
  args
@@ -0,0 +1,15 @@
1
+ require 'mandrill_mailer/message_mailer'
2
+ module MandrillMailer
3
+ class MandrillMessageJob < ActiveJob::Base
4
+ queue_as { MandrillMailer.config.deliver_later_queue_name }
5
+
6
+ def perform(message, async, ip_pool, send_at)
7
+ mailer = MandrillMailer::MessageMailer.new
8
+ mailer.message = message
9
+ mailer.async = async
10
+ mailer.ip_pool = ip_pool
11
+ mailer.send_at = send_at
12
+ mailer.deliver_now
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'mandrill_mailer/template_mailer'
2
+ module MandrillMailer
3
+ class MandrillTemplateJob < ActiveJob::Base
4
+ queue_as { MandrillMailer.config.deliver_later_queue_name }
5
+
6
+ def perform(template_name, template_content, message, async, ip_pool, send_at)
7
+ mailer = MandrillMailer::TemplateMailer.new
8
+ mailer.template_name = template_name
9
+ mailer.template_content = template_content
10
+ mailer.message = message
11
+ mailer.async = async
12
+ mailer.ip_pool = ip_pool
13
+ mailer.send_at = send_at
14
+ mailer.deliver_now
15
+ end
16
+ end
17
+ end
@@ -92,12 +92,20 @@
92
92
 
93
93
  # :important - whether or not this message is important, and should be delivered ahead of non-important messages
94
94
  require 'mandrill_mailer/core_mailer'
95
-
95
+ require 'mandrill_mailer/mandrill_message_later'
96
96
  module MandrillMailer
97
97
  class MessageMailer < MandrillMailer::CoreMailer
98
98
  # Public: Triggers the stored Mandrill params to be sent to the Mandrill api
99
99
  def deliver
100
+ deliver_now
101
+ end
102
+
103
+ def deliver_now
100
104
  mandrill_api.messages.send(message, async, ip_pool, send_at)
101
- end
105
+ end
106
+
107
+ def deliver_later(options={})
108
+ MandrillMailer::MandrillMessageJob.set(options).perform_later(message, async, ip_pool, send_at)
109
+ end
102
110
  end
103
111
  end
@@ -27,6 +27,22 @@ module MandrillMailer
27
27
 
28
28
  class TemplateMailer
29
29
  def deliver
30
+ deliver_now
31
+ end
32
+
33
+ def deliver_now
34
+ MandrillMailer::Mock.new({
35
+ :template_name => template_name,
36
+ :template_content => template_content,
37
+ :message => message,
38
+ :async => async,
39
+ :ip_pool => ip_pool,
40
+ :send_at => send_at
41
+ }).tap do |mock|
42
+ MandrillMailer.deliveries << mock
43
+ end
44
+ end
45
+ def deliver_later
30
46
  MandrillMailer::Mock.new({
31
47
  :template_name => template_name,
32
48
  :template_content => template_content,
@@ -42,6 +58,19 @@ module MandrillMailer
42
58
 
43
59
  class MessageMailer
44
60
  def deliver
61
+ deliver_now
62
+ end
63
+ def deliver_now
64
+ MandrillMailer::Mock.new({
65
+ :message => message,
66
+ :async => async,
67
+ :ip_pool => ip_pool,
68
+ :send_at => send_at
69
+ }).tap do |mock|
70
+ MandrillMailer.deliveries << mock
71
+ end
72
+ end
73
+ def deliver_later
45
74
  MandrillMailer::Mock.new({
46
75
  :message => message,
47
76
  :async => async,
@@ -106,6 +106,7 @@
106
106
  # :important - whether or not this message is important, and should be delivered ahead of non-important messages
107
107
  require 'mandrill_mailer/core_mailer'
108
108
  require 'mandrill_mailer/arg_formatter'
109
+ require 'mandrill_mailer/mandrill_template_later'
109
110
 
110
111
  module MandrillMailer
111
112
  class TemplateMailer < MandrillMailer::CoreMailer
@@ -118,9 +119,17 @@ module MandrillMailer
118
119
 
119
120
  # Public: Triggers the stored Mandrill params to be sent to the Mandrill api
120
121
  def deliver
122
+ deliver_now
123
+ end
124
+
125
+ def deliver_now
121
126
  mandrill_api.messages.send_template(template_name, template_content, message, async, ip_pool, send_at)
122
127
  end
123
128
 
129
+ def deliver_later(options={})
130
+ MandrillMailer::MandrillTemplateJob.set(options).perform_later(template_name, template_content, message, async, ip_pool, send_at)
131
+ end
132
+
124
133
  # Handle template mailer specifics before formating the given args
125
134
  def mandrill_mail_handler(args)
126
135
  # Mandrill requires template content to be there, set default value
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency 'activesupport'
22
22
  s.add_dependency 'actionpack'
23
+ s.add_dependency 'activejob'
23
24
  s.add_runtime_dependency 'mandrill-api', '~> 1.0.9'
24
25
 
25
26
  s.add_development_dependency 'pry'
@@ -8,20 +8,42 @@ describe MandrillMailer::MessageMailer do
8
8
  MandrillMailer.config.api_key = api_key
9
9
  end
10
10
 
11
- describe "#deliver" do
11
+ describe "#deliver_now" do
12
12
  let(:async) { double(:async) }
13
13
  let(:ip_pool) { double(:ip_pool) }
14
14
  let(:send_at) { double(:send_at) }
15
15
  let(:message) { double(:message) }
16
16
 
17
- it "calls the messages api with #send" do
17
+ before do
18
18
  mailer.async = async
19
19
  mailer.ip_pool = ip_pool
20
20
  mailer.send_at = send_at
21
21
  mailer.message = message
22
+ end
22
23
 
24
+ it "calls the messages api with #send" do
25
+ expect_any_instance_of(Mandrill::Messages).to receive(:send).with(message, async, ip_pool, send_at)
26
+ mailer.deliver_now
27
+ end
28
+ it "has an alias deliver" do
23
29
  expect_any_instance_of(Mandrill::Messages).to receive(:send).with(message, async, ip_pool, send_at)
24
30
  mailer.deliver
25
31
  end
26
32
  end
33
+ describe "#deliver_later" do
34
+ let(:async) { 'async' }
35
+ let(:ip_pool) { 'ip_pool' }
36
+ let(:send_at) { 'send_at'}
37
+ let(:message) { 'this is a message'}
38
+
39
+ it "calls the messages api with #send" do
40
+ mailer.async = async
41
+ mailer.ip_pool = ip_pool
42
+ mailer.send_at = send_at
43
+ mailer.message = message
44
+
45
+ expect_any_instance_of(Mandrill::Messages).to receive(:send).with(message, async, ip_pool, send_at)
46
+ mailer.deliver_later
47
+ end
48
+ end
27
49
  end
@@ -30,7 +30,7 @@ describe MandrillMailer::TemplateMailer do
30
30
  end
31
31
  end
32
32
 
33
- describe "#deliver" do
33
+ describe "#deliver_now" do
34
34
  let(:async) { double(:async) }
35
35
  let(:ip_pool) { double(:ip_pool) }
36
36
  let(:send_at) { double(:send_at) }
@@ -38,16 +38,43 @@ describe MandrillMailer::TemplateMailer do
38
38
  let(:template_name) { double(:template_name) }
39
39
  let(:template_content) { double(:template_content) }
40
40
 
41
- it "calls the messages api with #send_template" do
41
+ before do
42
42
  mailer.async = async
43
43
  mailer.ip_pool = ip_pool
44
44
  mailer.send_at = send_at
45
45
  mailer.message = message
46
46
  mailer.template_content = template_content
47
47
  mailer.template_name = template_name
48
+ end
48
49
 
50
+ it "calls the messages api with #send_template" do
51
+ expect_any_instance_of(Mandrill::Messages).to receive(:send_template).with(template_name, template_content, message, async, ip_pool, send_at)
52
+ mailer.deliver_now
53
+ end
54
+
55
+ it "has an alias deliver" do
49
56
  expect_any_instance_of(Mandrill::Messages).to receive(:send_template).with(template_name, template_content, message, async, ip_pool, send_at)
50
57
  mailer.deliver
51
58
  end
52
59
  end
60
+ describe "#deliver_later" do
61
+ let(:async) { false }
62
+ let(:ip_pool) { 1 }
63
+ let(:send_at) { '100'}
64
+ let(:message) { 'message' }
65
+ let(:template_name) { 'fake_template' }
66
+ let(:template_content) { 'content' }
67
+
68
+ it "calls the messages api with #send_template" do
69
+ mailer.async = async
70
+ mailer.ip_pool = ip_pool
71
+ mailer.send_at = send_at
72
+ mailer.message = message
73
+ mailer.template_content = template_content
74
+ mailer.template_name = template_name
75
+
76
+ expect_any_instance_of(Mandrill::Messages).to receive(:send_template).with(template_name, template_content, message, async, ip_pool, send_at)
77
+ mailer.deliver_later
78
+ end
79
+ end
53
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Rensel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activejob
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: mandrill-api
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +110,8 @@ files:
96
110
  - lib/mandrill_mailer.rb
97
111
  - lib/mandrill_mailer/arg_formatter.rb
98
112
  - lib/mandrill_mailer/core_mailer.rb
113
+ - lib/mandrill_mailer/mandrill_message_later.rb
114
+ - lib/mandrill_mailer/mandrill_template_later.rb
99
115
  - lib/mandrill_mailer/message_mailer.rb
100
116
  - lib/mandrill_mailer/mock.rb
101
117
  - lib/mandrill_mailer/offline.rb
@@ -137,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
153
  version: '0'
138
154
  requirements: []
139
155
  rubyforge_project:
140
- rubygems_version: 2.4.6
156
+ rubygems_version: 2.4.5.1
141
157
  signing_key:
142
158
  specification_version: 4
143
159
  summary: Transactional Mailer for Mandrill