mandrails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/mandrails.rb +4 -0
- data/lib/mandrails/delivery/mandrill.rb +75 -0
- data/lib/mandrails/message_builder.rb +100 -0
- data/lib/mandrails/railtie.rb +11 -0
- data/lib/mandrails/version.rb +3 -0
- data/mandrails.gemspec +26 -0
- data/spec/factories.rb +50 -0
- data/spec/mandrails/delivery/mandrill_spec.rb +62 -0
- data/spec/mandrails/message_builder_spec.rb +115 -0
- data/spec/spec_helper.rb +5 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 232ca2cd61971d639dff8c2a880335c979b218f7
|
4
|
+
data.tar.gz: a5a4a0d3ec3c9d0ee8283281f80710cd28a1fcb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c02696ceff66b20285ae3309edd86f6a91841fe81e63920cb98604e80281cbe6d54a579ec25fd3f8b31862a198aee9138b88daa94310dbd9a0fba7328c945ba
|
7
|
+
data.tar.gz: a54f6b7599bc5f7fb4da2fea9624304f8842d4ee310bfb6dbed84751c9f1501b439f64aa5d48c5c9a39c27a53d815903fedbc2e9326d978d944ddc04b8416e36
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013,2014 at-point ag. http://at-point.ch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Mandrails - The Mandrill/ActionMailer connector
|
2
|
+
|
3
|
+
A delivery method implementation which uses the Mandrill REST API. This allows
|
4
|
+
to simply send e-mails from a Rails app using Mandrill instead of SMTP or
|
5
|
+
sendmail.
|
6
|
+
|
7
|
+
### Open items
|
8
|
+
|
9
|
+
Currently this gem is in alpha quality, things we are still working:
|
10
|
+
|
11
|
+
- [ ] Support for custom `X-` headers
|
12
|
+
- [ ] Ability to override Mandrill settings, e.g. click tracking, per mail
|
13
|
+
- [x] <del>Improve test cases</del>
|
14
|
+
- [x] <del>Implement Railtie which automatically hooks delivery method into AM</del>
|
15
|
+
- [x] <del>Attachment support</del>
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add mandrails to your Gemfile and run `bundle` afterwards:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'mandrails'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
When using with Rails it's basically all setup to use the `:mandrill` delivery
|
28
|
+
handler in config/environemnts/*.rb:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
config.action_mailer.delivery_method = :mandrill
|
32
|
+
config.action_mailer.mandrill_settings = {
|
33
|
+
key: "123...-abcde", # or set the MANDRILL_APIKEY environment variable
|
34
|
+
from_name: "My Application",
|
35
|
+
from_email: "saas@example.com"
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
Basically the `:key` and `:from_email` are required attributes, the `:key` can
|
40
|
+
be omitted if the `MANDRILL_APIKEY` environment variable is set.
|
41
|
+
|
42
|
+
## Additional information
|
43
|
+
|
44
|
+
### Mailchimp & Mandrill
|
45
|
+
|
46
|
+
Thanks to the team at [Mailchimp][mc] which provides the [mandrill-api gem][gem]
|
47
|
+
and of course the [Mandrill service][ma] itself. FYI - the maintainers of this
|
48
|
+
gem are in no way affiliated with Mailchimp or Mandrill.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
MIT License. Copyright 2013 at-point ag. http://at-point.ch
|
53
|
+
|
54
|
+
[mc]: http://mailchimp.com/
|
55
|
+
[gem]: https://bitbucket.org/mailchimp/mandrill-api-ruby/
|
56
|
+
[ma]: https://mandrillapp.com/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mandrails.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "mail"
|
2
|
+
require "mandrill"
|
3
|
+
|
4
|
+
require "mandrails/message_builder"
|
5
|
+
|
6
|
+
module Mandrails
|
7
|
+
module Delivery
|
8
|
+
|
9
|
+
# == Sending e-mail with Mandrill API
|
10
|
+
#
|
11
|
+
# A delivery method implementation which uses the Mandrill REST API.
|
12
|
+
# This is done by providing a mailer on top of mandrill-api gem.
|
13
|
+
#
|
14
|
+
# === Using it with mail gem
|
15
|
+
#
|
16
|
+
# Requires the <code>:key</code> option, or set the environment
|
17
|
+
# variable <code>MANDRILL_APIKEY</code> to a your Mandrill API key.
|
18
|
+
#
|
19
|
+
# Mail.defaults do
|
20
|
+
# delivery_method Mandrails::Delivery::Mandrill, {
|
21
|
+
# :key => "123...-abcde", # or set the MANDRILL_APIKEY environment variable
|
22
|
+
# :from_name => "Your Name",
|
23
|
+
# :from_email => "your@mail.com" }
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# === Using it with Rails & ActionMailer
|
27
|
+
#
|
28
|
+
# Using the railtie the <code>:mandrill</code> delivery method is
|
29
|
+
# automatically available, also ensure to set the API key using
|
30
|
+
# either <code>:key</code> setting or <code>MANDRILL_APIKEY</code>
|
31
|
+
# environment variable. Add something like to the <code>config/environments/*</code>:
|
32
|
+
#
|
33
|
+
# config.action_mailer.delivery_method = :mandrill
|
34
|
+
# config.action_mailer.mandrails_settings = {
|
35
|
+
# key: "123...-abcde", # or set the MANDRILL_APIKEY environment variable
|
36
|
+
# from_name: "Your Name",
|
37
|
+
# from_email: "your@mail.com" }
|
38
|
+
#
|
39
|
+
class Mandrill
|
40
|
+
|
41
|
+
# Provide read/write access, dunno why write access is required,
|
42
|
+
# but seems to be in all deliver_methods from mikel/mail as well
|
43
|
+
attr_accessor :settings
|
44
|
+
|
45
|
+
def initialize(values = nil) #:nodoc:
|
46
|
+
@settings = {
|
47
|
+
track_opens: true,
|
48
|
+
track_clicks: false,
|
49
|
+
auto_text: true,
|
50
|
+
merge: false,
|
51
|
+
async: false,
|
52
|
+
key: ::ENV['MANDRILL_APIKEY'].presence
|
53
|
+
}.merge(values || {})
|
54
|
+
end
|
55
|
+
|
56
|
+
# Public: Access to the Mandrill::API instance used to send messages. It raises an
|
57
|
+
# error if no key was given or is present.
|
58
|
+
#
|
59
|
+
# Returns Mandrill::API instance.
|
60
|
+
def mandrill_api
|
61
|
+
@mandrill_api ||= ::Mandrill::API.new(settings[:key].presence)
|
62
|
+
end
|
63
|
+
|
64
|
+
def deliver!(mail)
|
65
|
+
# TODO: verify incoming `mail` argument, see https://github.com/mikel/mail/blob/master/lib/mail/check_delivery_params.rb
|
66
|
+
builder = Mandrails::MessageBuilder.new mail, settings
|
67
|
+
response = mandrill_api.messages.send(builder.as_json, settings[:async])
|
68
|
+
|
69
|
+
# Either return response or instance
|
70
|
+
return response if settings[:return_response]
|
71
|
+
self
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Mandrails
|
5
|
+
|
6
|
+
# The MessageBuilder is used to convert a Mail::Message into a JSON object
|
7
|
+
# consumable by the Mandrill API.
|
8
|
+
class MessageBuilder
|
9
|
+
|
10
|
+
# Setting keys which are not allowed to by set by the message
|
11
|
+
RESTRICTED_KEYS = %w{key async}
|
12
|
+
|
13
|
+
# Known mandrill settings
|
14
|
+
MANDRILL_SETTINGS = [:track_opens, :track_clicks, :auto_text,
|
15
|
+
:url_strip_qs, :preserve_recipients, :bcc_address]
|
16
|
+
|
17
|
+
# Access to mail and defaults
|
18
|
+
attr_reader :mail, :defaults
|
19
|
+
|
20
|
+
# Public:
|
21
|
+
#
|
22
|
+
def initialize(mail, defaults = {})
|
23
|
+
@mail = mail
|
24
|
+
@defaults = defaults.reject { |key, value| RESTRICTED_KEYS.include?(key.to_s) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def message
|
28
|
+
@message ||= defaults.merge(
|
29
|
+
# E-Mail stuff
|
30
|
+
html: body(:html),
|
31
|
+
text: body(:text),
|
32
|
+
subject: mail.subject,
|
33
|
+
from_email: from_email,
|
34
|
+
from_name: from_name,
|
35
|
+
to: recipients,
|
36
|
+
|
37
|
+
# Additional headers
|
38
|
+
attachments: attachments,
|
39
|
+
headers: headers)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Internal: Extract from name from either the header or defaults.
|
43
|
+
#
|
44
|
+
# Returns String.
|
45
|
+
def from_name
|
46
|
+
mail.header['from-name'].to_s.presence || defaults[:from_name]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Internal: Extract from email.
|
50
|
+
#
|
51
|
+
# Returns String
|
52
|
+
def from_email
|
53
|
+
mail.from && mail.from.first.presence || defaults[:from_email]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Internal: Extract body of specified format, if any.
|
57
|
+
#
|
58
|
+
# Returns String or nil.
|
59
|
+
def body(format)
|
60
|
+
content = mail.send("#{format}_part").presence
|
61
|
+
content ||= mail if mail.mime_type =~ %r{\Atext/#{format}} || format == :text && text?
|
62
|
+
content.body.raw_source if content.present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def text?
|
66
|
+
mail.mime_type =~ %r{\Atext/plain} || !mail.mime_type
|
67
|
+
end
|
68
|
+
|
69
|
+
# Internal: Build recipients list.
|
70
|
+
#
|
71
|
+
# Returns Array of Hash with `:name`, `:email`.
|
72
|
+
def recipients
|
73
|
+
[mail.to, mail.cc].compact.flatten.map { |email| { email: email, name: email } }
|
74
|
+
end
|
75
|
+
|
76
|
+
# Internal: Extract attachments.
|
77
|
+
#
|
78
|
+
# Returns Array of Hash.
|
79
|
+
def attachments
|
80
|
+
return unless mail.attachments.length > 0
|
81
|
+
mail.attachments.map do |part|
|
82
|
+
{ type: part.mime_type, name: part.filename, content: Base64.encode64(part.body.raw_source).strip }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Internal: Extract Reply-To header field.
|
87
|
+
# FIXME: extract all X-* headers as well!
|
88
|
+
#
|
89
|
+
# Returns Hash.
|
90
|
+
def headers
|
91
|
+
headers = {}
|
92
|
+
headers['Reply-To'] = mail.reply_to.first.to_s if mail.reply_to.present?
|
93
|
+
headers
|
94
|
+
end
|
95
|
+
|
96
|
+
def as_json
|
97
|
+
message
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Mandrails
|
4
|
+
class Railtie < Rails::Railtie #:nodoc:
|
5
|
+
initializer 'mandrails.setup_action_mailer', before: 'action_mailer.set_configs' do
|
6
|
+
ActiveSupport.on_load(:action_mailer) do
|
7
|
+
add_delivery_method :mandrill, Mandrails::Delivery::Mandrill
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/mandrails.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mandrails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "mandrails"
|
6
|
+
gem.version = Mandrails::VERSION
|
7
|
+
gem.authors = ["Lukas Westermann", "Philip Lehmann"]
|
8
|
+
gem.email = ["lukas@at-point.ch", "philip@at-point.ch"]
|
9
|
+
gem.summary = %q{An e-mail delivery method implementation which uses the Mandrill REST API.}
|
10
|
+
gem.description = %q{Provides a delivery method implementation for ActionMailer and mail which uses the Mandrill REST API.}
|
11
|
+
gem.homepage = "https://github.com/at-point/mandrails"
|
12
|
+
|
13
|
+
gem.files = %w{.gitignore Gemfile Rakefile README.md LICENSE.txt mandrails.gemspec} + Dir['{lib,spec}/**/*.rb']
|
14
|
+
gem.test_files = Dir['spec/**/*.rb']
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.required_ruby_version = '>= 1.9'
|
18
|
+
|
19
|
+
gem.add_dependency 'mail', '>= 2.0'
|
20
|
+
gem.add_dependency 'activesupport', '>= 4.0.0'
|
21
|
+
gem.add_dependency 'mandrill-api', '>= 1.0'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.12'
|
25
|
+
gem.add_development_dependency 'actionmailer', '>= 4.0.0'
|
26
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
module Factories
|
4
|
+
module Emails
|
5
|
+
def text_mail
|
6
|
+
@text_mail ||= Mail.new do
|
7
|
+
from 'mila@fox.com'
|
8
|
+
to 'megan@fox.com'
|
9
|
+
subject 'Hi'
|
10
|
+
body 'Yoo buddy'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def html_mail
|
15
|
+
@html_mail ||= Mail.new do
|
16
|
+
to 'megan@fox.com'
|
17
|
+
content_type 'text/html'
|
18
|
+
body '<b>Yoo</b> buddy'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def multipart_mail
|
23
|
+
@multipart_mail ||= Mail.new do
|
24
|
+
to 'megan@fox.com'
|
25
|
+
text_part { body 'Yoo buddy' }
|
26
|
+
html_part { body '<b>Yoo</b> buddy' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def cc_mail
|
31
|
+
@cc_mail ||= begin
|
32
|
+
text_mail[:to] = 'Megan <megan@fox.com>'
|
33
|
+
text_mail[:cc] = 'Mila <mila@fox.com>'
|
34
|
+
text_mail[:bcc] = 'Emma <emma@fox.com>'
|
35
|
+
text_mail
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def attachment_mail
|
40
|
+
@attachment_mail ||= Mail.new do
|
41
|
+
to 'megan@fox.com'
|
42
|
+
subject 'Hi'
|
43
|
+
body 'Yooo with attachment'
|
44
|
+
|
45
|
+
attachments['file.pdf'] = { mime_type: 'application/pdf', content: 'PDF FILE BRO!' }
|
46
|
+
attachments['other.csv'] = { mime_type: 'text/csv', content: "A,B,C\n1,2,3\n" }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mandrails/delivery/mandrill'
|
3
|
+
|
4
|
+
describe Mandrails::Delivery::Mandrill do
|
5
|
+
include Factories::Emails
|
6
|
+
|
7
|
+
subject { described_class.new(key: "12345") }
|
8
|
+
|
9
|
+
let(:messages) {
|
10
|
+
double("messages").tap { |msg| subject.mandrill_api.stub(:messages) { msg } }
|
11
|
+
}
|
12
|
+
|
13
|
+
context ':key' do
|
14
|
+
it 'raises an exception if missing' do
|
15
|
+
handler = described_class.new(key: nil)
|
16
|
+
expect { handler.deliver!(text_mail) }.to raise_error ::Mandrill::Error, /Mandrill API key/
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is forwarded to mandrill gem as key when creating API instance' do
|
20
|
+
subject.mandrill_api.apikey.should == "12345"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#deliver!' do
|
25
|
+
it 'delegates message to mandrill gem' do
|
26
|
+
messages.should_receive(:send).with(kind_of(Hash), false) { "OK" }
|
27
|
+
subject.deliver! text_mail
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'async' do
|
31
|
+
it 'normally does not send async' do
|
32
|
+
messages.should_receive(:send).with(kind_of(Hash), false) { "OK" }
|
33
|
+
subject.deliver! text_mail
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when :async is true' do
|
37
|
+
subject { described_class.new(key: '12345', async: true) }
|
38
|
+
|
39
|
+
it 'defaults to sending async' do
|
40
|
+
messages.should_receive(:send).with(kind_of(Hash), true) { "OK" }
|
41
|
+
subject.deliver! text_mail
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'return value' do
|
47
|
+
it 'normally returns self' do
|
48
|
+
messages.should_receive(:send) { "OK" }
|
49
|
+
subject.deliver!(text_mail).should eql subject
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when :return_response is true' do
|
53
|
+
subject { described_class.new(key: '12345', return_response: true) }
|
54
|
+
|
55
|
+
it 'returns the response 1:1 as returned by the mandrill gem' do
|
56
|
+
messages.should_receive(:send) { "TEH result" }
|
57
|
+
subject.deliver!(text_mail).should == "TEH result"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mail'
|
3
|
+
require 'mandrails/message_builder'
|
4
|
+
|
5
|
+
describe Mandrails::MessageBuilder do
|
6
|
+
include Factories::Emails
|
7
|
+
|
8
|
+
subject { described_class.new(text_mail).as_json }
|
9
|
+
|
10
|
+
context 'subject' do
|
11
|
+
it 'sets :subject' do
|
12
|
+
subject[:subject].should == 'Hi'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'recipients' do
|
17
|
+
it 'sets :to Array' do
|
18
|
+
subject[:to].should == [{ email: "megan@fox.com", name: "megan@fox.com" }]
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'To, Cc & Bcc' do
|
22
|
+
subject { described_class.new(cc_mail).as_json }
|
23
|
+
|
24
|
+
it 'sets :to by combining To & Cc' do
|
25
|
+
subject[:to].should == [{ email: "megan@fox.com", name: "megan@fox.com" }, { email: "mila@fox.com", name: "mila@fox.com" }]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'from' do
|
31
|
+
it 'sets :from_email and :from_name' do
|
32
|
+
subject[:from_email].should == 'mila@fox.com'
|
33
|
+
subject[:from_name].should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets :from_name based on header' do
|
37
|
+
text_mail[:from_name] = 'Mila'
|
38
|
+
subject[:from_name].should == 'Mila'
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with default from_name & from_email' do
|
42
|
+
subject { described_class.new(text_mail, from_name: "App", from_mail: "app@fox.com").as_json }
|
43
|
+
|
44
|
+
it 'sets :from_name from default' do
|
45
|
+
subject[:from_name].should == 'App'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'body' do
|
51
|
+
context 'text only mail' do
|
52
|
+
subject { described_class.new(text_mail).as_json }
|
53
|
+
|
54
|
+
it 'sets :html key to nil' do
|
55
|
+
subject[:html].should be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets :text' do
|
59
|
+
subject[:text].should == 'Yoo buddy'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'html only mail' do
|
64
|
+
subject { described_class.new(html_mail).as_json }
|
65
|
+
|
66
|
+
it 'sets :html' do
|
67
|
+
subject[:html].should == '<b>Yoo</b> buddy'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'sets :text to nil' do
|
71
|
+
subject[:text].should be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'multipart mail' do
|
76
|
+
subject { described_class.new(multipart_mail).as_json }
|
77
|
+
|
78
|
+
it 'sets :html' do
|
79
|
+
subject[:html].should == '<b>Yoo</b> buddy'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'sets :text' do
|
83
|
+
subject[:text].should == 'Yoo buddy'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'attachments' do
|
89
|
+
subject { described_class.new(attachment_mail).as_json }
|
90
|
+
|
91
|
+
it 'sets :text' do
|
92
|
+
subject[:text].should == 'Yooo with attachment'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has two attachments' do
|
96
|
+
subject[:attachments].length.should == 2
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'first attachment (pdf)' do
|
100
|
+
subject { described_class.new(attachment_mail).as_json[:attachments].first }
|
101
|
+
|
102
|
+
it 'has :type as application/pdf' do
|
103
|
+
subject[:type].should == 'application/pdf'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'has :name' do
|
107
|
+
subject[:name].should == 'file.pdf'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'has Base64 encoded :content' do
|
111
|
+
subject[:content].should == 'UERGIEZJTEUgQlJPIQ=='
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mandrails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Westermann
|
8
|
+
- Philip Lehmann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mail
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 4.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 4.0.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mandrill-api
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.12'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.12'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: actionmailer
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 4.0.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 4.0.0
|
98
|
+
description: Provides a delivery method implementation for ActionMailer and mail which
|
99
|
+
uses the Mandrill REST API.
|
100
|
+
email:
|
101
|
+
- lukas@at-point.ch
|
102
|
+
- philip@at-point.ch
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/mandrails.rb
|
113
|
+
- lib/mandrails/delivery/mandrill.rb
|
114
|
+
- lib/mandrails/message_builder.rb
|
115
|
+
- lib/mandrails/railtie.rb
|
116
|
+
- lib/mandrails/version.rb
|
117
|
+
- mandrails.gemspec
|
118
|
+
- spec/factories.rb
|
119
|
+
- spec/mandrails/delivery/mandrill_spec.rb
|
120
|
+
- spec/mandrails/message_builder_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: https://github.com/at-point/mandrails
|
123
|
+
licenses: []
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.9'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.0
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: An e-mail delivery method implementation which uses the Mandrill REST API.
|
145
|
+
test_files:
|
146
|
+
- spec/factories.rb
|
147
|
+
- spec/mandrails/delivery/mandrill_spec.rb
|
148
|
+
- spec/mandrails/message_builder_spec.rb
|
149
|
+
- spec/spec_helper.rb
|