mandrill_mailer 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -29
- data/change_log.md +3 -0
- data/lib/mandrill_mailer/offline.rb +40 -0
- data/lib/mandrill_mailer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 066d9d8a41e15e942635771fdef695a54a71a667
|
4
|
+
data.tar.gz: c1dddaf88be75ed2ddab9165767145aace80dc1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 768bfe2d37ea0b516bead42c089ffdb5d2a077bb8e0300a5e721f8ec656f1fc9717e068877e5b6d5c190c2b73e6c09fdea9e67a74b47f8a2332e74a77ac8a05e
|
7
|
+
data.tar.gz: df0ea1de244c30e78cb3b5c8de329c2f8bc017abb01e56369dab9c7c715a280a8da9d4ada95f1538d2b8d4bcad9455868cfb07ed48cd165f3429e98d9af85e52
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Mandrill Mailer gem
|
2
|
-
|
2
|
+
MandrillMailer class for sending transactional emails through Mandrill.
|
3
3
|
Only template based emails are supported at this time.
|
4
4
|
|
5
5
|
## Usage
|
@@ -10,7 +10,7 @@ You don't need to add the ActionMailer stuff unless your still using ActionMaile
|
|
10
10
|
This just plugs into the Mandrill smtp servers. If your doing template based emails
|
11
11
|
through the Mandrill api you really only need the `MandrillMailer.configure` part
|
12
12
|
|
13
|
-
```
|
13
|
+
```ruby
|
14
14
|
ActionMailer::Base.smtp_settings = {
|
15
15
|
:address => "smtp.mandrillapp.com",
|
16
16
|
:port => 587,
|
@@ -35,31 +35,31 @@ in your environment config files:
|
|
35
35
|
## Creating a new mailer
|
36
36
|
Creating a new Mandrill Mailer is similar to a normal Rails mailer:
|
37
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
|
-
|
62
|
-
|
38
|
+
```ruby
|
39
|
+
class InvitationMailer < MandrillMailer::TemplateMailer
|
40
|
+
default from: 'support@example.com'
|
41
|
+
|
42
|
+
def invite(invitation)
|
43
|
+
mandrill_mail template: 'Group Invite',
|
44
|
+
subject: I18n.t('invitation_mailer.invite.subject'),
|
45
|
+
to: invitation.invitees.map {|invitee| { email: invitee.email, name: invitee.name }},
|
46
|
+
# to: {email: invitation.email, name: 'Honored Guest'},
|
47
|
+
vars: {
|
48
|
+
'OWNER_NAME' => invitation.owner_name,
|
49
|
+
'PROJECT_NAME' => invitation.project_name
|
50
|
+
},
|
51
|
+
important: true,
|
52
|
+
inline_css: true,
|
53
|
+
recipient_vars: invitation.invitees.map do |invitee| # invitation.invitees is an Array
|
54
|
+
{ invitee.email =>
|
55
|
+
{
|
56
|
+
'INVITEE_NAME' => invitee.name,
|
57
|
+
'INVITATION_URL' => new_invitation_url(invitee.email, secret: invitee.secret_code)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
63
|
```
|
64
64
|
|
65
65
|
* `#default:`
|
@@ -133,7 +133,7 @@ You can test the above email by typing: `InvitationMailer.test(:invite, email:<y
|
|
133
133
|
|
134
134
|
The test for this particular Mailer is setup like so:
|
135
135
|
|
136
|
-
```
|
136
|
+
```ruby
|
137
137
|
test_setup_for :invite do |mailer, options|
|
138
138
|
invitation = MandrillMailer::Mock.new({
|
139
139
|
email: options[:email],
|
@@ -150,7 +150,7 @@ If in order to represent a url within a mock, make sure there is a `url` or `pat
|
|
150
150
|
for example, if I had a course mock and I was using the `course_url` route helper within the mailer
|
151
151
|
I would create the mock like so:
|
152
152
|
|
153
|
-
```
|
153
|
+
```ruby
|
154
154
|
course = MandrillMailer::Mock.new({
|
155
155
|
title: 'zombies',
|
156
156
|
type: 'Ruby',
|
@@ -164,6 +164,29 @@ The mailer and options passed to the `.test` method are yielded to the block.
|
|
164
164
|
|
165
165
|
The `:email` option is the only required option, make sure to add at least this to your test object.
|
166
166
|
|
167
|
+
## Offline Testing
|
168
|
+
You can turn on offline testing by requiring this file (say, in your spec_helper.rb):
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
require 'mandrill_mailer/offline'
|
172
|
+
```
|
173
|
+
|
174
|
+
And then if you wish you can look at the contents of `MandrillMailer.deliveries` to see whether an email was queued up by your test:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
email = MandrillMailer::deliveries.detect { |mail|
|
178
|
+
mail.template_name == 'my-template' &&
|
179
|
+
mail.message['to'].any? { |to| to['email'] == 'my@email.com' }
|
180
|
+
}
|
181
|
+
expect(email).to_not be_nil
|
182
|
+
```
|
183
|
+
|
184
|
+
Don't forget to clear out deliveries:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
before :each { MandrillMailer.deliveries.clear }
|
188
|
+
```
|
189
|
+
|
167
190
|
## Using Delayed Job
|
168
191
|
The typical Delayed Job mailer syntax won't work with this as of now. Either create a custom job or que the mailer as you would que a method. Take a look at the following examples:
|
169
192
|
|
data/change_log.md
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Offline modifications for using MandrillMailer without actually sending
|
2
|
+
# emails through Mandrill's API. Particularly useful for acceptance tests.
|
3
|
+
#
|
4
|
+
# To use, just require this file (say, in your spec_helper.rb):
|
5
|
+
#
|
6
|
+
# require 'mandrill_mailer/offline'
|
7
|
+
#
|
8
|
+
# And then if you wish you can look at the contents of
|
9
|
+
# MandrillMailer.deliveries to see whether an email was queued up by your test:
|
10
|
+
#
|
11
|
+
# email = MandrillMailer::deliveries.detect { |mail|
|
12
|
+
# mail.template_name == 'my-template' &&
|
13
|
+
# mail.message['to'].any? { |to| to['email'] == 'my@email.com' }
|
14
|
+
# }
|
15
|
+
# expect(email).to_not be_nil
|
16
|
+
#
|
17
|
+
# Don't forget to clear out deliveries:
|
18
|
+
#
|
19
|
+
# before :each { MandrillMailer.deliveries.clear }
|
20
|
+
#
|
21
|
+
require 'mandrill_mailer'
|
22
|
+
|
23
|
+
module MandrillMailer
|
24
|
+
def self.deliveries
|
25
|
+
@deliveries ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
class TemplateMailer
|
29
|
+
def deliver
|
30
|
+
MandrillMailer.deliveries << MandrillMailer::Mock.new({
|
31
|
+
:template_name => template_name,
|
32
|
+
:template_content => template_content,
|
33
|
+
:message => message,
|
34
|
+
:async => async,
|
35
|
+
:ip_pool => ip_pool,
|
36
|
+
:send_at => send_at
|
37
|
+
})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Rensel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- change_log.md
|
95
95
|
- lib/mandrill_mailer.rb
|
96
96
|
- lib/mandrill_mailer/mock.rb
|
97
|
+
- lib/mandrill_mailer/offline.rb
|
97
98
|
- lib/mandrill_mailer/railtie.rb
|
98
99
|
- lib/mandrill_mailer/template_mailer.rb
|
99
100
|
- lib/mandrill_mailer/version.rb
|