forked from kshnurov/mandrill_dm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
573 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 1.2 (2015-02-22) | ||
|
||
- [#2](https://github.com/jlberglund/mandrill_dm/pull/2) Attachment support | ||
- [#3](https://github.com/jlberglund/mandrill_dm/pull/3) Add tags and headers to mandrill_dm | ||
- [#5](https://github.com/jlberglund/mandrill_dm/pull/5) Send as text when no html part is found | ||
- [#6](https://github.com/jlberglund/mandrill_dm/pull/6) Update `MandrillDm::DeliveryMethod` to capture the response from the Mandrill API | ||
- [#7](https://github.com/jlberglund/mandrill_dm/pull/7) Ability to send asynchronous messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ class Configuration | |
|
||
def initialize | ||
@api_key = '' | ||
@async = true | ||
@async = false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module MandrillDm | ||
class DeliveryMethod | ||
attr_accessor :settings | ||
attr_accessor :settings, :response | ||
|
||
def initialize(options = {}) | ||
self.settings = options | ||
@settings = options | ||
end | ||
|
||
def deliver!(mail) | ||
mandrill = Mandrill::API.new(MandrillDm.configuration.api_key) | ||
message = Message.new(mail).to_json | ||
result = mandrill.messages.send(message, MandrillDm.configuration.async) | ||
mandrill_api = Mandrill::API.new(MandrillDm.configuration.api_key) | ||
message = Message.new(mail) | ||
@response = mandrill_api.messages.send(message.to_json, MandrillDm.configuration.async) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require 'spec_helper' | ||
|
||
describe MandrillDm::DeliveryMethod, 'integrating with the Mail API', integration: true do | ||
|
||
before(:each) do | ||
Mail.defaults { delivery_method MandrillDm::DeliveryMethod } | ||
end | ||
|
||
context '#deliver' do | ||
let(:from_name) { 'From Name' } | ||
let(:from_email) { 'from@domain.tld' } | ||
let(:from) { "#{from_name} <#{from_email}>" } | ||
let(:to) { (1..3).map { |i| "To #{i} <to_#{i}@domain.tld>" } } | ||
let(:cc) { (1..3).map { |i| "Cc #{i} <cc_#{i}@domain.tld>" } } | ||
let(:bcc) { (1..3).map { |i| "Bcc #{i} <bcc_#{i}@domain.tld>" } } | ||
let(:message_subject) { 'Some Message Subject' } | ||
let(:body) { 'Some Message Body' } | ||
|
||
let(:api) { instance_double(Mandrill::API) } | ||
let(:messages) { instance_double(Mandrill::Messages, send: {}) } | ||
|
||
before(:each) do | ||
allow(Mandrill::API).to receive(:new).and_return(api) | ||
allow(api).to receive(:messages).and_return(messages) | ||
end | ||
|
||
subject do | ||
example = self | ||
Mail.deliver do | ||
from example.from | ||
to example.to | ||
cc example.cc | ||
bcc example.bcc | ||
subject example.message_subject | ||
body example.body | ||
end | ||
end | ||
|
||
it 'instantiates the Mandrill API with the configured API key' do | ||
expect(Mandrill::API).to receive(:new).with(MandrillDm.configuration.api_key).and_return(api) | ||
|
||
subject | ||
end | ||
|
||
it 'successfully sends a message' do | ||
allow(Mandrill::API).to receive(:new).and_call_original | ||
|
||
expect { subject }.not_to raise_error | ||
end | ||
|
||
context 'the sent message' do | ||
it 'contains the provided from address' do | ||
expect(messages).to receive(:send).with(hash_including(from_name: from_name, from_email: from_email), false) | ||
|
||
subject | ||
end | ||
|
||
%w{ to cc bcc }.each do |recipient_type| | ||
it 'contains the provided #{recipient_type} addresses' do | ||
expect(messages).to receive(:send) do |message_hash| | ||
(1..3).each do |i| | ||
expected_recipient = { | ||
email: "#{recipient_type}_#{i}@domain.tld", | ||
name: "#{recipient_type.capitalize} #{i}", | ||
type: recipient_type | ||
} | ||
expect(message_hash[:to]).to include(expected_recipient) | ||
end | ||
end | ||
|
||
subject | ||
end | ||
end | ||
|
||
it 'contains the provided subject' do | ||
expect(messages).to receive(:send).with(hash_including(subject: message_subject), false) | ||
|
||
subject | ||
end | ||
|
||
it 'contains the provided body as HTML' do | ||
expect(messages).to receive(:send).with(hash_including(html: body), false) | ||
|
||
subject | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.