iron_mailer 0.0.10 → 0.0.11
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.
- data/iron_mailer.gemspec +1 -1
- data/lib/iron_mailer/send_email.rb +9 -1
- data/lib/iron_mailer/version.rb +1 -1
- data/spec/iron_mailer/send_email_spec.rb +78 -33
- metadata +18 -2
data/iron_mailer.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'iron_cache'
|
2
|
+
require 'uuidtools'
|
2
3
|
class IronMailer::SendEmail
|
3
4
|
attr_reader :iron_mq_client, :iron_cache_client, :queue, :cache, :debug, :delivery_method, :delivery_method_settings
|
4
5
|
|
@@ -43,6 +44,7 @@ class IronMailer::SendEmail
|
|
43
44
|
duplicate.bcc = nil
|
44
45
|
duplicate.cc = nil
|
45
46
|
end
|
47
|
+
duplicate.header['X-SMTPAPI']={cache_key: UUIDTools::UUID.random_create.to_s}.to_json
|
46
48
|
duplicate
|
47
49
|
}
|
48
50
|
end
|
@@ -56,6 +58,12 @@ class IronMailer::SendEmail
|
|
56
58
|
}
|
57
59
|
end
|
58
60
|
|
61
|
+
def cache_email(mail)
|
62
|
+
field = mail.header['X-SMTPAPI'].is_a?(Array) ? mail.header['X-SMTPAPI'].first : mail.header['X-SMTPAPI']
|
63
|
+
cache_key = JSON.parse(field.value)['cache_key']
|
64
|
+
self.cache.put(cache_key, self.extract_cache_info(mail).to_json)
|
65
|
+
end
|
66
|
+
|
59
67
|
def execute
|
60
68
|
messages = self.queue.get(:n=>100)
|
61
69
|
|
@@ -69,7 +77,7 @@ class IronMailer::SendEmail
|
|
69
77
|
mails.each do |mail|
|
70
78
|
mail.delivery_method self.delivery_method, self.delivery_method_settings
|
71
79
|
mail.deliver
|
72
|
-
|
80
|
+
cache_email(mail)
|
73
81
|
end
|
74
82
|
message.delete
|
75
83
|
rescue Exception=>e
|
data/lib/iron_mailer/version.rb
CHANGED
@@ -94,33 +94,6 @@ describe IronMailer::SendEmail do
|
|
94
94
|
|
95
95
|
end
|
96
96
|
|
97
|
-
def test_config
|
98
|
-
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
99
|
-
@iron_cache_config = JSON.parse(File.read('spec/config/iron_cache.json'))
|
100
|
-
{'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>false}
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_email(other_tos=[])
|
104
|
-
to = (['to@example.com']<<other_tos)
|
105
|
-
|
106
|
-
mail=Mail.new do
|
107
|
-
to to
|
108
|
-
from "from@example.com"
|
109
|
-
subject "This is a test email"
|
110
|
-
if block_given?
|
111
|
-
body yield
|
112
|
-
else
|
113
|
-
text_part do
|
114
|
-
body "This is a test"
|
115
|
-
end
|
116
|
-
html_part do
|
117
|
-
content_type 'text/html; charset=UTF-8'
|
118
|
-
body "<h1>This is a test</h1>"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
97
|
describe "execute" do
|
125
98
|
before(:each) do
|
126
99
|
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
@@ -150,11 +123,8 @@ describe IronMailer::SendEmail do
|
|
150
123
|
end
|
151
124
|
|
152
125
|
it "should add info about the email to the cache" do
|
153
|
-
@
|
154
|
-
|
155
|
-
lambda{
|
156
|
-
JSON.parse(@send_email.cache.get(@test_email.message_id).value)
|
157
|
-
}.should_not raise_error
|
126
|
+
@send_email.should_receive(:cache_email)
|
127
|
+
@execute.call
|
158
128
|
end
|
159
129
|
|
160
130
|
it "should call deliver with on the results of split_email" do
|
@@ -192,7 +162,49 @@ describe IronMailer::SendEmail do
|
|
192
162
|
end
|
193
163
|
end
|
194
164
|
|
195
|
-
|
165
|
+
describe "cache_email" do
|
166
|
+
before(:each) do
|
167
|
+
@send_email = IronMailer::SendEmail.new(test_config)
|
168
|
+
@test_email = @send_email.split_email(test_email).first
|
169
|
+
@cache=lambda{
|
170
|
+
@send_email.cache_email(@test_email)
|
171
|
+
@send_email.cache.reload
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
after(:each) do
|
177
|
+
@send_email.cache.clear if @send_email.cache.size > 0
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should add an item to the cache " do
|
181
|
+
@cache.should change(@send_email.cache, :size).by(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should use the cache key from the header" do
|
185
|
+
@cache.call
|
186
|
+
cache_key=JSON.parse(@test_email.header['X-SMTPAPI'].value)['cache_key']
|
187
|
+
@send_email.cache.get(cache_key).should_not be_nil
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should blow up if the cache key is blank" do
|
191
|
+
@test_email.header['X-SMTPAPI'] = nil
|
192
|
+
@test_email.header['X-SMTPAPI'] = {cache_key: nil}.to_json
|
193
|
+
@cache.should raise_error
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should blow up if the header is blank" do
|
197
|
+
@test_email.header['X-SMTPAPI'] = nil
|
198
|
+
@test_email.header['X-SMTPAPI'] = ""
|
199
|
+
@cache.should raise_error
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should handle 'X-SMTPAPI' being an array" do
|
203
|
+
@test_email.header['X-SMTPAPI'] = 'some_header_value'
|
204
|
+
@cache.should change(@send_email.cache, :size).by(1)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
196
208
|
describe "extract_cache_info" do
|
197
209
|
before(:each) do
|
198
210
|
@send_email = IronMailer::SendEmail.new(test_config)
|
@@ -268,5 +280,38 @@ describe IronMailer::SendEmail do
|
|
268
280
|
}
|
269
281
|
@send_email.split_email(@test_email).first.body.to_s.should =~ /This is not multipart/
|
270
282
|
end
|
283
|
+
|
284
|
+
it "should include a cache_id in the smtp headers" do
|
285
|
+
@email = @send_email.split_email(@test_email).first
|
286
|
+
JSON.parse(@email.header['X-SMTPAPI'].first.value)['cache_key'].should_not be_blank
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_config
|
291
|
+
@iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
|
292
|
+
@iron_cache_config = JSON.parse(File.read('spec/config/iron_cache.json'))
|
293
|
+
{'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>false}
|
271
294
|
end
|
295
|
+
|
296
|
+
def test_email(other_tos=[])
|
297
|
+
to = (['to@example.com']<<other_tos)
|
298
|
+
|
299
|
+
mail=Mail.new do
|
300
|
+
to to
|
301
|
+
from "from@example.com"
|
302
|
+
subject "This is a test email"
|
303
|
+
if block_given?
|
304
|
+
body yield
|
305
|
+
else
|
306
|
+
text_part do
|
307
|
+
body "This is a test"
|
308
|
+
end
|
309
|
+
html_part do
|
310
|
+
content_type 'text/html; charset=UTF-8'
|
311
|
+
body "<h1>This is a test</h1>"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
272
317
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: uuidtools
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
126
142
|
description: A Rails mail delivery method using Iron MQ & Workers
|
127
143
|
email:
|
128
144
|
- erich@hordesoftware.com
|