simple_postmark 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +3 -13
- data/CHANGELOG.md +7 -0
- data/README.md +13 -10
- data/Rakefile +1 -1
- data/gemfiles/Rails_4_0.gemfile +5 -0
- data/gemfiles/Rails_4_1.gemfile +5 -0
- data/lib/simple_postmark/version.rb +1 -1
- data/simple_postmark.gemspec +6 -5
- data/test/mail/message_test.rb +7 -0
- data/test/mail/part_test.rb +38 -0
- data/test/mail_test.rb +92 -0
- data/test/simple_postmark/api_test.rb +69 -0
- data/test/simple_postmark/integration_test.rb +91 -0
- data/test/simple_postmark_test.rb +31 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +5 -3
- data/test/test_mailer.rb +41 -0
- data/{spec → test}/thebrocode.jpg +0 -0
- metadata +88 -68
- data/gemfiles/Rails_master.gemfile +0 -12
- data/spec/delivery_method_spec.rb +0 -44
- data/spec/integration_spec.rb +0 -101
- data/spec/mail_ext/message_spec.rb +0 -103
- data/spec/mail_ext/part_spec.rb +0 -62
- data/spec/railtie_spec.rb +0 -118
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9de1ac47100b912b377ad14820d3b529b21c25a1
|
4
|
+
data.tar.gz: f7a59261a018c6089be91095f517067061fbcc9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35da1d86866675baaea4557c108804aac3fdc67cdf4cb299a920d8f47b58e6d1610cba82d8741bf296d413374a8daa194fecd1e0157506384ded67ffe173bc77
|
7
|
+
data.tar.gz: c06df2471facc7192a9156c49277a7a1193d4bc0288072182efd88cd28f0d344b886c6bbb9dd3df901be24db2a5b85d08def38b30b803c52308ce543dea2c83d
|
data/.travis.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 1.9.2
|
5
4
|
- 1.9.3
|
6
5
|
- 2.0.0
|
7
|
-
-
|
6
|
+
- 2.1.0
|
7
|
+
- 2.2.0
|
8
8
|
|
9
9
|
gemfile:
|
10
10
|
- Gemfile
|
@@ -12,18 +12,8 @@ gemfile:
|
|
12
12
|
- gemfiles/Rails_3_1.gemfile
|
13
13
|
- gemfiles/Rails_3_2.gemfile
|
14
14
|
- gemfiles/Rails_4_0.gemfile
|
15
|
-
- gemfiles/
|
15
|
+
- gemfiles/Rails_4_1.gemfile
|
16
16
|
|
17
17
|
branches:
|
18
18
|
only:
|
19
19
|
- master
|
20
|
-
|
21
|
-
matrix:
|
22
|
-
exclude:
|
23
|
-
- rvm: 1.9.2
|
24
|
-
gemfile: gemfiles/Rails_master.gemfile
|
25
|
-
- rvm: 1.9.2
|
26
|
-
gemfile: gemfiles/Rails_4_0.gemfile
|
27
|
-
allow_failures:
|
28
|
-
- rvm: ruby-head
|
29
|
-
- gemfile: gemfiles/Rails_master.gemfile
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,18 +2,21 @@
|
|
2
2
|
|
3
3
|
simple_postmark makes it easy to send mails via [Postmark](http://postmarkapp.com)™ using Rails's ActionMailer.
|
4
4
|
|
5
|
-
|
5
|
+
## Table of Contents
|
6
6
|
|
7
|
-
|
7
|
+
* [About](#about)
|
8
|
+
* [Installation](#installation)
|
9
|
+
* [Usage](#usage)
|
10
|
+
* [Configuration](#configuration)
|
11
|
+
* [Testing](#testing)
|
12
|
+
* [Contributing](#contributing)
|
13
|
+
* [Copyright](#copyright)
|
8
14
|
|
9
|
-
|
15
|
+
## About
|
10
16
|
|
11
|
-
|
17
|
+
simple_postmark was created because of the lack of the proper Rails API support in the official [postmark-gem](https://github.com/wildbit/postmark-gem). This was back in 2011, the postmark-gem was [updated](https://github.com/wildbit/postmark-rails/issues/17#issuecomment-13761405) to support the Rails API since then. I recently decided to deprecate this gem in favor of the official gem. However, this gem will continue to support all Rails versions until `5.0`.
|
12
18
|
|
13
|
-
Tested against Ruby
|
14
|
-
`ruby-head`, `2.0` and Rails `master` should work too btw.
|
15
|
-
|
16
|
-
If you are still using Ruby `1.8.7` or `Ruby Enterprise Edition` with Rails, you can use the backported version of this gem called [simple_postmark18](https://github.com/haihappen/simple_postmark/tree/ruby18).
|
19
|
+
Tested against Ruby version `>= 1.9.3` up to `=< 2.2.0` and Rails versions `~> 3.0.0` up to `~> 4.1.0`.
|
17
20
|
|
18
21
|
## Installation
|
19
22
|
|
@@ -60,7 +63,7 @@ class NotificationMailer < ActionMailer::Base
|
|
60
63
|
end
|
61
64
|
```
|
62
65
|
|
63
|
-
##
|
66
|
+
## Configuration
|
64
67
|
|
65
68
|
* `api_key`: Your Postmark API key. Go to [your Rack](https://postmarkapp.com/servers),
|
66
69
|
selected the one you want to use and then go to the **Credentials** tab to find your API key.
|
@@ -108,7 +111,7 @@ With this setup, it will actually trigger a connection to the Postmark API, but
|
|
108
111
|
|
109
112
|
(The MIT license)
|
110
113
|
|
111
|
-
Copyright (c) 2011-
|
114
|
+
Copyright (c) 2011-2015 Mario Uher
|
112
115
|
|
113
116
|
Permission is hereby granted, free of charge, to any person obtaining
|
114
117
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/simple_postmark.gemspec
CHANGED
@@ -6,19 +6,20 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.version = SimplePostmark::VERSION
|
7
7
|
gem.authors = 'Mario Uher'
|
8
8
|
gem.email = 'uher.mario@gmail.com'
|
9
|
-
gem.description = 'SimplePostmark makes it easy to send mails via Postmark
|
10
|
-
gem.summary = 'A simple way to use Postmark
|
9
|
+
gem.description = 'SimplePostmark makes it easy to send mails via Postmark using Rails\'s ActionMailer.'
|
10
|
+
gem.summary = 'A simple way to use Postmark with your Rails app.'
|
11
11
|
gem.homepage = 'http://haihappen.github.com/simple_postmark'
|
12
12
|
|
13
13
|
gem.files = `git ls-files`.split("\n")
|
14
14
|
gem.require_path = 'lib'
|
15
15
|
|
16
|
-
gem.add_dependency 'activesupport', '>= 3.0'
|
16
|
+
gem.add_dependency 'activesupport', '>= 3.0', '< 4.2.0'
|
17
|
+
gem.add_dependency 'actionmailer', '>= 3.0', '< 4.2.0'
|
17
18
|
gem.add_dependency 'httparty'
|
18
19
|
gem.add_dependency 'json'
|
19
20
|
gem.add_dependency 'mail'
|
20
21
|
|
21
|
-
gem.add_development_dependency 'minitest'
|
22
|
-
gem.add_development_dependency '
|
22
|
+
gem.add_development_dependency 'minitest', '>= 4.0', '< 5.0'
|
23
|
+
gem.add_development_dependency 'rake'
|
23
24
|
gem.add_development_dependency 'webmock'
|
24
25
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class Mail::PartTest < MiniTest::Unit::TestCase
|
4
|
+
def test_responds_to_to_postmark
|
5
|
+
assert_respond_to Mail::Part.new, :to_postmark
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def test_to_postmark_text_part
|
10
|
+
content = %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!}
|
11
|
+
|
12
|
+
part = Mail::Part.new
|
13
|
+
part.body = content
|
14
|
+
part.content_type = 'text/plain'
|
15
|
+
|
16
|
+
assert_equal Hash['Name' => nil, 'Content' => content, 'ContentType' => 'text/plain'], part.to_postmark
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def test_to_postmark_mail_part
|
21
|
+
content = %{<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>}
|
22
|
+
|
23
|
+
part = Mail::Part.new
|
24
|
+
part.body = content
|
25
|
+
part.content_type = 'text/html'
|
26
|
+
|
27
|
+
assert_equal Hash['Name' => nil, 'Content' => content, 'ContentType' => 'text/html'], part.to_postmark
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def test_to_postmark_file_part
|
32
|
+
part = Mail::Part.new
|
33
|
+
part.add_file BROCODE
|
34
|
+
attachment = part.attachments.first
|
35
|
+
|
36
|
+
assert_equal Hash['Name' => 'thebrocode.jpg', 'Content' => [File.read(BROCODE)].pack('m'), 'ContentType' => 'image/jpeg'], attachment.to_postmark
|
37
|
+
end
|
38
|
+
end
|
data/test/mail_test.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MailTest < MiniTest::Unit::TestCase
|
4
|
+
def test_responds_to_to_postmark
|
5
|
+
assert_respond_to Mail.new, :to_postmark
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def build_mail
|
10
|
+
Mail.new do
|
11
|
+
from 'barney@himym.tld'
|
12
|
+
to 'ted@himym.tld'
|
13
|
+
subject %{I'm your bro!}
|
14
|
+
body %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!}
|
15
|
+
tag 'simple-postmark'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def test_to_postmark_returns_a_hash
|
21
|
+
hash = {
|
22
|
+
'From' => 'barney@himym.tld',
|
23
|
+
'To' => 'ted@himym.tld',
|
24
|
+
'Subject' => %{I'm your bro!},
|
25
|
+
'TextBody' => %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!},
|
26
|
+
'Tag' => 'simple-postmark',
|
27
|
+
'Attachments' => [{
|
28
|
+
'Name' => 'thebrocode.jpg',
|
29
|
+
'Content' => [File.read(BROCODE)].pack('m'),
|
30
|
+
'ContentType' => 'image/jpeg'
|
31
|
+
}]
|
32
|
+
}
|
33
|
+
|
34
|
+
mail = build_mail
|
35
|
+
mail.add_file BROCODE
|
36
|
+
|
37
|
+
assert_equal hash, mail.to_postmark
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def test_multiple_recipients
|
42
|
+
mail = build_mail
|
43
|
+
mail.to = ['barney@himym.tld', 'marshall@himym.tld']
|
44
|
+
|
45
|
+
assert_equal 'barney@himym.tld, marshall@himym.tld', mail.to_postmark.fetch('To')
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def test_email_headers
|
50
|
+
hash = {
|
51
|
+
'Bcc' => 'lily@himym.tld',
|
52
|
+
'Cc' => 'marshall@himym.tld',
|
53
|
+
'From' => 'barney@himym.tld',
|
54
|
+
'ReplyTo' => 'barney@barneystinsonblog.com',
|
55
|
+
'Subject' => %{I'm your bro!},
|
56
|
+
'Tag' => 'simple-postmark',
|
57
|
+
'TextBody' => %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!},
|
58
|
+
'To' => 'ted@himym.tld'
|
59
|
+
}
|
60
|
+
|
61
|
+
mail = build_mail
|
62
|
+
mail.bcc = 'lily@himym.tld'
|
63
|
+
mail.cc = 'marshall@himym.tld'
|
64
|
+
mail.reply_to = 'barney@barneystinsonblog.com'
|
65
|
+
|
66
|
+
assert_equal hash, mail.to_postmark
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_from_and_reply_to
|
71
|
+
hash = {
|
72
|
+
'To' => 'Lily <lily@himym.tld>',
|
73
|
+
'From' => 'Marshall <marshall@himym.tld>',
|
74
|
+
'ReplyTo' => 'Barney <barney@barneystinsonblog.com>',
|
75
|
+
'Bcc' => 'lily@himym.tld',
|
76
|
+
'Cc' => 'marshall@himym.tld',
|
77
|
+
'Subject' => %{I'm your bro!},
|
78
|
+
'Tag' => 'simple-postmark',
|
79
|
+
'TextBody' => %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!},
|
80
|
+
}
|
81
|
+
|
82
|
+
mail = build_mail
|
83
|
+
mail.to = 'Lily <lily@himym.tld>'
|
84
|
+
mail.from = 'Marshall <marshall@himym.tld>'
|
85
|
+
mail.reply_to = 'Barney <barney@barneystinsonblog.com>'
|
86
|
+
mail.bcc = 'lily@himym.tld'
|
87
|
+
mail.cc = 'marshall@himym.tld'
|
88
|
+
|
89
|
+
assert_equal hash, mail.to_postmark
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class SimplePostmark::APITest < MiniTest::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
ActionMailer::Base.add_delivery_method :simple_postmark, Mail::SimplePostmark, api_key: nil
|
7
|
+
ActionMailer::Base.delivery_method = :simple_postmark
|
8
|
+
ActionMailer::Base.simple_postmark_settings = { api_key: 'POSTMARK_API_TEST', return_response: true }
|
9
|
+
ActionMailer::Base.raise_delivery_errors = true
|
10
|
+
|
11
|
+
load File.join(File.dirname(__FILE__), '../test_mailer.rb')
|
12
|
+
|
13
|
+
WebMock.disable!
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_send_email
|
18
|
+
TestMailer.email.deliver
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_send_email_with_tags
|
23
|
+
TestMailer.email_with_tags.deliver
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def test_send_email_with_attachments
|
28
|
+
TestMailer.email_with_attachments.deliver
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_send_email_with_reply_to
|
33
|
+
TestMailer.email_with_reply_to.deliver
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def test_fails_using_wrong_settings
|
38
|
+
ActionMailer::Base.simple_postmark_settings = { api_key: '********-****-****-****-************', return_response: true }
|
39
|
+
|
40
|
+
assert_raises SimplePostmark::APIError do
|
41
|
+
TestMailer.email.deliver
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def test_can_be_silent
|
47
|
+
ActionMailer::Base.simple_postmark_settings = { api_key: '********-****-****-****-************', return_response: true }
|
48
|
+
ActionMailer::Base.raise_delivery_errors = false
|
49
|
+
|
50
|
+
TestMailer.email.deliver
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_parsed_response
|
55
|
+
response = TestMailer.email.deliver!.parsed_response
|
56
|
+
|
57
|
+
assert_equal 'ted@himym.tld', response.fetch('To')
|
58
|
+
assert_equal 'Test job accepted', response.fetch('Message')
|
59
|
+
assert response.fetch('MessageID')
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
WebMock.enable!
|
65
|
+
|
66
|
+
ActionMailer::Base.delivery_method = :test
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class IntegrationTest < MiniTest::Unit::TestCase
|
5
|
+
URL = 'http://api.postmarkapp.com/email'
|
6
|
+
API_KEY = '********-****-****-****-************'
|
7
|
+
|
8
|
+
HEADERS = {
|
9
|
+
'Accept' => 'application/json',
|
10
|
+
'ContentType' => 'application/json',
|
11
|
+
'X-Postmark-Server-Token' => API_KEY
|
12
|
+
}
|
13
|
+
|
14
|
+
BODY = {
|
15
|
+
'From' => 'barney@himym.tld',
|
16
|
+
'Subject' => %{I'm your bro!},
|
17
|
+
'TextBody' => %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!},
|
18
|
+
'To' => 'ted@himym.tld'
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
def setup
|
23
|
+
ActionMailer::Base.add_delivery_method :simple_postmark, Mail::SimplePostmark, api_key: nil
|
24
|
+
ActionMailer::Base.delivery_method = :simple_postmark
|
25
|
+
ActionMailer::Base.simple_postmark_settings = { api_key: API_KEY, return_response: true }
|
26
|
+
ActionMailer::Base.raise_delivery_errors = true
|
27
|
+
|
28
|
+
WebMock.enable!
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_responds_to_simple_postmark_settings
|
33
|
+
assert_respond_to ActionMailer::Base, :simple_postmark_settings
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def test_set_api_key
|
38
|
+
assert_equal API_KEY, ActionMailer::Base.simple_postmark_settings.fetch(:api_key)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def test_send_email
|
43
|
+
stub_request :post, URL
|
44
|
+
TestMailer.email.deliver
|
45
|
+
|
46
|
+
assert_requested :post, URL, headers: HEADERS, body: BODY.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_send_email_with_tags
|
51
|
+
stub_request :post, URL
|
52
|
+
TestMailer.email_with_tags.deliver
|
53
|
+
|
54
|
+
assert_requested :post, URL, headers: HEADERS, body: Hash[BODY.merge('Tag' => 'simple-postmark').sort].to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_send_email_with_attachments
|
59
|
+
attachment = {
|
60
|
+
'Content' => [BROCODE].pack('m'),
|
61
|
+
'ContentType' => 'image/jpeg',
|
62
|
+
'Name' => 'thebrocode.jpg'
|
63
|
+
}
|
64
|
+
|
65
|
+
stub_request :post, URL
|
66
|
+
TestMailer.email_with_attachments.deliver
|
67
|
+
|
68
|
+
assert_requested :post, URL, headers: HEADERS, body: Hash[BODY.merge('Subject' => %{The Brocode!}, 'Attachments' => [attachment]).sort].to_json
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def test_send_email_with_multipart
|
73
|
+
multipart = {
|
74
|
+
'HtmlBody' => %{<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>},
|
75
|
+
'TextBody' => %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!}
|
76
|
+
}
|
77
|
+
|
78
|
+
stub_request :post, URL
|
79
|
+
TestMailer.email_with_multipart.deliver
|
80
|
+
|
81
|
+
assert_requested :post, URL, headers: HEADERS, body: Hash[BODY.merge(multipart).sort].to_json
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def teardown
|
86
|
+
ActionMailer::Base.delivery_method = :test
|
87
|
+
|
88
|
+
WebMock.disable!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class SimplePostmarkTest < MiniTest::Unit::TestCase
|
4
|
+
def test_responds_to_deliver!
|
5
|
+
assert_respond_to Mail::SimplePostmark.new, :deliver!
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def test_makes_request
|
10
|
+
WebMock.enable!
|
11
|
+
|
12
|
+
url = 'http://api.postmarkapp.com/email'
|
13
|
+
|
14
|
+
mail = Mail.new do
|
15
|
+
from 'barney@himym.tld'
|
16
|
+
to 'ted@himym.tld'
|
17
|
+
subject %{I'm your bro!}
|
18
|
+
body %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!}
|
19
|
+
tag 'simple-postmark'
|
20
|
+
add_file BROCODE
|
21
|
+
end
|
22
|
+
|
23
|
+
mail.delivery_method Mail::SimplePostmark
|
24
|
+
stub_request :post, url
|
25
|
+
mail.deliver
|
26
|
+
|
27
|
+
assert_requested :post, url, headers: { 'Accept' => 'application/json', 'ContentType' => 'application/json', 'X-Postmark-Server-Token' => '' }
|
28
|
+
|
29
|
+
WebMock.disable!
|
30
|
+
end
|
31
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
$: << File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
2
|
require 'minitest/autorun'
|
4
3
|
require 'minitest/pride'
|
5
|
-
require 'minitest
|
4
|
+
require 'webmock/minitest'
|
6
5
|
|
6
|
+
require 'action_mailer'
|
7
7
|
require 'simple_postmark'
|
8
8
|
|
9
|
-
|
9
|
+
require_relative 'test_mailer'
|
10
|
+
|
11
|
+
BROCODE = File.join(File.dirname(__FILE__), 'thebrocode.jpg')
|
data/test/test_mailer.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class TestMailer < ActionMailer::Base
|
2
|
+
default from: 'barney@himym.tld', to: 'ted@himym.tld'
|
3
|
+
|
4
|
+
def text
|
5
|
+
%{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!}
|
6
|
+
end
|
7
|
+
|
8
|
+
def email
|
9
|
+
mail subject: %{I'm your bro!} do |as|
|
10
|
+
as.text { render text: text }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def email_with_tags
|
15
|
+
mail subject: %{I'm your bro!}, tag: 'simple-postmark' do |as|
|
16
|
+
as.text { render text: text }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def email_with_attachments
|
21
|
+
attachments['thebrocode.jpg'] = BROCODE
|
22
|
+
|
23
|
+
mail subject: %{The Brocode!} do |as|
|
24
|
+
as.text { render text: text }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def email_with_reply_to
|
29
|
+
mail subject: %{I'm your bro!}, reply_to: 'barney@barneystinsonblog.com' do |as|
|
30
|
+
as.text { render text: text }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def email_with_multipart
|
36
|
+
mail subject: %{I'm your bro!} do |as|
|
37
|
+
as.text { render text: %{Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!} }
|
38
|
+
as.html { render text: %{<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>} }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,137 +1,154 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_postmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.6.0
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mario Uher
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.2.0
|
23
|
+
type: :runtime
|
15
24
|
prerelease: false
|
16
25
|
version_requirements: !ruby/object:Gem::Requirement
|
17
26
|
requirements:
|
18
|
-
- -
|
27
|
+
- - ">="
|
19
28
|
- !ruby/object:Gem::Version
|
20
29
|
version: '3.0'
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: actionmailer
|
24
35
|
requirement: !ruby/object:Gem::Requirement
|
25
36
|
requirements:
|
26
|
-
- -
|
37
|
+
- - ">="
|
27
38
|
- !ruby/object:Gem::Version
|
28
39
|
version: '3.0'
|
29
|
-
|
30
|
-
- !ruby/object:Gem::
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 4.2.0
|
43
|
+
type: :runtime
|
31
44
|
prerelease: false
|
32
45
|
version_requirements: !ruby/object:Gem::Requirement
|
33
46
|
requirements:
|
34
|
-
- -
|
47
|
+
- - ">="
|
35
48
|
- !ruby/object:Gem::Version
|
36
|
-
version: '0'
|
37
|
-
|
38
|
-
|
49
|
+
version: '3.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 4.2.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
39
54
|
name: httparty
|
40
55
|
requirement: !ruby/object:Gem::Requirement
|
41
56
|
requirements:
|
42
|
-
- -
|
57
|
+
- - ">="
|
43
58
|
- !ruby/object:Gem::Version
|
44
59
|
version: '0'
|
45
|
-
|
46
|
-
- !ruby/object:Gem::Dependency
|
60
|
+
type: :runtime
|
47
61
|
prerelease: false
|
48
62
|
version_requirements: !ruby/object:Gem::Requirement
|
49
63
|
requirements:
|
50
|
-
- -
|
64
|
+
- - ">="
|
51
65
|
- !ruby/object:Gem::Version
|
52
66
|
version: '0'
|
53
|
-
|
54
|
-
type: :runtime
|
67
|
+
- !ruby/object:Gem::Dependency
|
55
68
|
name: json
|
56
69
|
requirement: !ruby/object:Gem::Requirement
|
57
70
|
requirements:
|
58
|
-
- -
|
71
|
+
- - ">="
|
59
72
|
- !ruby/object:Gem::Version
|
60
73
|
version: '0'
|
61
|
-
|
62
|
-
- !ruby/object:Gem::Dependency
|
74
|
+
type: :runtime
|
63
75
|
prerelease: false
|
64
76
|
version_requirements: !ruby/object:Gem::Requirement
|
65
77
|
requirements:
|
66
|
-
- -
|
78
|
+
- - ">="
|
67
79
|
- !ruby/object:Gem::Version
|
68
80
|
version: '0'
|
69
|
-
|
70
|
-
type: :runtime
|
81
|
+
- !ruby/object:Gem::Dependency
|
71
82
|
name: mail
|
72
83
|
requirement: !ruby/object:Gem::Requirement
|
73
84
|
requirements:
|
74
|
-
- -
|
85
|
+
- - ">="
|
75
86
|
- !ruby/object:Gem::Version
|
76
87
|
version: '0'
|
77
|
-
|
78
|
-
- !ruby/object:Gem::Dependency
|
88
|
+
type: :runtime
|
79
89
|
prerelease: false
|
80
90
|
version_requirements: !ruby/object:Gem::Requirement
|
81
91
|
requirements:
|
82
|
-
- -
|
92
|
+
- - ">="
|
83
93
|
- !ruby/object:Gem::Version
|
84
94
|
version: '0'
|
85
|
-
|
86
|
-
type: :development
|
95
|
+
- !ruby/object:Gem::Dependency
|
87
96
|
name: minitest
|
88
97
|
requirement: !ruby/object:Gem::Requirement
|
89
98
|
requirements:
|
90
|
-
- -
|
99
|
+
- - ">="
|
91
100
|
- !ruby/object:Gem::Version
|
92
|
-
version: '0'
|
93
|
-
|
94
|
-
- !ruby/object:Gem::
|
101
|
+
version: '4.0'
|
102
|
+
- - "<"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5.0'
|
105
|
+
type: :development
|
95
106
|
prerelease: false
|
96
107
|
version_requirements: !ruby/object:Gem::Requirement
|
97
108
|
requirements:
|
98
|
-
- -
|
109
|
+
- - ">="
|
99
110
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
version: '4.0'
|
112
|
+
- - "<"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '5.0'
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rake
|
104
117
|
requirement: !ruby/object:Gem::Requirement
|
105
118
|
requirements:
|
106
|
-
- -
|
119
|
+
- - ">="
|
107
120
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
109
|
-
|
110
|
-
- !ruby/object:Gem::Dependency
|
121
|
+
version: '0'
|
122
|
+
type: :development
|
111
123
|
prerelease: false
|
112
124
|
version_requirements: !ruby/object:Gem::Requirement
|
113
125
|
requirements:
|
114
|
-
- -
|
126
|
+
- - ">="
|
115
127
|
- !ruby/object:Gem::Version
|
116
128
|
version: '0'
|
117
|
-
|
118
|
-
type: :development
|
129
|
+
- !ruby/object:Gem::Dependency
|
119
130
|
name: webmock
|
120
131
|
requirement: !ruby/object:Gem::Requirement
|
121
132
|
requirements:
|
122
|
-
- -
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
type: :development
|
137
|
+
prerelease: false
|
138
|
+
version_requirements: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
123
141
|
- !ruby/object:Gem::Version
|
124
142
|
version: '0'
|
125
|
-
|
126
|
-
description: SimplePostmark makes it easy to send mails via Postmark™ using Rails's
|
143
|
+
description: SimplePostmark makes it easy to send mails via Postmark using Rails's
|
127
144
|
ActionMailer.
|
128
145
|
email: uher.mario@gmail.com
|
129
146
|
executables: []
|
130
147
|
extensions: []
|
131
148
|
extra_rdoc_files: []
|
132
149
|
files:
|
133
|
-
- .gitignore
|
134
|
-
- .travis.yml
|
150
|
+
- ".gitignore"
|
151
|
+
- ".travis.yml"
|
135
152
|
- CHANGELOG.md
|
136
153
|
- Gemfile
|
137
154
|
- README.md
|
@@ -139,7 +156,8 @@ files:
|
|
139
156
|
- gemfiles/Rails_3_0.gemfile
|
140
157
|
- gemfiles/Rails_3_1.gemfile
|
141
158
|
- gemfiles/Rails_3_2.gemfile
|
142
|
-
- gemfiles/
|
159
|
+
- gemfiles/Rails_4_0.gemfile
|
160
|
+
- gemfiles/Rails_4_1.gemfile
|
143
161
|
- lib/simple_postmark.rb
|
144
162
|
- lib/simple_postmark/api_error.rb
|
145
163
|
- lib/simple_postmark/delivery_method.rb
|
@@ -148,35 +166,37 @@ files:
|
|
148
166
|
- lib/simple_postmark/railtie.rb
|
149
167
|
- lib/simple_postmark/version.rb
|
150
168
|
- simple_postmark.gemspec
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
169
|
+
- test/mail/message_test.rb
|
170
|
+
- test/mail/part_test.rb
|
171
|
+
- test/mail_test.rb
|
172
|
+
- test/simple_postmark/api_test.rb
|
173
|
+
- test/simple_postmark/integration_test.rb
|
174
|
+
- test/simple_postmark_test.rb
|
175
|
+
- test/test_helper.rb
|
176
|
+
- test/test_mailer.rb
|
177
|
+
- test/thebrocode.jpg
|
158
178
|
homepage: http://haihappen.github.com/simple_postmark
|
159
179
|
licenses: []
|
180
|
+
metadata: {}
|
160
181
|
post_install_message:
|
161
182
|
rdoc_options: []
|
162
183
|
require_paths:
|
163
184
|
- lib
|
164
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
165
186
|
requirements:
|
166
|
-
- -
|
187
|
+
- - ">="
|
167
188
|
- !ruby/object:Gem::Version
|
168
189
|
version: '0'
|
169
|
-
none: false
|
170
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
191
|
requirements:
|
172
|
-
- -
|
192
|
+
- - ">="
|
173
193
|
- !ruby/object:Gem::Version
|
174
194
|
version: '0'
|
175
|
-
none: false
|
176
195
|
requirements: []
|
177
196
|
rubyforge_project:
|
178
|
-
rubygems_version:
|
197
|
+
rubygems_version: 2.2.2
|
179
198
|
signing_key:
|
180
|
-
specification_version:
|
181
|
-
summary: A simple way to use Postmark
|
199
|
+
specification_version: 4
|
200
|
+
summary: A simple way to use Postmark with your Rails app.
|
182
201
|
test_files: []
|
202
|
+
has_rdoc:
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe Mail do
|
4
|
-
describe SimplePostmark do
|
5
|
-
let(:instance) { Mail::SimplePostmark.new }
|
6
|
-
|
7
|
-
|
8
|
-
it 'responds to deliver!' do
|
9
|
-
instance.must_respond_to(:deliver!)
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
describe :deliver! do
|
14
|
-
let(:mail) do
|
15
|
-
Mail.new do
|
16
|
-
from 'barney@himym.tld'
|
17
|
-
to 'ted@himym.tld'
|
18
|
-
subject "I'm your bro!"
|
19
|
-
body "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!"
|
20
|
-
tag 'simple-postmark'
|
21
|
-
add_file(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
let(:url) { 'http://api.postmarkapp.com/email' }
|
25
|
-
|
26
|
-
|
27
|
-
before do
|
28
|
-
mail.delivery_method(Mail::SimplePostmark)
|
29
|
-
stub_request(:post, url)
|
30
|
-
mail.deliver
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
it 'sends emails' do
|
35
|
-
assert_requested(:post, url)
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
it 'sends appropriate headers' do
|
40
|
-
assert_requested(:post, url, headers: { 'Accept' => 'application/json', 'ContentType' => 'application/json', 'X-Postmark-Server-Token' => '' })
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/spec/integration_spec.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require 'action_mailer'
|
3
|
-
require 'rails'
|
4
|
-
require 'simple_postmark/railtie'
|
5
|
-
|
6
|
-
WebMock.allow_net_connect!
|
7
|
-
|
8
|
-
class IntegrationMailer < ActionMailer::Base
|
9
|
-
default from: 'barney@himym.tld', to: 'ted@himym.tld'
|
10
|
-
|
11
|
-
def text
|
12
|
-
'Mail send via Postmark using SimplePostmark'
|
13
|
-
end
|
14
|
-
|
15
|
-
def email
|
16
|
-
mail(subject: 'SimplePostmark') do |as|
|
17
|
-
as.text { render(text: text) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def email_with_tags
|
22
|
-
mail(subject: 'SimplePostmark with Tags', tag: 'simple-postmark') do |as|
|
23
|
-
as.text { render(text: text) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def email_with_attachments
|
28
|
-
attachments['thebrocode.jpg'] = File.read(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))
|
29
|
-
|
30
|
-
mail(subject: 'SimplePostmark with Attachments') do |as|
|
31
|
-
as.text { render(text: text) }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def email_with_reply_to
|
36
|
-
mail(subject: 'SimplePostmark with Reply To', reply_to: 'barney@barneystinsonblog.com') do |as|
|
37
|
-
as.text { render(text: text) }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'SimplePostmark integration' do
|
43
|
-
before do
|
44
|
-
ActionMailer::Base.simple_postmark_settings = { api_key: 'POSTMARK_API_TEST', return_response: true }
|
45
|
-
ActionMailer::Base.raise_delivery_errors = true
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
it 'sends emails' do
|
50
|
-
IntegrationMailer.email.deliver
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
it 'sends emails with tags' do
|
55
|
-
IntegrationMailer.email_with_tags.deliver
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
it 'sends emails with attachments' do
|
60
|
-
IntegrationMailer.email_with_attachments.deliver
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
it 'sends emails with reply-to' do
|
65
|
-
IntegrationMailer.email_with_reply_to.deliver
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
describe 'wrong mail settings' do
|
70
|
-
before do
|
71
|
-
ActionMailer::Base.simple_postmark_settings = { api_key: '********-****-****-****-************' }
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
it 'is silent if raise_delivery_errors is not set' do
|
76
|
-
ActionMailer::Base.raise_delivery_errors = false
|
77
|
-
|
78
|
-
IntegrationMailer.email.deliver
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
it 'raises a SimplePostmark::APIError containing the error from postmarkapp.com if raise_delivery_errors is set' do
|
83
|
-
->{ IntegrationMailer.email.deliver }.must_raise(SimplePostmark::APIError)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
describe 'setting return_response option' do
|
89
|
-
before do
|
90
|
-
ActionMailer::Base.simple_postmark_settings = { api_key: 'POSTMARK_API_TEST', return_response: true }
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'returns the response from postmarkapp.com' do
|
94
|
-
response = IntegrationMailer.email.deliver!.parsed_response
|
95
|
-
|
96
|
-
response['To'].must_equal('ted@himym.tld')
|
97
|
-
response['Message'].must_equal('Test job accepted')
|
98
|
-
response['MessageID'].wont_be_empty
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe Mail::Message do
|
4
|
-
describe 'integration into Mail::Message' do
|
5
|
-
subject { Mail::Message.new }
|
6
|
-
|
7
|
-
|
8
|
-
it 'responds to +to_postmark+' do
|
9
|
-
subject.must_respond_to(:to_postmark)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
describe 'integration into Mail' do
|
15
|
-
subject { Mail.new }
|
16
|
-
|
17
|
-
|
18
|
-
it 'responds to +to_postmark+' do
|
19
|
-
subject.must_respond_to(:to_postmark)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
describe :to_postmark do
|
25
|
-
subject do
|
26
|
-
Mail.new do
|
27
|
-
from 'barney@himym.tld'
|
28
|
-
to 'ted@himym.tld'
|
29
|
-
subject "I'm your bro!"
|
30
|
-
body "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!"
|
31
|
-
tag 'simple-postmark'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
it 'returns a hash' do
|
37
|
-
hash = {
|
38
|
-
'From' => 'barney@himym.tld',
|
39
|
-
'To' => 'ted@himym.tld',
|
40
|
-
'Subject' => "I'm your bro!",
|
41
|
-
'TextBody' => "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!",
|
42
|
-
'Tag' => 'simple-postmark',
|
43
|
-
'Attachments' => [{
|
44
|
-
'Name' => 'thebrocode.jpg',
|
45
|
-
'Content' => [File.read(File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg'))].pack('m'),
|
46
|
-
'ContentType' => 'image/jpeg'
|
47
|
-
}]
|
48
|
-
}
|
49
|
-
subject.add_file(File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg'))
|
50
|
-
|
51
|
-
subject.to_postmark.must_equal(hash)
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
it 'returns multiple recipients as comma-separated list' do
|
56
|
-
subject.to = ['barney@himym.tld', 'marshall@himym.tld']
|
57
|
-
|
58
|
-
subject.to_postmark['To'].must_equal('barney@himym.tld, marshall@himym.tld')
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
it 'returns all email headers as hash' do
|
63
|
-
subject.bcc = 'lily@himym.tld'
|
64
|
-
subject.cc = 'marshall@himym.tld'
|
65
|
-
subject.reply_to = 'barney@barneystinsonblog.com'
|
66
|
-
|
67
|
-
hash = {
|
68
|
-
'Bcc' => 'lily@himym.tld',
|
69
|
-
'Cc' => 'marshall@himym.tld',
|
70
|
-
'From' => 'barney@himym.tld',
|
71
|
-
'ReplyTo' => 'barney@barneystinsonblog.com',
|
72
|
-
'Subject' => "I'm your bro!",
|
73
|
-
'Tag' => 'simple-postmark',
|
74
|
-
'TextBody' => "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!",
|
75
|
-
'To' => 'ted@himym.tld'
|
76
|
-
}
|
77
|
-
|
78
|
-
subject.to_postmark.must_equal(hash)
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
it 'should use the from and reply-to names as well as the email addresses' do
|
83
|
-
subject.to = 'Lily <lily@himym.tld>'
|
84
|
-
subject.from = 'Marshall <marshall@himym.tld>'
|
85
|
-
subject.reply_to = 'Barney <barney@barneystinsonblog.com>'
|
86
|
-
subject.bcc = 'lily@himym.tld'
|
87
|
-
subject.cc = 'marshall@himym.tld'
|
88
|
-
|
89
|
-
hash = {
|
90
|
-
'To' => 'Lily <lily@himym.tld>',
|
91
|
-
'From' => 'Marshall <marshall@himym.tld>',
|
92
|
-
'ReplyTo' => 'Barney <barney@barneystinsonblog.com>',
|
93
|
-
'Bcc' => 'lily@himym.tld',
|
94
|
-
'Cc' => 'marshall@himym.tld',
|
95
|
-
'Subject' => "I'm your bro!",
|
96
|
-
'Tag' => 'simple-postmark',
|
97
|
-
'TextBody' => "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!",
|
98
|
-
}
|
99
|
-
|
100
|
-
subject.to_postmark.must_equal(hash)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/spec/mail_ext/part_spec.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe 'Mail::Part' do
|
4
|
-
describe 'integration into Mail::Part' do
|
5
|
-
subject { Mail::Part.new }
|
6
|
-
|
7
|
-
|
8
|
-
it 'responds to +to_postmark+' do
|
9
|
-
subject.must_respond_to(:to_postmark)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
describe :to_postmark do
|
15
|
-
describe 'a text/plain part' do
|
16
|
-
let(:content) { "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!" }
|
17
|
-
subject do
|
18
|
-
Mail::Part.new.tap do |mail|
|
19
|
-
mail.body = content
|
20
|
-
mail.content_type = 'text/plain'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
it 'returns body hash' do
|
26
|
-
subject.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/plain')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
describe 'a text/html part' do
|
32
|
-
let(:content) { "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>" }
|
33
|
-
subject do
|
34
|
-
Mail::Part.new.tap do |mail|
|
35
|
-
mail.body = content
|
36
|
-
mail.content_type = 'text/html'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
it 'returns body hash' do
|
42
|
-
subject.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/html')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
describe 'a file part' do
|
48
|
-
let(:file) { File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg') }
|
49
|
-
let(:content) { [File.read(file)].pack('m') }
|
50
|
-
subject do
|
51
|
-
Mail::Part.new.tap do |mail|
|
52
|
-
mail.add_file(file)
|
53
|
-
end.attachments.first
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
it 'returns base64-encoded file-content hash if part is an attachment' do
|
58
|
-
subject.to_postmark.must_equal('Name' => 'thebrocode.jpg', 'Content' => content, 'ContentType' => 'image/jpeg')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/spec/railtie_spec.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require 'action_mailer'
|
3
|
-
require 'rails'
|
4
|
-
require 'simple_postmark/railtie'
|
5
|
-
|
6
|
-
ActionMailer::Base.delivery_method = :simple_postmark
|
7
|
-
|
8
|
-
class NotificationMailer < ActionMailer::Base
|
9
|
-
default from: 'barney@himym.tld', to: 'ted@himym.tld'
|
10
|
-
|
11
|
-
def im_your_bro
|
12
|
-
mail(subject: "I'm your bro!", body: '')
|
13
|
-
end
|
14
|
-
|
15
|
-
def im_your_bro_tagged
|
16
|
-
mail(subject: "I'm your bro!", tag: 'simple-postmark', body: '')
|
17
|
-
end
|
18
|
-
|
19
|
-
def im_your_bro_multipart
|
20
|
-
mail(subject: "I'm your bro!") do |as|
|
21
|
-
as.html { render(text: "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>" )}
|
22
|
-
as.text { render(text: "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!" )}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def the_bro_code
|
27
|
-
attachments['thebrocode.jpg'] = File.read(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))
|
28
|
-
mail(subject: 'The Brocode!', body: '')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def merge_body(hash = {})
|
33
|
-
Hash[*body.merge(hash).sort.flatten(1)].to_json
|
34
|
-
end
|
35
|
-
|
36
|
-
describe ActionMailer::Base do
|
37
|
-
let(:url) { 'http://api.postmarkapp.com/email' }
|
38
|
-
let(:api_key) { '********-****-****-****-************' }
|
39
|
-
|
40
|
-
let(:headers) do
|
41
|
-
{
|
42
|
-
'Accept' => 'application/json',
|
43
|
-
'ContentType' => 'application/json',
|
44
|
-
'X-Postmark-Server-Token' => api_key
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:body) do
|
49
|
-
{
|
50
|
-
'From' => 'barney@himym.tld',
|
51
|
-
'Subject' => "I'm your bro!",
|
52
|
-
'To' => 'ted@himym.tld'
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
before do
|
58
|
-
stub_request(:post, url)
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
it 'responds to +simple_postmark_settings+' do
|
63
|
-
ActionMailer::Base.must_respond_to(:simple_postmark_settings)
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
it 'allows setting an api key' do
|
68
|
-
ActionMailer::Base.simple_postmark_settings = { api_key: api_key }
|
69
|
-
|
70
|
-
ActionMailer::Base.simple_postmark_settings[:api_key].must_equal(api_key)
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
describe 'sending mails' do
|
75
|
-
before do
|
76
|
-
ActionMailer::Base.simple_postmark_settings = { api_key: api_key }
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
it 'works' do
|
81
|
-
NotificationMailer.im_your_bro.deliver
|
82
|
-
|
83
|
-
assert_requested(:post, url, headers: headers, body: merge_body)
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
it 'allows tags' do
|
88
|
-
NotificationMailer.im_your_bro_tagged.deliver
|
89
|
-
|
90
|
-
assert_requested(:post, url, headers: headers, body: merge_body('Tag' => 'simple-postmark'))
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
it 'works with attachments' do
|
95
|
-
attachment = {
|
96
|
-
'Content' => [File.read(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))].pack('m'),
|
97
|
-
'ContentType' => 'image/jpeg',
|
98
|
-
'Name' => 'thebrocode.jpg'
|
99
|
-
}
|
100
|
-
|
101
|
-
NotificationMailer.the_bro_code.deliver
|
102
|
-
|
103
|
-
assert_requested(:post, url, headers: headers, body: merge_body('Subject' => 'The Brocode!', 'Attachments' => [attachment]))
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
it 'works with multipart messages' do
|
108
|
-
bodies = {
|
109
|
-
'HtmlBody' => "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>",
|
110
|
-
'TextBody' => "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!"
|
111
|
-
}
|
112
|
-
|
113
|
-
NotificationMailer.im_your_bro_multipart.deliver
|
114
|
-
|
115
|
-
assert_requested(:post, url, headers: headers, body: merge_body(bodies))
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|