postmark-rails 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 938744b498ee1426bb86994d63c17bae10d7486a
4
- data.tar.gz: fd2b297c276a09b55edc281032064c4c98d6738e
3
+ metadata.gz: f2df5ed989cb277bb16b071ca354702e6b99f87d
4
+ data.tar.gz: 14347b26486e2dfd1be2da601904fc4614f641dd
5
5
  SHA512:
6
- metadata.gz: 682b017c3514da84c9ae3611d42c72d6daf48e394ac7fa160cab502d03607a656f0214fa43791b230f6a1b73e916df5bd69a4e537483fbc768f788b9fc5f8b61
7
- data.tar.gz: 3f0882c98e6c84ff7737bbcb7586df5952c4bab5ad5dbf7fc92139c394706c991e4360718b5952ed75f706372380c38138b40ec7117b488225ebe3e91f6d6c93
6
+ metadata.gz: 65cd3fb9c9044c5fe718683f2ddcfae18965d65a7412d7edd894ef5e12755b64624b6fa64550a15302f18d30e12240773c7ddbbb4b0a618980df4568168066ed
7
+ data.tar.gz: 323747a71a0331865a32b9200817b101e94b13e89d8a534fcc4697ad0488db0f5c384f457bfc75b4e7adae6701370bff58a1624634a3a9890a5e361cbbaaf90a
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ pkg
8
8
  .rvmrc
9
9
  Gemfile.lock
10
10
  gemfiles/*.lock
11
+ **/*.idea
@@ -3,8 +3,12 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.9
7
- - 2.2.5
6
+ - 2.1.10
7
+ - 2.2.10
8
+ - 2.3.8
9
+ - 2.4.5
10
+ - 2.5.3
11
+ - 2.6.0
8
12
  script: bundle exec rake spec
9
13
  gemfile:
10
14
  - Gemfile
@@ -13,22 +17,58 @@ gemfile:
13
17
  - gemfiles/Gemfile.actionmailer-4.0.x
14
18
  - gemfiles/Gemfile.actionmailer-4.1.x
15
19
  - gemfiles/Gemfile.actionmailer-4.2.x
20
+ - gemfiles/Gemfile.actionmailer-5.0.x
21
+ - gemfiles/Gemfile.actionmailer-5.1.x
16
22
  matrix:
17
23
  exclude:
18
24
  - rvm: 1.8.7
19
25
  gemfile: Gemfile
26
+ - rvm: 1.8.7
27
+ gemfile: gemfiles/Gemfile.actionmailer-4.0.x
28
+ - rvm: 1.8.7
29
+ gemfile: gemfiles/Gemfile.actionmailer-4.1.x
30
+ - rvm: 1.8.7
31
+ gemfile: gemfiles/Gemfile.actionmailer-4.2.x
32
+ - rvm: 1.8.7
33
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
34
+ - rvm: 1.8.7
35
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
36
+
20
37
  - rvm: 1.9.3
21
38
  gemfile: Gemfile
39
+ - rvm: 1.9.3
40
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
41
+ - rvm: 1.9.3
42
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
43
+
22
44
  - rvm: 2.0.0
23
45
  gemfile: Gemfile
24
- - rvm: 2.1.9
46
+ - rvm: 2.0.0
47
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
48
+ - rvm: 2.0.0
49
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
50
+
51
+ - rvm: 2.1.10
25
52
  gemfile: Gemfile
26
- - rvm: 1.8.7
53
+ - rvm: 2.1.10
54
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
55
+ - rvm: 2.1.10
56
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
57
+
58
+ - rvm: 2.5.3
59
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
60
+ - rvm: 2.5.3
61
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
62
+
63
+ - rvm: 2.6.0
64
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
65
+ - rvm: 2.6.0
66
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
67
+ - rvm: 2.6.0
27
68
  gemfile: gemfiles/Gemfile.actionmailer-4.0.x
28
- - rvm: 1.8.7
69
+ - rvm: 2.6.0
29
70
  gemfile: gemfiles/Gemfile.actionmailer-4.1.x
30
- - rvm: 1.8.7
71
+ - rvm: 2.6.0
31
72
  gemfile: gemfiles/Gemfile.actionmailer-4.2.x
32
73
  before_install:
33
- - gem update --system
34
- - gem install bundler
74
+ - .travis/setup.sh
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ set -eax
4
+
5
+ echo "Configuring Ruby and Bundler..."
6
+ echo "TRAVIS_RUBY_VERSION=${TRAVIS_RUBY_VERSION}"
7
+
8
+ if [[ "$TRAVIS_RUBY_VERSION" < "2.3" ]];
9
+ then
10
+ gem install bundler -v '< 2'
11
+ else
12
+ gem update --system
13
+ gem install bundler
14
+ fi
@@ -1,5 +1,12 @@
1
1
  = Changelog
2
2
 
3
+ == 0.19.0
4
+
5
+ * Update the postmark gem dependency to 1.15.x.
6
+ * Added support for templated mailers.
7
+ * Added source_code_uri to the gemspec.
8
+ * Tested against all stable versions of ActionMailer 3.0-5.2 and Ruby 1.8.7-2.6.0.
9
+
3
10
  == 0.18.0
4
11
 
5
12
  * Update the postmark gem dependency to 1.14.x.
@@ -0,0 +1,18 @@
1
+ # Before you report an issue or submit a pull request
2
+
3
+ *If you are blocked or need help with Postmark, please [contact
4
+ Postmark Support](https://postmarkapp.com/contact)*. For other, non-urgent
5
+ cases you’re welcome to report a bug and/or contribute to this project. We will
6
+ make our best effort to review your contributions and triage any bug reports in
7
+ a timely fashion.
8
+
9
+ If you’d like to submit a pull request:
10
+
11
+ * Fork the project.
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is important to prevent future regressions.
14
+ * Do not mess with rakefile, version, or history.
15
+ * Update the CHANGELOG, list your changes under Unreleased.
16
+ * Update the README if necessary.
17
+ * Write short, descriptive commit messages, following the format used in therepo.
18
+ * Send a pull request. Bonus points for topic branches.
data/README.md CHANGED
@@ -1,18 +1,41 @@
1
- # postmark-rails gem
1
+ <a href="https://postmarkapp.com">
2
+ <img src="postmark.png" alt="Postmark Logo" title="Postmark" width="120" height="120" align="right">
3
+ </a>
4
+
5
+ # Postmark Rails Gem
2
6
 
3
7
  [![Build Status](https://travis-ci.org/wildbit/postmark-rails.svg?branch=master)](https://travis-ci.org/wildbit/postmark-rails) [![Code Climate](https://codeclimate.com/github/wildbit/postmark-rails/badges/gpa.svg)](https://codeclimate.com/github/wildbit/postmark-rails)
8
+ [![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://www.opensource.org/licenses/MIT)
9
+ [![Gem Version](https://badge.fury.io/rb/postmark-rails.svg)](https://badge.fury.io/rb/postmark-rails)
10
+
11
+ [Postmark](https://postmarkapp.com) allows you to send your emails with high delivery rates.
12
+ It also includes detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.
13
+
14
+ The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via [Postmark](https://postmarkapp.com).
15
+ The gem has been created for fast implementation and fully supports all of [Postmark’s features](https://postmarkapp.com/why).
16
+
17
+ ## Usage
18
+
19
+ Please see the [wiki](https://github.com/wildbit/postmark-rails/wiki) for detailed instructions about library features.
20
+ For details about Postmark API in general, please check out [Postmark developer docs](https://postmarkapp.com/developer).
21
+
22
+ ## Requirements
23
+
24
+ You will need a Postmark account, server and sender signature (or verified domain) set up to use it.
25
+ For details about setup, check out [wiki pages](https://github.com/wildbit/postmark-rails/wiki/Getting-Started).
4
26
 
5
- The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via [Postmark](https://postmarkapp.com), an email delivery service for web apps. The gem has been created for fast implementation and fully supports all of [Postmark’s features](https://postmarkapp.com/why).
27
+ Also you will need a [postmark gem](https://github.com/wildbit/postmark-gem) version 1.0 and higher is required.
6
28
 
7
- ## Supported Rails Versions
29
+ ### Supported Rails Versions
8
30
 
9
31
  * Rails 5.0
10
32
  * Rails 4.x
11
33
  * Rails 3.x
12
34
 
13
- For Rails 2.3 please take a look at [version 0.4](https://github.com/wildbit/postmark-rails/tree/v0.4.2). It may miss some new features, but receives all required bug fixes and other support if needed.
35
+ For Rails 2.3 please take a look at [version 0.4](https://github.com/wildbit/postmark-rails/tree/v0.4.2).
36
+ It may miss some new features, but receives all required bug fixes and other support if needed.
14
37
 
15
- ## Configuring your Rails application
38
+ ## Installation
16
39
 
17
40
  Add `postmark-rails` to your Gemfile and run `bundle install`.
18
41
 
@@ -35,206 +58,15 @@ config.action_mailer.postmark_settings = { :api_token => Rails.application.secre
35
58
 
36
59
  **Note**: The `postmark_settings` hash can contain [any options](https://github.com/wildbit/postmark-gem#communicating-with-the-api) supported by `Postmark::ApiClient`.
37
60
 
38
- ## Tracking opens and tagging your deliveries
39
-
40
- You can use tags to categorize outgoing messages and attach application-specific information. Tagging the different types of email that you send lets you [review statistics and bounce reports separately](http://developer.postmarkapp.com/developer-build.html#message-format).
41
-
42
- Pass `:track_opens => 'true'` to enable/disable open tracking on per-message basis. Check out the [Triggers API](https://github.com/wildbit/postmark-gem/wiki/The-Triggers-API-Support) to see how Postmark can help you control this with tags. **Note that we pass a string here, since it becomes a header value. Passing a boolean may or may not work depending on your Rails version.**
43
-
44
- ``` ruby
45
- class TestMailer < ActionMailer::Base
46
-
47
- def tagged_message
48
- mail(
49
- :subject => 'hello',
50
- :to => 'sheldon@bigbangtheory.com',
51
- :from => 'leonard@bigbangtheory.com',
52
- :tag => 'my-tag',
53
- :track_opens => 'true'
54
- )
55
- end
56
-
57
- end
58
- ```
59
-
60
- ## Sending attachments
61
-
62
- You can also send file attachments with Postmark. Read our Developer docs for [additional information](http://developer.postmarkapp.com/developer-build.html#attachments).
63
-
64
- The Postmark gem is compatible with [ActionMailer attachments API](http://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-attachments). It allows you to specify the name, content-type and other attributes for your attachments.
65
-
66
- The legacy `:postmark_attachments` attribute is *no longer supported* on Rails 3.2.13 and above.
67
-
68
- ``` ruby
69
- class TestMailer < ActionMailer::Base
70
-
71
- def message_with_attachment
72
- attachments.inline['logo.png'] = File.read("/path/to/image") # Inline image
73
- attachments['42.jpg'] = File.read("/path/to/file") # Attached file
74
- mail(
75
- :subject => 'hello',
76
- :to => 'sheldon@bigbangtheory.com',
77
- :from => 'leonard@bigbangtheory.com'
78
- )
79
- end
80
-
81
- end
82
- ```
83
-
84
- ## Attaching metadata to messages
85
-
86
- Postmark supports [attaching metadata to messages](https://postmarkapp.com/support/article/1125-custom-metadata-faq-1). All metadata field values will be interpreted and returned in webhook payloads as strings.
87
-
88
- ``` ruby
89
- class TestMailer < ActionMailer::Base
90
-
91
- def message_with_metadata
92
- metadata['foo'] = 'bar'
93
- mail(
94
- :subject => 'meta hello',
95
- :to => 'sheldon@bigbangtheory.com',
96
- :from => 'leonard@bigbangtheory.com'
97
- )
98
- end
99
-
100
- end
101
- ```
102
-
103
- ## Sending in batches
104
-
105
- While Postmark is focused on transactional email, we understand that developers
106
- with higher volumes or processing time constraints need to send their messages
107
- in batches. To facilitate this we provide a batching endpoint that permits you
108
- to send up to 500 well-formed Postmark messages in a single API call.
109
-
110
- ``` ruby
111
- client = Postmark::ApiClient.new('your-api-token')
112
61
 
113
- messages = []
114
- messages << DigestMailer.weekly_digest(@user1)
115
- messages << DigestMailer.weekly_digest(@user2)
116
-
117
- client.deliver_messages(messages)
118
-
119
- messages.first.delivered?
120
- # => true
121
-
122
- messages.all?(&:delivered)
123
- # => true
124
- ```
125
-
126
- ## Error handling
127
-
128
- The gem respects the `ActionMailer::Base.raise_delivery_errors` setting and will surpress any exceptions
129
- if it’s set to `false`. When delivery errors are enabled, the gem can raise any one of the exceptions
130
- listed in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem docs.
131
-
132
-
133
- ### ActionMailer 5
134
-
135
- For ActionMailer 5 and above, use `ActionMailer::Base.rescue_from` to define handlers for
136
- each error you care about.
137
-
138
- #### Example
139
-
140
- ``` ruby
141
- class ApplicationMailer < ActionMailer::Base
142
- default from: 'user@example.org'
143
- layout 'mailer'
144
-
145
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
146
-
147
- private
148
-
149
- def postmark_client
150
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
151
- ActionMailer::Base.postmark_settings.except(:api_token))
152
- end
153
-
154
-
155
- # This is just an example. Sometimes you might not want to reactivate
156
- # an address that hard bounced.
157
- # Warning: Having too many bounces can affect your delivery reputation
158
- # with email providers
159
- def reactivate_and_retry(error)
160
- Rails.logger.info("Error when sending #{message} to #{error.recipients.join(', ')}")
161
- Rails.logger.info(error)
162
-
163
- error.recipients.each do |recipient|
164
- bounce = postmark_client.bounces(emailFilter: recipient).first
165
- next unless bounce
166
- postmark_client.activate_bounce(bounce[:id])
167
- end
168
-
169
- # Try again immediately
170
- message.deliver
171
- end
172
- end
173
- ```
174
-
175
- ### ActionMailer 4 and below
176
-
177
- Wrap any calls to `#deliver_now` in error handlers like the one described
178
- in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem
179
- docs.
180
-
181
- Rails 4.2 introduces `#deliver_later` but doesn’t support `rescue_from` for
182
- mailer classes. Instead, use the following monkey patch for
183
- `ActionMailer::DeliveryJob`.
184
-
185
- ``` ruby
186
- # app/mailers/application_mailer.rb
187
-
188
- class ApplicationMailer < ActionMailer::Base
189
- default from: 'user@example.org'
190
- end
191
-
192
- class ActionMailer::DeliveryJob
193
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
194
-
195
- def postmark_client
196
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
197
- ActionMailer::Base.postmark_settings.except(:api_token))
198
- end
199
-
200
-
201
- # This is just an example. Sometimes you might not want to reactivate
202
- # an address that hard bounced.
203
- # Warning: Having too many bounces can affect your delivery reputation
204
- # with email providers
205
- def reactivate_and_retry(error)
206
- Rails.logger.info("Error when sending a message to #{error.recipients.join(', ')}")
207
- Rails.logger.info(error)
208
-
209
- error.recipients.each do |recipient|
210
- bounce = postmark_client.bounces(emailFilter: recipient).first
211
- next unless bounce
212
- postmark_client.activate_bounce(bounce[:id])
213
- end
214
-
215
- # Try again immediately
216
- perform(*arguments)
217
- end
218
- end
219
- ```
220
-
221
- ## Additional information
222
-
223
- Looking for the advanced usage examples? Check out [the documentation](https://github.com/wildbit/postmark-gem/blob/master/README.md) for the `postmark` gem. The `postmark-rails` gem is built on top of it, so you can benefit from all its features.
224
-
225
- ## Requirements
226
-
227
- * `postmark` gem version 1.0 and higher is required.
228
- * You will also need a Postmark account, a server and at least one sender signature set up to use it. To get an account, [sign up](https://postmarkapp.com/sign_up)!
62
+ ### Additional information
229
63
 
64
+ Looking for the advanced usage examples? Check out [the documentation](https://github.com/wildbit/postmark-gem/blob/master/README.md) for the [postmark gem](https://github.com/wildbit/postmark-gem).
65
+ The `postmark-rails` gem is built on top of it, so you can benefit from all it's features.
230
66
 
231
67
  ## Note on Patches/Pull Requests
232
68
 
233
- * Fork the project.
234
- * Make your feature addition or bug fix.
235
- * Add tests for it. This is important so we don’t break it in a future version unintentionally.
236
- * Commit, do not mess with rakefile, version, or history.
237
- * Send a pull request. Bonus points for topic branches.
69
+ See [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
238
70
 
239
71
  ## Authors & Contributors
240
72
 
@@ -247,6 +79,16 @@ Looking for the advanced usage examples? Check out [the documentation](https://g
247
79
  * Nicolás Sanguinetti
248
80
  * Laust Rud Jacobsen (rud)
249
81
 
82
+ ## Issues & Comments
83
+
84
+ Feel free to contact us if you encounter any issues with the library or Postmark API.
85
+ Please leave all comments, bugs, requests and issues on the Issues page.
86
+
87
+ ## License
88
+
89
+ The Postmark Rails gem is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) license.
90
+ Refer to the [LICENSE](https://github.com/wildbit/postmark-rails/blob/master/LICENSE) file for more information.
91
+
250
92
  ## Copyright
251
93
 
252
- Copyright © 2010—2018 Wildbit LLC. See LICENSE for details.
94
+ Copyright © 2018 Wildbit LLC.
@@ -4,7 +4,7 @@ gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
6
  gem 'rake', '< 11.0.0'
7
- gem 'postmark', '~> 1.14.0', :path => ENV['POSTMARK_GEM_PATH']
7
+ gem 'postmark', '~> 1.15.0', :path => ENV['POSTMARK_GEM_PATH']
8
8
  gem 'actionmailer', '~> 3.0.0'
9
9
  gem 'rack-cache', '~> 1.2.0'
10
10
 
@@ -4,7 +4,7 @@ gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
6
  gem 'rake', '< 11.0.0'
7
- gem 'postmark', '~> 1.14.0', :path => ENV['POSTMARK_GEM_PATH']
7
+ gem 'postmark', '~> 1.15.0', :path => ENV['POSTMARK_GEM_PATH']
8
8
  gem 'actionmailer', :github => 'rails', :branch => '3-2-stable'
9
9
  gem 'i18n', '~> 0.6.0'
10
10
  gem 'rack-cache', '~> 1.2.0'
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.14.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15.0', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.0.0'
8
8
 
9
9
  group :test do
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.14.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15.0', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.1.0'
8
8
 
9
9
  group :test do
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.14.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15.0', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.2.0'
8
8
 
9
9
  group :test do
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 5.0.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 5.1.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -14,6 +14,8 @@ module PostmarkRails
14
14
  end
15
15
 
16
16
  def self.install
17
+ require 'postmark-rails/preview_interceptor'
18
+ require 'postmark-rails/templated_mailer'
17
19
  ActionMailer::Base.add_delivery_method :postmark, Mail::Postmark
18
20
  ActionMailer::Base.send(:include, ActionMailerExtensions)
19
21
  end
@@ -0,0 +1,10 @@
1
+ module PostmarkRails
2
+ class PreviewInterceptor
3
+ def self.previewing_email(message)
4
+ return unless message.templated?
5
+
6
+ message.delivery_method(::Mail::Postmark, ::ActionMailer::Base.postmark_settings)
7
+ message.prerender
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,68 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+
3
+ module PostmarkRails
4
+ module TemplatedMailerMixin
5
+ READ_ONLY_HEADERS = %w(body content_type subject).freeze
6
+ BODY_STUB = 'Temporary Postmark Template Body'.freeze
7
+ SUBJECT_STUB = 'Temporary Postmark Template Subject'.freeze
8
+ ALIAS_STUB = proc { action_name }
9
+
10
+ def self.included(mailer)
11
+ mailer.default(
12
+ :body => BODY_STUB,
13
+ :content_type => 'text/plain',
14
+ :subject => SUBJECT_STUB,
15
+ :postmark_template_alias => ALIAS_STUB
16
+ )
17
+ mailer.extend(ClassMethods)
18
+ end
19
+
20
+ def template_model(*args)
21
+ message.template_model(*args)
22
+ end
23
+
24
+ def template_model=(model)
25
+ message.template_model = model
26
+ end
27
+
28
+ def mail(headers = {})
29
+ super(self.class.safe_headers(headers))
30
+ ensure
31
+ message.body = standard_template_body
32
+ message.subject = standard_template_subject
33
+ end
34
+
35
+ private
36
+
37
+ module ClassMethods
38
+ def default(headers = {})
39
+ super(safe_headers(headers))
40
+ end
41
+
42
+ def safe_headers(headers = {})
43
+ headers = ActiveSupport::HashWithIndifferentAccess.new(headers)
44
+ violation = READ_ONLY_HEADERS.find { |h| headers.key?(h) }
45
+ raise ArgumentError, "Overriding '#{violation}' header in a templated mailer is not allowed." if violation
46
+ headers
47
+ end
48
+ end
49
+
50
+ def standard_template_body
51
+ "This message is using a Postmark template.\n\n" \
52
+ "Alias: #{message.template_alias.inspect}\n" \
53
+ "Model:\n#{JSON.pretty_generate(message.template_model || {})}\n\n" \
54
+ 'Use the #prerender method on this object to contact the Postmark API ' \
55
+ "to pre-render the template.\n\n" \
56
+ "Cheers,\n" \
57
+ 'Your friends at Postmark'
58
+ end
59
+
60
+ def standard_template_subject
61
+ "Postmark Template: #{message.template_alias.inspect}"
62
+ end
63
+ end
64
+
65
+ class TemplatedMailer < ::ActionMailer::Base
66
+ include TemplatedMailerMixin
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module PostmarkRails
2
- VERSION = '0.18.0'
2
+ VERSION = '0.19.0'
3
3
  end
@@ -10,6 +10,10 @@ Gem::Specification.new do |s|
10
10
  s.homepage = %q{http://postmarkapp.com}
11
11
  s.summary = %q{Postmark adapter for ActionMailer}
12
12
 
13
+ s.metadata = {
14
+ "source_code_uri" => "https://github.com/wildbit/postmark-rails"
15
+ }
16
+
13
17
  s.extra_rdoc_files = [
14
18
  "LICENSE",
15
19
  "README.md"
@@ -17,7 +21,7 @@ Gem::Specification.new do |s|
17
21
  s.rdoc_options = ["--charset=UTF-8"]
18
22
 
19
23
  s.add_dependency('actionmailer', ">= 3.0.0")
20
- s.add_dependency('postmark', "~> 1.14.0")
24
+ s.add_dependency('postmark', "~> 1.15.0")
21
25
 
22
26
  s.add_development_dependency("rake")
23
27
 
Binary file
@@ -10,3 +10,12 @@ ActionMailer::Base.delivery_method = :postmark
10
10
  ActionMailer::Base.prepend_view_path(File.join(File.dirname(__FILE__), "fixtures", "views"))
11
11
 
12
12
  Dir["#{File.dirname(__FILE__)}/fixtures/models/*.rb"].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ def make_mailer(base, &block)
16
+ mailer = Class.new(base, &block)
17
+ @mailer_number = 0
18
+ stub_const("Mailer#{@mailer_number += 1}", mailer)
19
+ mailer
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PostmarkRails::PreviewInterceptor do
4
+ describe '.previewing_email' do
5
+ subject(:preview) { described_class.previewing_email(message) }
6
+ let(:settings) { { :api_token => 'secret' } }
7
+
8
+ before do
9
+ ActionMailer::Base.postmark_settings = settings
10
+ end
11
+
12
+ context 'when given a templated message' do
13
+ let(:message) do
14
+ Mail::Message.new do
15
+ template_alias 'foo'
16
+ end
17
+ end
18
+
19
+ it 'changes the message' do
20
+ message.freeze
21
+ expect { preview }.to raise_error(StandardError, /can't modify/)
22
+ end
23
+
24
+ it 'changes delivery method to Postmark and prerenders' do
25
+ expect(message).to receive(:prerender).exactly(1)
26
+ expect { preview }.to change { message.delivery_method }.to(Mail::Postmark)
27
+ expect(message.delivery_method.settings).to eq(settings)
28
+ end
29
+ end
30
+
31
+ context 'when given a non-templated message' do
32
+ let(:message) { Mail::Message.new }
33
+
34
+ it 'returns the message "as is"' do
35
+ message.freeze
36
+ expect { preview }.to_not raise_error
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PostmarkRails::TemplatedMailer do
4
+ subject(:message) { mailer.test_message }
5
+
6
+ shared_examples_for 'templated message' do |template_alias, model|
7
+ it { is_expected.to be_templated }
8
+ specify { expect(message.template_alias).to eq(template_alias) }
9
+ specify { expect(message.template_model).to eq model }
10
+ specify { expect(message.subject).to eq "Postmark Template: #{template_alias.inspect}" }
11
+ specify { expect(message.body_text).to include(template_alias.inspect) }
12
+ specify { expect(message.body_text).to include(JSON.pretty_generate(model || {})) }
13
+ end
14
+
15
+ context 'when template is not specified' do
16
+ let(:mailer) do
17
+ make_mailer(described_class) do
18
+ def test_message
19
+ mail :from => 'sender@wildbit.com', :to => 'recipient@wildbit.com'
20
+ end
21
+ end
22
+ end
23
+
24
+ it_behaves_like 'templated message', 'test_message'
25
+ end
26
+
27
+ context 'when template is specified' do
28
+ let(:mailer) do
29
+ make_mailer(described_class) do
30
+ def test_message
31
+ mail :from => 'sender@wildbit.com',
32
+ :to => 'recipient@wildbit.com',
33
+ :postmark_template_alias => 'custom_template'
34
+ end
35
+ end
36
+ end
37
+
38
+ it_behaves_like 'templated message', 'custom_template'
39
+ end
40
+
41
+ context 'when template model is specified' do
42
+ let(:mailer) do
43
+ make_mailer(described_class) do
44
+ def test_message
45
+ self.template_model = { :foo => 'bar' }
46
+ mail :from => 'sender@wildbit.com',
47
+ :to => 'recipient@wildbit.com'
48
+ end
49
+ end
50
+ end
51
+
52
+ it_behaves_like 'templated message', 'test_message', :foo => 'bar'
53
+ end
54
+
55
+ describe '.default' do
56
+ it 'protects sensitive default headers from being overwritten' do
57
+ %w(subject body content_type).each do |header|
58
+ expect { described_class.default(header => 'foo') }.
59
+ to raise_error(ArgumentError, "Overriding '#{header}' header in a templated mailer is not allowed.")
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#mail' do
65
+ context "when overriding subject" do
66
+ let(:mailer) do
67
+ make_mailer(described_class) do
68
+ def test_message
69
+ mail :subject => 'Subject'
70
+ end
71
+ end
72
+ end
73
+
74
+ it 'protects it from being overwritten' do
75
+ expect { mailer.test_message.subject }.
76
+ to raise_error(ArgumentError, "Overriding 'subject' header in a templated mailer is not allowed.")
77
+ end
78
+ end
79
+
80
+ context "when overriding body" do
81
+ let(:mailer) do
82
+ make_mailer(described_class) do
83
+ def test_message
84
+ mail :body => 'body'
85
+ end
86
+ end
87
+ end
88
+
89
+ it 'protects it from being overwritten' do
90
+ expect { mailer.test_message.body }.
91
+ to raise_error(ArgumentError, "Overriding 'body' header in a templated mailer is not allowed.")
92
+ end
93
+ end
94
+
95
+ context "when overriding content_type" do
96
+ let(:mailer) do
97
+ make_mailer(described_class) do
98
+ def test_message
99
+ mail :content_type => 'content_type'
100
+ end
101
+ end
102
+ end
103
+
104
+ it 'protects it from being overwritten' do
105
+ expect { mailer.test_message.content_type }.
106
+ to raise_error(ArgumentError, "Overriding 'content_type' header in a templated mailer is not allowed.")
107
+ end
108
+ end
109
+ end
110
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-08-22 00:00:00.000000000 Z
13
+ date: 2019-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionmailer
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 1.14.0
35
+ version: 1.15.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 1.14.0
42
+ version: 1.15.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,9 @@ files:
66
66
  - ".document"
67
67
  - ".gitignore"
68
68
  - ".travis.yml"
69
+ - ".travis/setup.sh"
69
70
  - CHANGELOG.rdoc
71
+ - CONTRIBUTING.md
70
72
  - Gemfile
71
73
  - LICENSE
72
74
  - README.md
@@ -76,10 +78,15 @@ files:
76
78
  - gemfiles/Gemfile.actionmailer-4.0.x
77
79
  - gemfiles/Gemfile.actionmailer-4.1.x
78
80
  - gemfiles/Gemfile.actionmailer-4.2.x
81
+ - gemfiles/Gemfile.actionmailer-5.0.x
82
+ - gemfiles/Gemfile.actionmailer-5.1.x
79
83
  - lib/postmark-rails.rb
84
+ - lib/postmark-rails/preview_interceptor.rb
80
85
  - lib/postmark-rails/railtie.rb
86
+ - lib/postmark-rails/templated_mailer.rb
81
87
  - lib/postmark-rails/version.rb
82
88
  - postmark-rails.gemspec
89
+ - postmark.png
83
90
  - spec/fixtures/empty.gif
84
91
  - spec/fixtures/models/test_mailer.rb
85
92
  - spec/fixtures/views/test_mailer/message_with_attachment.erb
@@ -92,12 +99,15 @@ files:
92
99
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
93
100
  - spec/integration/batch_delivery_spec.rb
94
101
  - spec/integration/delivery_spec.rb
95
- - spec/postmark-rails_spec.rb
96
102
  - spec/spec.opts
97
103
  - spec/spec_helper.rb
104
+ - spec/unit/postmark-rails_spec.rb
105
+ - spec/unit/preview_interceptor_spec.rb
106
+ - spec/unit/templated_mailer_spec.rb
98
107
  homepage: http://postmarkapp.com
99
108
  licenses: []
100
- metadata: {}
109
+ metadata:
110
+ source_code_uri: https://github.com/wildbit/postmark-rails
101
111
  post_install_message:
102
112
  rdoc_options:
103
113
  - "--charset=UTF-8"
@@ -132,6 +142,8 @@ test_files:
132
142
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
133
143
  - spec/integration/batch_delivery_spec.rb
134
144
  - spec/integration/delivery_spec.rb
135
- - spec/postmark-rails_spec.rb
136
145
  - spec/spec.opts
137
146
  - spec/spec_helper.rb
147
+ - spec/unit/postmark-rails_spec.rb
148
+ - spec/unit/preview_interceptor_spec.rb
149
+ - spec/unit/templated_mailer_spec.rb