mandrill_batch_mailer 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +82 -3
- data/lib/mandrill_batch_mailer.rb +26 -0
- data/lib/mandrill_batch_mailer/base_mailer.rb +64 -98
- data/lib/mandrill_batch_mailer/version.rb +1 -1
- data/spec/mandrill_batch_mailer/base_mailer_spec.rb +90 -50
- data/spec/spec_helper.rb +6 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6e6c5d426fdfc9462c81098e2c64f2146907a5
|
4
|
+
data.tar.gz: c2a7696bad891b2479cf370db9ee6753b25cc9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284043167940b1473b76f4eff2b6b2c813a5853c9b50c549914567e76d737134730a12d0caf52e1dadd7bdc6f6254033d3c2393b0acf6fb6b321200a54137d3e
|
7
|
+
data.tar.gz: 6768a56dfb2d615fef6014f892906ce25eb5325fa12fd8be06b7ffe2f04bf7a6bb1f1776f0dc2eb686f05ad9cc122cfe5926beca256fe8be9adf3927e3cc2a3b
|
data/README.md
CHANGED
@@ -6,10 +6,89 @@
|
|
6
6
|
|
7
7
|
Send batched Mails via Mandrill API.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Installation
|
10
10
|
|
11
11
|
gem install mandrill_batch_mailer
|
12
12
|
|
13
|
-
##
|
13
|
+
## Configuration
|
14
14
|
|
15
|
-
|
15
|
+
# config/mandrill_batch_mailer.rb
|
16
|
+
|
17
|
+
MandrillBatchMailer.configure do |config|
|
18
|
+
# enable sending mails via the Mandrill API, default is false
|
19
|
+
config.perform_deliveries = true
|
20
|
+
|
21
|
+
# Enables interception of mails. Default is false
|
22
|
+
config.intercept_recipients = true
|
23
|
+
|
24
|
+
# Set a mail address you want your mails redirected to. '+#{nr}' will be
|
25
|
+
# added for each recipient and the subject line includes the original mail
|
26
|
+
# address.
|
27
|
+
config.interception_base_mail = 'all-mails-to@some-domain.com'
|
28
|
+
|
29
|
+
# Set to your Mandrill API Key you get from Mandrill.
|
30
|
+
config.api_key = '3x4mpl3_k3y'
|
31
|
+
|
32
|
+
# Set your from e-mail address and name
|
33
|
+
config.from_email = 'mail@my-app.com'
|
34
|
+
config.from_name = 'My App'
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
## Example
|
39
|
+
|
40
|
+
# config/locales/en.yml
|
41
|
+
|
42
|
+
en:
|
43
|
+
mandrill:
|
44
|
+
shared_translations:
|
45
|
+
cheers: 'Cheers Your App-Team''
|
46
|
+
welcome_mailer:
|
47
|
+
welcome:
|
48
|
+
subject: 'Welcome to our App!'
|
49
|
+
welcome_to_app: 'welcome to our App.'
|
50
|
+
mass_mailer:
|
51
|
+
mass_mail:
|
52
|
+
subject: 'This is a mass mail'
|
53
|
+
be_awesome: 'let's be awesome!'
|
54
|
+
|
55
|
+
# app/mailers/mandrill/welcome_mailer.rb
|
56
|
+
|
57
|
+
class Mandrill::WelcomeMailer < MandrillBatchMailer::BaseMailer
|
58
|
+
def welcome(user_id)
|
59
|
+
@user = User.find user_id
|
60
|
+
mail to: welcome_merge_vars
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def welcome_merge_vars
|
66
|
+
{
|
67
|
+
@user.email => {
|
68
|
+
user_salutation: @user.salutation
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# app/mailers/mandrill/mass_mailer.rb
|
75
|
+
|
76
|
+
class Mandrill::MassMailer < MandrillBatchMailer::BaseMailer
|
77
|
+
|
78
|
+
def mass_mail(user_ids)
|
79
|
+
@users = User.find user_ids
|
80
|
+
mail to: mass_mail_merge_vars
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def mass_mail_merge_vars
|
86
|
+
@users.map do |user|
|
87
|
+
[user.email,
|
88
|
+
{
|
89
|
+
user_salutation: user.salutation
|
90
|
+
}
|
91
|
+
]
|
92
|
+
end.to_h
|
93
|
+
end
|
94
|
+
end
|
@@ -1,4 +1,30 @@
|
|
1
1
|
require 'mandrill_batch_mailer/base_mailer'
|
2
|
+
require 'active_support/configurable'
|
2
3
|
|
3
4
|
module MandrillBatchMailer
|
5
|
+
include ActiveSupport::Configurable
|
6
|
+
|
7
|
+
ENDPOINT = 'https://mandrillapp.com/api/1.0/messages/'\
|
8
|
+
'send-template.json'
|
9
|
+
|
10
|
+
config_accessor :perform_deliveries,
|
11
|
+
:intercept_recipients,
|
12
|
+
:interception_base_mail,
|
13
|
+
:from_email,
|
14
|
+
:from_name,
|
15
|
+
:api_key
|
16
|
+
|
17
|
+
self.perform_deliveries = false
|
18
|
+
self.intercept_recipients = false
|
19
|
+
self.interception_base_mail = ''
|
20
|
+
|
21
|
+
attr_writer :logger
|
22
|
+
|
23
|
+
def self.logger
|
24
|
+
@logger ||= rails_logger || Logger.new(STDOUT)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.rails_logger
|
28
|
+
defined?(Rails) && Rails.logger
|
29
|
+
end
|
4
30
|
end
|
@@ -3,21 +3,6 @@ require 'active_support/inflector'
|
|
3
3
|
require 'active_support/core_ext/object/try'
|
4
4
|
|
5
5
|
module MandrillBatchMailer
|
6
|
-
ENDPOINT = 'https://mandrillapp.com/api/1.0/messages/'\
|
7
|
-
'send-template.json'
|
8
|
-
|
9
|
-
def self.logger
|
10
|
-
@logger ||= rails_logger || Logger.new(STDOUT)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.logger=(logger)
|
14
|
-
@logger = logger
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.rails_logger
|
18
|
-
defined?(Rails) && Rails.logger
|
19
|
-
end
|
20
|
-
|
21
6
|
class BaseMailer
|
22
7
|
private
|
23
8
|
|
@@ -25,57 +10,41 @@ module MandrillBatchMailer
|
|
25
10
|
|
26
11
|
public
|
27
12
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
["#{template_name}"]
|
62
|
-
end
|
63
|
-
|
64
|
-
def api_key
|
65
|
-
self.class.api_key
|
66
|
-
end
|
67
|
-
|
68
|
-
class << self
|
69
|
-
# do it just as ActionMailer
|
70
|
-
def method_missing(method, *args)
|
71
|
-
mailer = new method
|
72
|
-
if mailer.respond_to? method
|
73
|
-
mailer.public_send(method, *args)
|
74
|
-
else
|
75
|
-
super method, *args
|
13
|
+
def initialize(method)
|
14
|
+
self.caller_method_name = method
|
15
|
+
end
|
16
|
+
|
17
|
+
def mail(to: nil)
|
18
|
+
@tos = tos_from(to)
|
19
|
+
send_template mandrill_parameters
|
20
|
+
end
|
21
|
+
|
22
|
+
# feel free to override
|
23
|
+
def from_email
|
24
|
+
MandrillBatchMailer.from_email
|
25
|
+
end
|
26
|
+
|
27
|
+
# feel free to override
|
28
|
+
def from_name
|
29
|
+
MandrillBatchMailer.from_name || ''
|
30
|
+
end
|
31
|
+
|
32
|
+
# feel free to override
|
33
|
+
def tags
|
34
|
+
["#{template_name}"]
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# do it just as ActionMailer
|
39
|
+
def method_missing(method, *args)
|
40
|
+
mailer = new method
|
41
|
+
if mailer.respond_to? method
|
42
|
+
mailer.public_send(method, *args)
|
43
|
+
else
|
44
|
+
super method, *args
|
45
|
+
end
|
76
46
|
end
|
77
47
|
end
|
78
|
-
end
|
79
48
|
|
80
49
|
protected
|
81
50
|
|
@@ -85,9 +54,10 @@ module MandrillBatchMailer
|
|
85
54
|
|
86
55
|
private
|
87
56
|
|
57
|
+
# rubocop:disable MethodLength
|
88
58
|
def mandrill_parameters
|
89
59
|
{
|
90
|
-
key: api_key,
|
60
|
+
key: MandrillBatchMailer.api_key,
|
91
61
|
template_name: template_name,
|
92
62
|
template_content: [],
|
93
63
|
message: {
|
@@ -113,10 +83,11 @@ module MandrillBatchMailer
|
|
113
83
|
async: true
|
114
84
|
}.deep_merge(_default)
|
115
85
|
end
|
86
|
+
# rubocop:enable MethodLength
|
116
87
|
|
117
88
|
def _default
|
118
89
|
given_defaults = (respond_to?(:default, true) && default) || {}
|
119
|
-
if MandrillBatchMailer
|
90
|
+
if MandrillBatchMailer.intercept_recipients
|
120
91
|
given_defaults[:message].try(:delete, :to)
|
121
92
|
end
|
122
93
|
given_defaults
|
@@ -127,22 +98,14 @@ module MandrillBatchMailer
|
|
127
98
|
.gsub '_', '-'
|
128
99
|
end
|
129
100
|
|
130
|
-
def tags
|
131
|
-
["#{template_name}_#{locale}"]
|
132
|
-
end
|
133
|
-
|
134
|
-
def locale
|
135
|
-
I18n.locale
|
136
|
-
end
|
137
|
-
|
138
101
|
def subject
|
139
102
|
'*|subject|*'
|
140
103
|
end
|
141
104
|
|
142
105
|
def to
|
143
|
-
if MandrillBatchMailer
|
106
|
+
if MandrillBatchMailer.intercept_recipients
|
144
107
|
@tos.keys.size.times.map do |i|
|
145
|
-
{ email: MandrillBatchMailer
|
108
|
+
{ email: MandrillBatchMailer
|
146
109
|
.interception_base_mail.sub('@', "+#{i}@") }
|
147
110
|
end
|
148
111
|
else
|
@@ -157,22 +120,20 @@ module MandrillBatchMailer
|
|
157
120
|
def merge_vars
|
158
121
|
@tos.each_with_index.map do |to, i|
|
159
122
|
to_email, vars = to.to_a
|
160
|
-
if MandrillBatchMailer
|
161
|
-
|
162
|
-
.sub('@', "+#{i}@"),
|
163
|
-
vars: intercepted_merge_vars(to_email, vars)
|
164
|
-
}
|
123
|
+
if MandrillBatchMailer.intercept_recipients
|
124
|
+
intercepted_merge_vars(to_email, vars, i)
|
165
125
|
else
|
166
|
-
{ rcpt: to_email,
|
167
|
-
vars: merge_vars_from(vars)
|
168
|
-
}
|
126
|
+
{ rcpt: to_email, vars: merge_vars_from(vars) }
|
169
127
|
end
|
170
128
|
end
|
171
129
|
end
|
172
130
|
|
173
|
-
def intercepted_merge_vars(to_email, vars)
|
174
|
-
|
175
|
-
|
131
|
+
def intercepted_merge_vars(to_email, vars, i)
|
132
|
+
subject = vars[:subject] || translations[:subject]
|
133
|
+
{
|
134
|
+
rcpt: MandrillBatchMailer.interception_base_mail.sub('@', "+#{i}@"),
|
135
|
+
vars: merge_vars_from(vars.merge(subject: "#{to_email} #{subject}"))
|
136
|
+
}
|
176
137
|
end
|
177
138
|
|
178
139
|
## HELPER METHODS ##
|
@@ -201,8 +162,9 @@ module MandrillBatchMailer
|
|
201
162
|
end
|
202
163
|
|
203
164
|
def shared_translations
|
204
|
-
I18n.t
|
205
|
-
|
165
|
+
I18n.t(
|
166
|
+
"#{class_name.deconstantize.underscore}.shared_translations",
|
167
|
+
default: {})
|
206
168
|
end
|
207
169
|
|
208
170
|
def merge_vars_from(translations)
|
@@ -212,20 +174,24 @@ module MandrillBatchMailer
|
|
212
174
|
end
|
213
175
|
|
214
176
|
def send_template(params)
|
215
|
-
if MandrillBatchMailer
|
177
|
+
if MandrillBatchMailer.perform_deliveries
|
216
178
|
RestClient.post MandrillBatchMailer::ENDPOINT, params.to_json
|
217
179
|
params
|
218
180
|
else
|
219
|
-
|
220
|
-
if defined? AwesomePrint
|
221
|
-
params.ai
|
222
|
-
else
|
223
|
-
params.inspect
|
224
|
-
end
|
225
|
-
MandrillBatchMailer.logger
|
226
|
-
.info "Sending Mandrill Mail: #{params_inspect}"
|
181
|
+
log_sending(params)
|
227
182
|
params
|
228
183
|
end
|
229
184
|
end
|
185
|
+
|
186
|
+
def log_sending(params)
|
187
|
+
params_inspect =
|
188
|
+
if defined? AwesomePrint
|
189
|
+
params.ai
|
190
|
+
else
|
191
|
+
params.inspect
|
192
|
+
end
|
193
|
+
MandrillBatchMailer.logger
|
194
|
+
.info "Sending Mandrill Mail: #{params_inspect}"
|
195
|
+
end
|
230
196
|
end
|
231
197
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe MandrillBatchMailer::BaseMailer
|
3
|
+
describe MandrillBatchMailer::BaseMailer do
|
4
4
|
let(:user_dup) do
|
5
|
-
|
5
|
+
lambda do
|
6
6
|
double locale: :de, email: Faker::Internet.email, first_name: Faker.name
|
7
7
|
end
|
8
8
|
end
|
@@ -15,42 +15,50 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
15
15
|
|
16
16
|
let(:translations) do
|
17
17
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
shared_translations: {
|
19
|
+
salutation: 'Hello'
|
20
|
+
},
|
21
|
+
test_mailer: {
|
22
|
+
testing: {
|
23
|
+
subject: 'A Test Subject',
|
24
|
+
just_a_test: 'This is just a test',
|
25
|
+
regards: 'Regards, your dev team'
|
21
26
|
},
|
22
|
-
|
23
|
-
|
24
|
-
subject: 'A Test Subject',
|
25
|
-
just_a_test: 'This is just a test',
|
26
|
-
regards: 'Regards, your dev team'
|
27
|
-
},
|
28
|
-
test_bulk: {
|
29
|
-
salutation: 'Hello %{name}'
|
30
|
-
}
|
27
|
+
test_bulk: {
|
28
|
+
salutation: 'Hello %{name}'
|
31
29
|
}
|
32
30
|
}
|
33
31
|
}
|
34
32
|
end
|
35
33
|
|
36
|
-
class
|
34
|
+
class TestMailer < MandrillBatchMailer::BaseMailer
|
37
35
|
def testing(user)
|
38
36
|
@user = user
|
39
37
|
mail to: user.email
|
40
38
|
end
|
41
39
|
|
42
40
|
def test_bulk(users)
|
43
|
-
@user = users.first
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
@user = users.first
|
42
|
+
mail to: to_params(users)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def to_params(users)
|
48
|
+
users.map do |user|
|
49
|
+
[
|
50
|
+
user.email,
|
51
|
+
{ salutation: I18n.t(
|
52
|
+
:salutation,
|
53
|
+
name: user.first_name,
|
54
|
+
scope: 'mandrill.test_mailer.test_bulk')
|
55
|
+
}
|
56
|
+
]
|
48
57
|
end.to_h
|
49
|
-
mail to: to_params
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
53
|
-
let(:test_mailer) {
|
61
|
+
let(:test_mailer) { TestMailer.new :testing }
|
54
62
|
let(:base_mailer) { MandrillBatchMailer::BaseMailer.new :testing }
|
55
63
|
|
56
64
|
before do
|
@@ -63,47 +71,44 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
63
71
|
|
64
72
|
shared_context 'when intercepting', :intercept do
|
65
73
|
before do
|
66
|
-
@old_intercept = MandrillBatchMailer
|
67
|
-
MandrillBatchMailer
|
68
|
-
@old_intercept_mail =
|
69
|
-
|
70
|
-
MandrillBatchMailer::BaseMailer.interception_base_mail =
|
71
|
-
'notifier@gapfish.com'
|
74
|
+
@old_intercept = MandrillBatchMailer.intercept_recipients
|
75
|
+
MandrillBatchMailer.intercept_recipients = true
|
76
|
+
@old_intercept_mail = MandrillBatchMailer.interception_base_mail
|
77
|
+
MandrillBatchMailer.interception_base_mail = 'notifier@some-domain.com'
|
72
78
|
end
|
73
79
|
after do
|
74
|
-
MandrillBatchMailer
|
75
|
-
MandrillBatchMailer
|
76
|
-
@old_intercept_mail
|
80
|
+
MandrillBatchMailer.intercept_recipients = @old_value
|
81
|
+
MandrillBatchMailer.interception_base_mail = @old_intercept_mail
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
80
85
|
shared_context 'when not intercepting', intercept: false do
|
81
86
|
before do
|
82
|
-
@old_intercept = MandrillBatchMailer
|
83
|
-
MandrillBatchMailer
|
87
|
+
@old_intercept = MandrillBatchMailer.intercept_recipients
|
88
|
+
MandrillBatchMailer.intercept_recipients = false
|
84
89
|
end
|
85
90
|
after do
|
86
|
-
MandrillBatchMailer
|
91
|
+
MandrillBatchMailer.intercept_recipients = @old_intercept
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
90
95
|
shared_context 'when delivering', :deliver do
|
91
96
|
before do
|
92
|
-
@old_deliveries = MandrillBatchMailer
|
93
|
-
MandrillBatchMailer
|
97
|
+
@old_deliveries = MandrillBatchMailer.perform_deliveries
|
98
|
+
MandrillBatchMailer.perform_deliveries = true
|
94
99
|
end
|
95
100
|
after do
|
96
|
-
MandrillBatchMailer
|
101
|
+
MandrillBatchMailer.perform_deliveries = @old_deliveries
|
97
102
|
end
|
98
103
|
end
|
99
104
|
|
100
105
|
shared_context 'when not delivering', deliver: false do
|
101
106
|
before do
|
102
|
-
@old_deveries = MandrillBatchMailer
|
103
|
-
MandrillBatchMailer
|
107
|
+
@old_deveries = MandrillBatchMailer.perform_deliveries
|
108
|
+
MandrillBatchMailer.perform_deliveries = false
|
104
109
|
end
|
105
110
|
after do
|
106
|
-
MandrillBatchMailer
|
111
|
+
MandrillBatchMailer.perform_deliveries = @old_deliveries
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
@@ -124,7 +129,7 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
124
129
|
describe '#template_name' do
|
125
130
|
subject { test_mailer.send :template_name }
|
126
131
|
|
127
|
-
it { should eq 'test-mailer-testing'}
|
132
|
+
it { should eq 'test-mailer-testing' }
|
128
133
|
|
129
134
|
context 'when calling from BaseMailer' do
|
130
135
|
subject { base_mailer.send :template_name }
|
@@ -150,12 +155,12 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
150
155
|
|
151
156
|
describe '#to' do
|
152
157
|
before do
|
153
|
-
test_mailer.instance_variable_set :@tos,
|
158
|
+
test_mailer.instance_variable_set :@tos, user.email => []
|
154
159
|
end
|
155
160
|
subject { test_mailer.send :to }
|
156
161
|
|
157
162
|
context 'when intercepted', :intercept do
|
158
|
-
it { should eq [{ email: 'notifier+0@
|
163
|
+
it { should eq [{ email: 'notifier+0@some-domain.com' }] }
|
159
164
|
end
|
160
165
|
|
161
166
|
context 'when not intercepted', intercept: false do
|
@@ -178,16 +183,16 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
178
183
|
|
179
184
|
describe '#merge_vars' do
|
180
185
|
before do
|
181
|
-
test_mailer
|
182
|
-
base_mailer.send(:tos_from, user.email)
|
186
|
+
test_mailer
|
187
|
+
.instance_variable_set :@tos, base_mailer.send(:tos_from, user.email)
|
183
188
|
end
|
184
189
|
subject(:merge_vars) { test_mailer.send :merge_vars }
|
185
190
|
|
186
191
|
context 'when not intercept', intercept: false do
|
187
|
-
it { should eq [{ rcpt: user.email, vars: [] }]}
|
192
|
+
it { should eq [{ rcpt: user.email, vars: [] }] }
|
188
193
|
end
|
189
194
|
context 'when intercept_recipients', :intercept do
|
190
|
-
it { expect(merge_vars.first[:rcpt]).to eq 'notifier+0@
|
195
|
+
it { expect(merge_vars.first[:rcpt]).to eq 'notifier+0@some-domain.com' }
|
191
196
|
it do
|
192
197
|
expect(merge_vars.first[:vars].first[:content]).to include user.email
|
193
198
|
end
|
@@ -216,14 +221,14 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
216
221
|
describe '#translations' do
|
217
222
|
subject { test_mailer.send :translations }
|
218
223
|
it do
|
219
|
-
should eq translations[:
|
224
|
+
should eq translations[:test_mailer][:testing]
|
220
225
|
end
|
221
226
|
end
|
222
227
|
|
223
228
|
describe '#shared_translations' do
|
224
229
|
subject { test_mailer.send :shared_translations }
|
225
230
|
it do
|
226
|
-
should eq translations[:
|
231
|
+
should eq translations[:shared_translations]
|
227
232
|
.deep_merge(subject)
|
228
233
|
end
|
229
234
|
end
|
@@ -251,9 +256,44 @@ describe MandrillBatchMailer::BaseMailer, :dbless do
|
|
251
256
|
end
|
252
257
|
|
253
258
|
context 'when not performing deliveries', deliver: false do
|
254
|
-
after { test_mailer.send :send_template, params }
|
255
259
|
it 'just logs something' do
|
256
260
|
expect(MandrillBatchMailer.logger).to receive(:info)
|
261
|
+
test_mailer.send :send_template, params
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'awesome_print is available' do
|
265
|
+
before { module AwesomePrint; end }
|
266
|
+
after { Object.send :remove_const, 'AwesomePrint' }
|
267
|
+
|
268
|
+
it 'uses awesome_print' do
|
269
|
+
expect_any_instance_of(Hash).to receive :ai
|
270
|
+
test_mailer.send :send_template, params
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe '#tags' do
|
277
|
+
before do
|
278
|
+
allow(base_mailer)
|
279
|
+
.to receive(:template_name)
|
280
|
+
.and_return 'my_template_name'
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'defaults to template name' do
|
284
|
+
expect(base_mailer.tags).to eq ['my_template_name']
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe 'calling the Mailer with class methods' do
|
289
|
+
it 'should create an instance and call instance_method' do
|
290
|
+
expect_any_instance_of(TestMailer).to receive :testing
|
291
|
+
TestMailer.testing
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when instance method does not exist' do
|
295
|
+
it 'throws an error' do
|
296
|
+
expect { TestMailer.method_does_not_exist }.to raise_error
|
257
297
|
end
|
258
298
|
end
|
259
299
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path '../../lib', __FILE__
|
2
|
-
require 'mandrill_batch_mailer'
|
3
|
-
require 'mandrill_batch_mailer/base_mailer'
|
4
2
|
|
5
3
|
require 'pry'
|
6
4
|
require 'faker'
|
7
5
|
require 'simplecov'
|
8
6
|
require 'coveralls'
|
9
7
|
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
Coveralls::SimpleCov::Formatter
|
11
|
+
]
|
10
12
|
SimpleCov.start
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
14
|
+
require 'mandrill_batch_mailer'
|
15
|
+
require 'mandrill_batch_mailer/base_mailer'
|
15
16
|
|
16
17
|
RSpec.configure do |config|
|
17
18
|
config.order = 'random'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill_batch_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- schasse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|