mandrill-api-delivery-method 0.1 → 0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74bcaf23acc15165880998993807a3ae1449f4d1
4
- data.tar.gz: bbfda73af6eb4833c7e1bb5bb28cfcf3c3cdd007
3
+ metadata.gz: 8f93e5e4c86d1ed00d16544b53705dda7fa680cf
4
+ data.tar.gz: 89220324f4a8d2f62f55f986fa80cb33efaeb08d
5
5
  SHA512:
6
- metadata.gz: 43eafd4e1927df227ff5c21cc7ba31f54bbfbad37bc16eb38bd630fb99f09fa9eec7b6d786b299e692d6221c9753123988c552742cabf9b5a56ab94bc592a43a
7
- data.tar.gz: c04472a0d50a1eb5548f9f1f42e3dd9c2597856497decb69761954bc837d159e2430ee8309e6d0773e0307272f44b56211dae6c83c26af1246acae412b0f513d
6
+ metadata.gz: 0cd22a5c97918674d9975379af91d518dc29bcb74f1b1526a00cfd060f9781627e1219d9b2c921b5e43922ed689c023739edcd3bb4720f3e59eea73ecc7aa8d4
7
+ data.tar.gz: 046bad63e0ee100f5f2de538fb168c0d75e31942abd73b927ea358a68d7812fbc205c94a8a127cc25878f721bd2f749dbb0026b6b5d1567aa28e43f155516d7c
@@ -4,6 +4,11 @@ module MandrillAPIDeliveryMethod
4
4
  class DeliveryMethod
5
5
  class InvalidOption < StandardError; end
6
6
 
7
+ @@deliveries = []
8
+ class << self
9
+ attr_accessor :deliveries
10
+ end
11
+
7
12
  attr_accessor :settings
8
13
 
9
14
  def initialize(options = {})
@@ -15,13 +20,20 @@ module MandrillAPIDeliveryMethod
15
20
  begin
16
21
  mandrill = Mandrill::API.new self.settings[:api_key]
17
22
 
18
- message = {
19
- subject: mail.subject,
20
- from_email: mail.from.first,
21
- to: [{
22
- email: mail.to.first
23
- }]
24
- }
23
+ message = mail.mandrill_options || {}
24
+
25
+ unless message.has_key? :subject
26
+ message[:subject] = mail.subject
27
+ end
28
+ unless message.has_key? :from_email
29
+ message[:from_email] = mail.from.first
30
+ end
31
+ unless message.has_key? :to
32
+ message[:to] = []
33
+ mail.to.each do |email_address|
34
+ message[:to] << {email: email_address}
35
+ end
36
+ end
25
37
 
26
38
  if not mail.text_part.nil?
27
39
  message[:text] = mail.text_part.body.to_s
@@ -35,6 +47,10 @@ module MandrillAPIDeliveryMethod
35
47
  send_at = mail.deliver_at.nil? ? Time.now.utc.to_s : mail.deliver_at.uts.to_s
36
48
 
37
49
  result = mandrill.messages.send message, async, nil, send_at
50
+
51
+ if self.settings[:test]
52
+ self.class.deliveries << result
53
+ end
38
54
  rescue Mandrill::Error => e
39
55
  puts "Error delivering mail to Mandrill API: #{e.class} - #{e.message}"
40
56
  raise
@@ -3,16 +3,22 @@ require "spec_helper"
3
3
  describe MandrillAPIDeliveryMethod::DeliveryMethod do
4
4
  before do
5
5
  Mail.defaults do
6
- delivery_method MandrillAPIDeliveryMethod::DeliveryMethod, api_key: ENV["MANDRILL_API_KEY"]
6
+ delivery_method MandrillAPIDeliveryMethod::DeliveryMethod, api_key: ENV["MANDRILL_API_KEY"], test: true
7
7
  end
8
8
  end
9
9
 
10
+ let(:deliveries) { MandrillAPIDeliveryMethod::DeliveryMethod.deliveries }
11
+ before(:each) do
12
+ # Clear deliveries
13
+ MandrillAPIDeliveryMethod::DeliveryMethod.deliveries = []
14
+ end
15
+
10
16
  it 'raises an exception if no api key specified' do
11
17
  expect { MandrillAPIDeliveryMethod::DeliveryMethod.new }.to raise_exception(MandrillAPIDeliveryMethod::DeliveryMethod::InvalidOption)
12
18
  expect { MandrillAPIDeliveryMethod::DeliveryMethod.new(api_key: "123") }.to_not raise_exception
13
19
  end
14
20
 
15
- context 'mail message extension' do
21
+ describe 'mail message extension' do
16
22
  it 'has deliver_at' do
17
23
  m = Mail::Message.new
18
24
  date = Time.now
@@ -28,17 +34,62 @@ describe MandrillAPIDeliveryMethod::DeliveryMethod do
28
34
  end
29
35
  end
30
36
 
31
- context 'delivery' do
32
- it 'should succeed' do
33
- Mail.deliver do
34
- from 'Foo <foo@example.com>'
35
- sender 'Baz <baz@example.com>'
36
- reply_to 'No Reply <no-reply@example.com>'
37
- to 'Bar <bar@example.com>'
38
- cc 'Qux <qux@example.com>'
39
- bcc 'Qux <qux@example.com>'
40
- subject 'Hello'
41
- body 'World! http://example.com'
37
+ describe 'delivery' do
38
+ context 'plain' do
39
+ before(:each) do
40
+ Mail.deliver do
41
+ from 'Foo <foo@example.com>'
42
+ sender 'Baz <baz@example.com>'
43
+ reply_to 'No Reply <no-reply@example.com>'
44
+ to 'Bar <bar@example.com>'
45
+ cc 'Qux <qux@example.com>'
46
+ bcc 'Qux <qux@example.com>'
47
+ subject 'Hello'
48
+ body 'World! http://example.com'
49
+ end
50
+ end
51
+
52
+ it 'should succeed' do
53
+ expect(deliveries.length).to eq 1
54
+ end
55
+ end
56
+
57
+ context 'html' do
58
+ before(:each) do
59
+ Mail.deliver do
60
+ from 'Foo <foo@example.com>'
61
+ to 'Bar <bar@example.com>'
62
+ subject 'Hello'
63
+ text_part do
64
+ body 'World! http://example.com'
65
+ end
66
+ html_part do
67
+ content_type 'text/html; charset=UTF-8'
68
+ body '<h1>World! http://example.com</h1>'
69
+ end
70
+ end
71
+ end
72
+
73
+ it 'should succeed' do
74
+ expect(deliveries.length).to eq 1
75
+ end
76
+ end
77
+
78
+ context 'attachments' do
79
+ before(:each) do
80
+ Mail.deliver do
81
+ from 'Foo <foo@example.com>'
82
+ to 'Bar <bar@example.com>'
83
+ subject 'Hello'
84
+ text_part do
85
+ body 'World! http://example.com'
86
+ end
87
+ attachments[File.basename(__FILE__)] = File.read(__FILE__)
88
+ end
89
+ end
90
+
91
+ it 'should succeed' do
92
+ expect(deliveries.length).to eq 1
42
93
  end
43
94
  end
44
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill-api-delivery-method
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pieter Jongsma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-14 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec