postmark 1.9.1 → 1.10.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: 76623008dfbb09504295182472b645b013700da6
4
- data.tar.gz: 8648dba9d5ed435d630493777d8b42552369df54
3
+ metadata.gz: 0783a6fc070a9e3aa81200e4e37df4b4ac7cc615
4
+ data.tar.gz: 945107372cad40489c8ceb05537429114d1e9e1a
5
5
  SHA512:
6
- metadata.gz: f6b5c6789fa0d38c1d4ba35a426febce12b11c3bd09a9450e388d9cf1c17d2c5312ae67611e33d9d2cc750173e2020c86920b4100ea9f46b7a847e18cfe88fd6
7
- data.tar.gz: e3324835f12c6a203fdc78147a400c039714d5a0045917823b95d4bdd2890f7afbad80ab7a816aaea12785ba2c6cee62132016ec25eb3ad027ce86b481ee0782
6
+ metadata.gz: 69edcd10b9a8b14ea2d211150992af00387438870424a5d3adf015e409f11fe67baa924cf10963a524dadbd258ef0df244cb5086f1106c3f1a0662a3e9f29bbb
7
+ data.tar.gz: a5818e954ca24d7098166a5a8c63e445b0e58b763766c901ead97fe835176433ae1924d4ecb9b5b933b1c53547583a2af1d5c5577069c6d9285866633c35e691
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = Changelog
2
2
 
3
+ == 1.10.0
4
+
5
+ * Fix a bug when open tracking flag is set to false by default, when open tracking flag is not set by a user.
6
+ * Added support for link tracking
7
+
3
8
  == 1.9.1
4
9
 
5
10
  * Fix a bug when port setting is not respected.
data/README.md CHANGED
@@ -66,7 +66,7 @@ client.deliver(from: 'sheldon@bigbangtheory.com',
66
66
  # => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:45:16.2059023-04:00", :message_id=>"b2b268e3-6a70-xxxx-b897-49c9eb8b1d2e", :error_code=>0, :message=>"OK"}
67
67
  ```
68
68
 
69
- ## Sending an HTML message (with open tracking!)
69
+ ## Sending an HTML message with open tracking
70
70
 
71
71
  Simply pass an HTML document as html_body parameter to `#deliver`. You can also enable open tracking by setting `track_opens` to `true`.
72
72
 
@@ -80,6 +80,22 @@ client.deliver(from: 'sheldon@bigbangtheory.com',
80
80
  track_opens: true)
81
81
  # => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:51:08.8789433-04:00", :message_id=>"75c28987-564e-xxxx-b6eb-e8071873ac06", :error_code=>0, :message=>"OK"}
82
82
  ```
83
+ ## Sending a message with link tracking
84
+
85
+ To track visited links for emails you send, make sure to have links in html_body, text_body or both when passing them to `#deliver`. You need to enable link tracking by setting `track_links` parameter to one of the following options: `:html_only`, `:text_only`, `:html_and_text` or `:none`.
86
+ Depending on parameter you set, link tracking will be enabled on plain text body, html body, both or none. Optionally you can also use string values as parameters 'HtmlOnly', 'TextOnly', 'HtmlAndText' or 'None'.
87
+
88
+ ``` ruby
89
+ client.deliver(from: 'sheldon@bigbangtheory.com',
90
+ to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
91
+ subject: 'Re: What, to you, is a large crowd?',
92
+ html_body: '<p>Any group big enough to trample me to death. ' \
93
+ 'General <a href="http://www.example.com">rule of thumb</a> is 36 adults or 70 ' \
94
+ 'children.</p>',
95
+ text_body: 'Any group big enough to trample me to death. General rule of thumb is 36 adults or 70 children - http://www.example.com.',
96
+ track_links: :html_and_text)
97
+ # => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:51:08.8789433-04:00", :message_id=>"75c28987-564e-xxxx-b6eb-e8071873ac06", :error_code=>0, :message=>"OK"}
98
+ ```
83
99
 
84
100
  ## Sending a message with attachments
85
101
 
@@ -391,7 +407,7 @@ message = Mail.new do
391
407
  body '<p>Any group big enough to trample me to death. General ' \
392
408
  'rule of thumb is 36 adults or 70 children.</p>'
393
409
 
394
- track_opens "true" # Feel free to use boolean values on mail >= 2.3.0
410
+ track_opens true
395
411
 
396
412
  delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
397
413
  end
@@ -400,6 +416,41 @@ message.deliver
400
416
  # => #<Mail::Message:70355902117460, Multipart: false, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: 3a9370a2-6c24-4304-a03c-320a54cc59f7>, <Subject: Re: What, to you, is a large crowd?>, <Content-Type: text/html; charset=UTF-8>>
401
417
  ```
402
418
 
419
+ ## Multipart message (with link tracking)
420
+
421
+ Notice that we set `track_links` field to `:html_and_text`, to enable link tracking for both plain text and html parts for this message.
422
+
423
+ ``` ruby
424
+ require 'rubygems'
425
+ require 'postmark'
426
+ require 'mail'
427
+ require 'json'
428
+
429
+ message = Mail.new do
430
+ from 'sheldon@bigbangtheory.com'
431
+ to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
432
+ subject 'Re: What, to you, is a large crowd?'
433
+
434
+ text_part do
435
+ body 'Any group big enough to trample me to death. General rule of thumb is 36 adults or 70 children - http://www.example.com.'
436
+ end
437
+
438
+ html_part do
439
+ content_type 'text/html; charset=UTF-8'
440
+ body '<p>Any group big enough to trample me to death. ' \
441
+ 'General <a href="http://www.example.com">rule of thumb</a> is 36 adults or 70 ' \
442
+ 'children.</p>'
443
+ end
444
+
445
+ track_links :html_and_text
446
+
447
+ delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
448
+ end
449
+
450
+ message.deliver
451
+ # => #<Mail::Message:70355902117460, Multipart: true, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: 1a1370a1-6c21-4304-a03c-320a54cc59f7>, <Subject: Re: What, to you, is a large crowd?>, <Content-Type: multipart/alternative; boundary=--==_mimepart_58380d6029b17_20543fd48543fa14977a>, <TRACK-LINKS: HtmlAndText>>
452
+ ```
453
+
403
454
  ## Message with attachments
404
455
 
405
456
  ``` ruby
@@ -629,10 +680,13 @@ Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl are also suppor
629
680
 
630
681
  * Fork the project.
631
682
  * Make your feature addition or bug fix.
632
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
633
- * Commit, do not mess with rakefile, version, or history.
634
- * Send me a pull request. Bonus points for topic branches.
683
+ * Add tests for it. This is important to prevent future regressions.
684
+ * Do not mess with rakefile, version, or history
685
+ * Update the CHANGELOG, list your changes under Unreleased.
686
+ * Update the README if necessary.
687
+ * Write short, descriptive commit messages, following the format used in the repo.
688
+ * Send a pull request. Bonus points for topic branches.
635
689
 
636
690
  ## Copyright
637
691
 
638
- Copyright © 2014 Wildbit LLC. See LICENSE for details.
692
+ Copyright © 2016 Wildbit LLC. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.1
1
+ 1.10.0
@@ -18,6 +18,10 @@ module Postmark
18
18
  message[:attachments] = attachments_to_postmark(message[:attachments])
19
19
  end
20
20
 
21
+ if message[:track_links]
22
+ message[:track_links] = ::Postmark::Inflector.to_postmark(message[:track_links])
23
+ end
24
+
21
25
  HashHelper.to_postmark(message)
22
26
  end
23
27
 
@@ -30,7 +30,8 @@ module Postmark
30
30
  'Subject' => @message.subject,
31
31
  'Headers' => @message.export_headers,
32
32
  'Tag' => @message.tag.to_s,
33
- 'TrackOpens' => cast_to_bool(@message.track_opens)
33
+ 'TrackOpens' => (cast_to_bool(@message.track_opens) unless @message.track_opens.empty?),
34
+ 'TrackLinks' => (@message.track_links unless @message.track_links.empty?)
34
35
  }
35
36
  end
36
37
 
@@ -15,12 +15,22 @@ module Mail
15
15
  header['TAG'] = val
16
16
  end
17
17
 
18
+ def track_links(val = nil)
19
+ self.track_links=(val) unless val.nil?
20
+ header['TRACK-LINKS'].to_s
21
+ end
22
+
23
+ def track_links=(val)
24
+ header['TRACK-LINKS'] = ::Postmark::Inflector.to_postmark(val)
25
+ end
26
+
18
27
  def track_opens(val = nil)
19
- default 'TRACK-OPENS', !!val
28
+ self.track_opens=(val) unless val.nil?
29
+ header['TRACK-OPENS'].to_s
20
30
  end
21
31
 
22
32
  def track_opens=(val)
23
- header['TRACK-OPENS'] = !!val
33
+ header['TRACK-OPENS'] = (!!val).to_s
24
34
  end
25
35
 
26
36
  def postmark_attachments=(value)
@@ -116,7 +126,7 @@ module Mail
116
126
  cc bcc
117
127
  subject tag
118
128
  attachment to
119
- track-opens
129
+ track-opens track-links
120
130
  ]
121
131
  end
122
132
 
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.9.1'
2
+ VERSION = '1.10.0'
3
3
  end
@@ -80,46 +80,92 @@ describe Postmark::MessageHelper do
80
80
  message.merge(:track_opens => true)
81
81
  }
82
82
 
83
+ let(:message_with_open_tracking_false) {
84
+ message.merge(:track_opens => false)
85
+ }
86
+
83
87
  let(:postmark_message_with_open_tracking) {
84
88
  postmark_message.merge("TrackOpens" => true)
85
89
  }
86
90
 
91
+ let(:postmark_message_with_open_tracking_false) {
92
+ postmark_message.merge("TrackOpens" => false)
93
+ }
94
+
87
95
  it 'converts messages without custom headers and attachments correctly' do
88
- subject.to_postmark(message).should == postmark_message
96
+ expect(subject.to_postmark(message)).to eq postmark_message
89
97
  end
90
98
 
91
99
  it 'converts messages with custom headers and without attachments correctly' do
92
- subject.to_postmark(message_with_headers).should == postmark_message_with_headers
100
+ expect(subject.to_postmark(message_with_headers)).to eq postmark_message_with_headers
93
101
  end
94
102
 
95
103
  it 'converts messages with custom headers and attachments correctly' do
96
- subject.to_postmark(message_with_headers_and_attachments).should == postmark_message_with_headers_and_attachments
104
+ expect(subject.to_postmark(message_with_headers_and_attachments)).to eq postmark_message_with_headers_and_attachments
105
+ end
106
+
107
+ context 'open tracking flag set' do
108
+
109
+ it 'true' do
110
+ expect(subject.to_postmark(message_with_open_tracking)).to eq(postmark_message_with_open_tracking)
111
+ end
112
+
113
+ it 'false' do
114
+ expect(subject.to_postmark(message_with_open_tracking_false)).to eq(postmark_message_with_open_tracking_false)
115
+ end
116
+
97
117
  end
98
118
 
99
- it 'includes open tracking flag when specified' do
100
- expect(subject.to_postmark(message_with_open_tracking)).to eq(postmark_message_with_open_tracking)
119
+ context 'link tracking flag set' do
120
+
121
+ let(:message_with_link_tracking_html) { message.merge(:track_links => :html_only) }
122
+ let(:message_with_link_tracking_text) { message.merge(:track_links => :text_only) }
123
+ let(:message_with_link_tracking_all) { message.merge(:track_links => :html_and_text) }
124
+ let(:message_with_link_tracking_none) { message.merge(:track_links => :none) }
125
+
126
+ let(:postmark_message_with_link_tracking_html) { postmark_message.merge("TrackLinks" => 'HtmlOnly') }
127
+ let(:postmark_message_with_link_tracking_text) { postmark_message.merge("TrackLinks" => 'TextOnly') }
128
+ let(:postmark_message_with_link_tracking_all) { postmark_message.merge("TrackLinks" => 'HtmlAndText') }
129
+ let(:postmark_message_with_link_tracking_none) { postmark_message.merge("TrackLinks" => 'None') }
130
+
131
+ it 'html' do
132
+ expect(subject.to_postmark(message_with_link_tracking_html)).to eq(postmark_message_with_link_tracking_html)
133
+ end
134
+
135
+ it 'text' do
136
+ expect(subject.to_postmark(message_with_link_tracking_text)).to eq(postmark_message_with_link_tracking_text)
137
+ end
138
+
139
+ it 'html and text' do
140
+ expect(subject.to_postmark(message_with_link_tracking_all)).to eq(postmark_message_with_link_tracking_all)
141
+ end
142
+
143
+ it 'none' do
144
+ expect(subject.to_postmark(message_with_link_tracking_none)).to eq(postmark_message_with_link_tracking_none)
145
+ end
146
+
101
147
  end
102
148
 
103
149
  end
104
150
 
105
151
  describe ".headers_to_postmark" do
106
152
  it 'converts headers to Postmark format' do
107
- subject.headers_to_postmark(headers).should == postmark_headers
153
+ expect(subject.headers_to_postmark(headers)).to eq postmark_headers
108
154
  end
109
155
 
110
156
  it 'accepts single header as a non-array' do
111
- subject.headers_to_postmark(headers.first).should == [postmark_headers.first]
157
+ expect(subject.headers_to_postmark(headers.first)).to eq [postmark_headers.first]
112
158
  end
113
159
  end
114
160
 
115
161
  describe ".attachments_to_postmark" do
116
162
 
117
163
  it 'converts attachments to Postmark format' do
118
- subject.attachments_to_postmark(attachments).should == postmark_attachments
164
+ expect(subject.attachments_to_postmark(attachments)).to eq postmark_attachments
119
165
  end
120
166
 
121
167
  it 'accepts single attachment as a non-array' do
122
- subject.attachments_to_postmark(attachments.first).should == [postmark_attachments.first]
168
+ expect(subject.attachments_to_postmark(attachments.first)).to eq [postmark_attachments.first]
123
169
  end
124
170
 
125
171
  end
@@ -15,7 +15,7 @@ describe Postmark::MailMessageConverter do
15
15
  end
16
16
 
17
17
  let(:mail_html_message) do
18
- mail = Mail.new do
18
+ Mail.new do
19
19
  from "sheldon@bigbangtheory.com"
20
20
  to "lenard@bigbangtheory.com"
21
21
  subject "Hello!"
@@ -24,8 +24,8 @@ describe Postmark::MailMessageConverter do
24
24
  end
25
25
  end
26
26
 
27
- let(:mail_message_with_tracking) do
28
- mail = Mail.new do
27
+ let(:mail_message_with_open_tracking) do
28
+ Mail.new do
29
29
  from "sheldon@bigbangtheory.com"
30
30
  to "lenard@bigbangtheory.com"
31
31
  subject "Hello!"
@@ -35,6 +35,52 @@ describe Postmark::MailMessageConverter do
35
35
  end
36
36
  end
37
37
 
38
+ let(:mail_message_with_open_tracking_disabled) do
39
+ Mail.new do
40
+ from "sheldon@bigbangtheory.com"
41
+ to "lenard@bigbangtheory.com"
42
+ subject "Hello!"
43
+ content_type 'text/html; charset=UTF-8'
44
+ body "<b>Hello Sheldon!</b>"
45
+ track_opens false
46
+ end
47
+ end
48
+
49
+ let(:mail_message_with_open_tracking_set_variable) do
50
+ mail = mail_html_message
51
+ mail.track_opens=true
52
+ mail
53
+ end
54
+
55
+ let(:mail_message_with_open_tracking_disabled_set_variable) do
56
+ mail = mail_html_message
57
+ mail.track_opens=false
58
+ mail
59
+ end
60
+
61
+ let(:mail_message_with_link_tracking_all) do
62
+ mail = mail_html_message
63
+ mail.track_links :html_and_text
64
+ mail
65
+ end
66
+
67
+ let(:mail_message_with_link_tracking_html) do
68
+ mail = mail_html_message
69
+ mail.track_links = :html_only
70
+ mail
71
+ end
72
+
73
+ let(:mail_message_with_link_tracking_text) do
74
+ mail = mail_html_message
75
+ mail.track_links = :text_only
76
+ mail
77
+ end
78
+
79
+ let(:mail_message_with_link_tracking_none) do
80
+ mail = mail_html_message
81
+ mail.track_links = :none
82
+ mail
83
+ end
38
84
 
39
85
  let(:tagged_mail_message) do
40
86
  Mail.new do
@@ -55,7 +101,7 @@ describe Postmark::MailMessageConverter do
55
101
  end
56
102
 
57
103
  let(:mail_multipart_message) do
58
- mail = Mail.new do
104
+ Mail.new do
59
105
  from "sheldon@bigbangtheory.com"
60
106
  to "lenard@bigbangtheory.com"
61
107
  subject "Hello!"
@@ -123,8 +169,7 @@ describe Postmark::MailMessageConverter do
123
169
  "From" => "sheldon@bigbangtheory.com",
124
170
  "Subject" => "Hello!",
125
171
  "TextBody" => "Hello Sheldon!",
126
- "To" => "lenard@bigbangtheory.com",
127
- 'TrackOpens' => false}
172
+ "To" => "lenard@bigbangtheory.com"}
128
173
  end
129
174
 
130
175
  it 'converts tagged text messages correctly' do
@@ -133,16 +178,14 @@ describe Postmark::MailMessageConverter do
133
178
  "Subject" => "Hello!",
134
179
  "TextBody" => "Hello Sheldon!",
135
180
  "Tag" => "sheldon",
136
- "To"=>"lenard@bigbangtheory.com",
137
- 'TrackOpens' => false}
181
+ "To"=>"lenard@bigbangtheory.com"}
138
182
  end
139
183
 
140
184
  it 'converts plain text messages without body correctly' do
141
185
  subject.new(mail_message_without_body).run.should == {
142
186
  "From" => "sheldon@bigbangtheory.com",
143
187
  "Subject" => "Hello!",
144
- "To" => "lenard@bigbangtheory.com",
145
- 'TrackOpens' => false}
188
+ "To" => "lenard@bigbangtheory.com"}
146
189
  end
147
190
 
148
191
  it 'converts html messages correctly' do
@@ -150,8 +193,7 @@ describe Postmark::MailMessageConverter do
150
193
  "From" => "sheldon@bigbangtheory.com",
151
194
  "Subject" => "Hello!",
152
195
  "HtmlBody" => "<b>Hello Sheldon!</b>",
153
- "To" => "lenard@bigbangtheory.com",
154
- 'TrackOpens' => false}
196
+ "To" => "lenard@bigbangtheory.com"}
155
197
  end
156
198
 
157
199
  it 'converts multipart messages correctly' do
@@ -160,8 +202,7 @@ describe Postmark::MailMessageConverter do
160
202
  "Subject" => "Hello!",
161
203
  "HtmlBody" => "<b>Hello Sheldon!</b>",
162
204
  "TextBody" => "Hello Sheldon!",
163
- "To" => "lenard@bigbangtheory.com",
164
- 'TrackOpens' => false}
205
+ "To" => "lenard@bigbangtheory.com"}
165
206
  end
166
207
 
167
208
  it 'converts messages with attachments correctly' do
@@ -172,8 +213,7 @@ describe Postmark::MailMessageConverter do
172
213
  "Content"=>encoded_empty_gif_data,
173
214
  "ContentType"=>"image/gif"}],
174
215
  "TextBody"=>"Hello Sheldon!",
175
- "To"=>"lenard@bigbangtheory.com",
176
- 'TrackOpens' => false}
216
+ "To"=>"lenard@bigbangtheory.com"}
177
217
  end
178
218
 
179
219
  it 'converts messages with named addresses correctly' do
@@ -182,18 +222,95 @@ describe Postmark::MailMessageConverter do
182
222
  "Subject" => "Hello!",
183
223
  "TextBody" => "Hello Sheldon!",
184
224
  "To" => "Leonard Hofstadter <leonard@bigbangtheory.com>",
185
- "ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>',
186
- 'TrackOpens' => false
187
- }
225
+ "ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>'}
188
226
  end
189
227
 
190
- it 'recognizes when open tracking is enabled' do
191
- subject.new(mail_message_with_tracking).run.should == {
192
- "From" => "sheldon@bigbangtheory.com",
193
- "Subject" => "Hello!",
194
- "HtmlBody" => "<b>Hello Sheldon!</b>",
195
- "To" => "lenard@bigbangtheory.com",
196
- "TrackOpens" => true}
228
+ context 'recognizes open tracking' do
229
+
230
+ context 'setup inside of mail' do
231
+
232
+ it 'enabled' do
233
+ expect(subject.new(mail_message_with_open_tracking).run).to eq ({
234
+ "From" => "sheldon@bigbangtheory.com",
235
+ "Subject" => "Hello!",
236
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
237
+ "To" => "lenard@bigbangtheory.com",
238
+ "TrackOpens" => true})
239
+ end
240
+
241
+ it 'disabled' do
242
+ expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq ({
243
+ "From" => "sheldon@bigbangtheory.com",
244
+ "Subject" => "Hello!",
245
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
246
+ "To" => "lenard@bigbangtheory.com",
247
+ "TrackOpens" => false})
248
+ end
249
+
250
+ end
251
+
252
+ context 'setup with tracking variable' do
253
+
254
+ it 'enabled' do
255
+ expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq ({
256
+ "From" => "sheldon@bigbangtheory.com",
257
+ "Subject" => "Hello!",
258
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
259
+ "To" => "lenard@bigbangtheory.com",
260
+ "TrackOpens" => true})
261
+ end
262
+
263
+ it 'disabled' do
264
+ expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq ({
265
+ "From" => "sheldon@bigbangtheory.com",
266
+ "Subject" => "Hello!",
267
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
268
+ "To" => "lenard@bigbangtheory.com",
269
+ "TrackOpens" => false})
270
+ end
271
+
272
+ end
273
+
274
+ end
275
+
276
+ context 'link tracking' do
277
+
278
+ it 'html and text' do
279
+ expect(subject.new(mail_message_with_link_tracking_all).run).to eq ({
280
+ "From" => "sheldon@bigbangtheory.com",
281
+ "Subject" => "Hello!",
282
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
283
+ "To" => "lenard@bigbangtheory.com",
284
+ "TrackLinks" => 'HtmlAndText'})
285
+ end
286
+
287
+ it 'html only' do
288
+ expect(subject.new(mail_message_with_link_tracking_html).run).to eq ({
289
+ "From" => "sheldon@bigbangtheory.com",
290
+ "Subject" => "Hello!",
291
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
292
+ "To" => "lenard@bigbangtheory.com",
293
+ "TrackLinks" => 'HtmlOnly'})
294
+ end
295
+
296
+ it 'text only' do
297
+ expect(subject.new(mail_message_with_link_tracking_text).run).to eq ({
298
+ "From" => "sheldon@bigbangtheory.com",
299
+ "Subject" => "Hello!",
300
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
301
+ "To" => "lenard@bigbangtheory.com",
302
+ "TrackLinks" => 'TextOnly'})
303
+ end
304
+
305
+ it 'none' do
306
+ expect(subject.new(mail_message_with_link_tracking_none).run).to eq ({
307
+ "From" => "sheldon@bigbangtheory.com",
308
+ "Subject" => "Hello!",
309
+ "HtmlBody" => "<b>Hello Sheldon!</b>",
310
+ "To" => "lenard@bigbangtheory.com",
311
+ "TrackLinks" => 'None'})
312
+ end
313
+
197
314
  end
198
315
 
199
316
  it 'correctly decodes unicode in messages transfered as quoted-printable' do
@@ -15,7 +15,7 @@ describe Mail::Message do
15
15
  end
16
16
 
17
17
  let(:mail_html_message) do
18
- mail = Mail.new do
18
+ Mail.new do
19
19
  from "sheldon@bigbangtheory.com"
20
20
  to "lenard@bigbangtheory.com"
21
21
  subject "Hello!"
@@ -38,24 +38,102 @@ describe Mail::Message do
38
38
  mail_message.header['Tag'] = 'bogus-tag'
39
39
  mail_message.header['Attachment'] = 'anydatahere'
40
40
  mail_message.header['Allowed-Header'] = 'value'
41
+ mail_message.header['TRACK-OPENS'] = 'true'
42
+ mail_message.header['TRACK-LINKS'] = 'HtmlOnly'
41
43
  mail_message
42
44
  end
43
45
 
46
+ describe '#tag' do
47
+
48
+ it 'value set on tag=' do
49
+ mail_message.tag='value'
50
+ expect(mail_message.tag).to eq 'value'
51
+ end
52
+
53
+ it 'value set on tag()' do
54
+ mail_message.tag('value')
55
+ expect(mail_message.tag).to eq 'value'
56
+ end
57
+
58
+ end
59
+
60
+ describe '#track_opens' do
61
+
62
+ context 'flag set on track_opens=' do
63
+
64
+ it 'true' do
65
+ mail_message.track_opens = true
66
+ expect(mail_message.track_opens).to eq 'true'
67
+ end
68
+
69
+ it 'false' do
70
+ mail_message.track_opens = false
71
+ expect(mail_message.track_opens).to eq 'false'
72
+ end
73
+
74
+ it 'not set' do
75
+ expect(mail_message.track_opens).to eq ''
76
+ end
77
+
78
+ end
79
+
80
+ context 'flag set on track_opens()' do
81
+
82
+ it 'true' do
83
+ mail_message.track_opens(true)
84
+ expect(mail_message.track_opens).to eq 'true'
85
+ end
86
+
87
+ it 'false' do
88
+ mail_message.track_opens(false)
89
+ expect(mail_message.track_opens).to eq 'false'
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ describe '#track_links' do
97
+
98
+ context 'flag set on track_links=' do
99
+
100
+ it 'set' do
101
+ mail_message.track_links=:html_only
102
+ expect(mail_message.track_links).to eq 'HtmlOnly'
103
+ end
104
+
105
+ it 'not set' do
106
+ expect(mail_message.track_links).to eq ''
107
+ end
108
+
109
+ end
110
+
111
+ context 'flag set on track_links()' do
112
+
113
+ it 'set' do
114
+ mail_message.track_links(:html_only)
115
+ expect(mail_message.track_links).to eq 'HtmlOnly'
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
44
122
  describe "#html?" do
45
123
  it 'is true for html only email' do
46
- mail_html_message.should be_html
124
+ expect(mail_html_message).to be_html
47
125
  end
48
126
  end
49
127
 
50
128
  describe "#body_html" do
51
129
  it 'returns html body if present' do
52
- mail_html_message.body_html.should == "<b>Hello Sheldon!</b>"
130
+ expect(mail_html_message.body_html).to eq "<b>Hello Sheldon!</b>"
53
131
  end
54
132
  end
55
133
 
56
134
  describe "#body_text" do
57
135
  it 'returns text body if present' do
58
- mail_message.body_text.should == "Hello Sheldon!"
136
+ expect(mail_message.body_text).to eq "Hello Sheldon!"
59
137
  end
60
138
  end
61
139
 
@@ -65,7 +143,7 @@ describe Mail::Message do
65
143
 
66
144
  it "stores attachments as an array" do
67
145
  mail_message.postmark_attachments = attached_hash
68
- mail_message.instance_variable_get(:@_attachments).should include(attached_hash)
146
+ expect(mail_message.instance_variable_get(:@_attachments)).to include(attached_hash)
69
147
  end
70
148
 
71
149
  it "is deprecated" do
@@ -93,8 +171,8 @@ describe Mail::Message do
93
171
  mail_message.postmark_attachments = [attached_hash, attached_file]
94
172
  attachments = mail_message.export_attachments
95
173
 
96
- attachments.should include(attached_hash)
97
- attachments.should include(exported_file)
174
+ expect(attachments).to include(attached_hash)
175
+ expect(attachments).to include(exported_file)
98
176
  end
99
177
 
100
178
  it "is deprecated" do
@@ -116,13 +194,13 @@ describe Mail::Message do
116
194
 
117
195
  it "exports native attachments" do
118
196
  mail_message.attachments["face.jpeg"] = file_data
119
- mail_message.export_attachments.should include(exported_data)
197
+ expect(mail_message.export_attachments).to include(exported_data)
120
198
  end
121
199
 
122
200
  it "still supports the deprecated attachments API" do
123
201
  mail_message.attachments["face.jpeg"] = file_data
124
202
  mail_message.postmark_attachments = exported_data
125
- mail_message.export_attachments.should == [exported_data, exported_data]
203
+ expect(mail_message.export_attachments).to eq [exported_data, exported_data]
126
204
  end
127
205
 
128
206
  end
@@ -132,10 +210,11 @@ describe Mail::Message do
132
210
  it "exports the attachment with related content id" do
133
211
  mail_message.attachments.inline["face.jpeg"] = file_data
134
212
  attachments = mail_message.export_attachments
135
- attachments.count.should_not be_zero
136
- attachments.first.should include(exported_data)
137
- attachments.first.should have_key('ContentID')
138
- attachments.first['ContentID'].should start_with('cid:')
213
+
214
+ expect(attachments.count).to_not be_zero
215
+ expect(attachments.first).to include(exported_data)
216
+ expect(attachments.first).to have_key('ContentID')
217
+ expect(attachments.first['ContentID']).to start_with('cid:')
139
218
  end
140
219
 
141
220
  end
@@ -146,8 +225,8 @@ describe Mail::Message do
146
225
  let(:headers) { mail_message_with_bogus_headers.export_headers }
147
226
  let(:header_names) { headers.map { |h| h['Name'] } }
148
227
 
149
- specify { header_names.should include('Allowed-Header') }
150
- specify { header_names.count.should == 1 }
228
+ specify { expect(header_names).to include('Allowed-Header') }
229
+ specify { expect(header_names.count).to eq 1 }
151
230
  end
152
231
 
153
232
  describe "#to_postmark_hash" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.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: 2016-10-25 00:00:00.000000000 Z
13
+ date: 2016-11-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake