postmark 1.18.0 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,81 +7,81 @@ describe Postmark::Inbound do
7
7
  context "given a serialized inbound document" do
8
8
  subject { Postmark::Inbound.to_ruby_hash(example_inbound) }
9
9
 
10
- it { should have_key(:from) }
11
- it { should have_key(:from_full) }
12
- it { should have_key(:to) }
13
- it { should have_key(:to_full) }
14
- it { should have_key(:cc) }
15
- it { should have_key(:cc_full) }
16
- it { should have_key(:reply_to) }
17
- it { should have_key(:subject) }
18
- it { should have_key(:message_id) }
19
- it { should have_key(:date) }
20
- it { should have_key(:mailbox_hash) }
21
- it { should have_key(:text_body) }
22
- it { should have_key(:html_body) }
23
- it { should have_key(:tag) }
24
- it { should have_key(:headers) }
25
- it { should have_key(:attachments) }
10
+ it { expect(subject).to have_key(:from) }
11
+ it { expect(subject).to have_key(:from_full) }
12
+ it { expect(subject).to have_key(:to) }
13
+ it { expect(subject).to have_key(:to_full) }
14
+ it { expect(subject).to have_key(:cc) }
15
+ it { expect(subject).to have_key(:cc_full) }
16
+ it { expect(subject).to have_key(:reply_to) }
17
+ it { expect(subject).to have_key(:subject) }
18
+ it { expect(subject).to have_key(:message_id) }
19
+ it { expect(subject).to have_key(:date) }
20
+ it { expect(subject).to have_key(:mailbox_hash) }
21
+ it { expect(subject).to have_key(:text_body) }
22
+ it { expect(subject).to have_key(:html_body) }
23
+ it { expect(subject).to have_key(:tag) }
24
+ it { expect(subject).to have_key(:headers) }
25
+ it { expect(subject).to have_key(:attachments) }
26
26
 
27
27
  context "cc" do
28
28
  it 'has 2 CCs' do
29
- subject[:cc_full].count.should == 2
29
+ expect(subject[:cc_full].count).to eq 2
30
30
  end
31
31
 
32
32
  it 'stores CCs as an array of Ruby hashes' do
33
33
  cc = subject[:cc_full].last
34
- cc.should have_key(:email)
35
- cc.should have_key(:name)
34
+ expect(cc).to have_key(:email)
35
+ expect(cc).to have_key(:name)
36
36
  end
37
37
  end
38
38
 
39
39
  context "to" do
40
40
  it 'has 1 recipients' do
41
- subject[:to_full].count.should == 1
41
+ expect(subject[:to_full].count).to eq 1
42
42
  end
43
43
 
44
44
  it 'stores TOs as an array of Ruby hashes' do
45
45
  cc = subject[:to_full].last
46
- cc.should have_key(:email)
47
- cc.should have_key(:name)
46
+ expect(cc).to have_key(:email)
47
+ expect(cc).to have_key(:name)
48
48
  end
49
49
  end
50
50
 
51
51
  context "from" do
52
52
  it 'is a hash' do
53
- subject[:from_full].should be_a Hash
53
+ expect(subject[:from_full]).to be_a Hash
54
54
  end
55
55
 
56
- it 'should have all required fields' do
57
- subject[:from_full].should have_key(:email)
58
- subject[:from_full].should have_key(:name)
56
+ it 'has all required fields' do
57
+ expect(subject[:from_full]).to have_key(:email)
58
+ expect(subject[:from_full]).to have_key(:name)
59
59
  end
60
60
  end
61
61
 
62
62
  context "headers" do
63
63
  it 'has 8 headers' do
64
- subject[:headers].count.should == 8
64
+ expect(subject[:headers].count).to eq 8
65
65
  end
66
66
 
67
67
  it 'stores headers as an array of Ruby hashes' do
68
68
  header = subject[:headers].last
69
- header.should have_key(:name)
70
- header.should have_key(:value)
69
+ expect(header).to have_key(:name)
70
+ expect(header).to have_key(:value)
71
71
  end
72
72
  end
73
73
 
74
74
  context "attachments" do
75
75
  it 'has 2 attachments' do
76
- subject[:attachments].count.should == 2
76
+ expect(subject[:attachments].count).to eq 2
77
77
  end
78
78
 
79
79
  it 'stores attachemnts as an array of Ruby hashes' do
80
80
  attachment = subject[:attachments].last
81
- attachment.should have_key(:name)
82
- attachment.should have_key(:content)
83
- attachment.should have_key(:content_type)
84
- attachment.should have_key(:content_length)
81
+ expect(attachment).to have_key(:name)
82
+ expect(attachment).to have_key(:content)
83
+ expect(attachment).to have_key(:content_type)
84
+ expect(attachment).to have_key(:content_length)
85
85
  end
86
86
  end
87
87
  end
@@ -1,35 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Postmark::Inflector do
4
-
5
4
  describe ".to_postmark" do
6
5
  it 'converts rubyish underscored format to camel cased symbols accepted by the Postmark API' do
7
- subject.to_postmark(:foo_bar).should == 'FooBar'
8
- subject.to_postmark(:_bar).should == 'Bar'
9
- subject.to_postmark(:really_long_long_long_long_symbol).should == 'ReallyLongLongLongLongSymbol'
10
- subject.to_postmark(:foo_bar_1).should == 'FooBar1'
6
+ expect(subject.to_postmark(:foo_bar)).to eq 'FooBar'
7
+ expect(subject.to_postmark(:_bar)).to eq 'Bar'
8
+ expect(subject.to_postmark(:really_long_long_long_long_symbol)).to eq 'ReallyLongLongLongLongSymbol'
9
+ expect(subject.to_postmark(:foo_bar_1)).to eq 'FooBar1'
11
10
  end
12
11
 
13
12
  it 'accepts strings as well' do
14
- subject.to_postmark('foo_bar').should == 'FooBar'
13
+ expect(subject.to_postmark('foo_bar')).to eq 'FooBar'
15
14
  end
16
15
 
17
16
  it 'acts idempotentely' do
18
- subject.to_postmark('FooBar').should == 'FooBar'
17
+ expect(subject.to_postmark('FooBar')).to eq 'FooBar'
19
18
  end
20
19
  end
21
20
 
22
21
  describe ".to_ruby" do
23
22
  it 'converts camel cased symbols returned by the Postmark API to underscored Ruby symbols' do
24
- subject.to_ruby('FooBar').should == :foo_bar
25
- subject.to_ruby('LongTimeAgoInAFarFarGalaxy').should == :long_time_ago_in_a_far_far_galaxy
26
- subject.to_ruby('MessageID').should == :message_id
23
+ expect(subject.to_ruby('FooBar')).to eq :foo_bar
24
+ expect(subject.to_ruby('LongTimeAgoInAFarFarGalaxy')).to eq :long_time_ago_in_a_far_far_galaxy
25
+ expect(subject.to_ruby('MessageID')).to eq :message_id
27
26
  end
28
27
 
29
28
  it 'acts idempotentely' do
30
- subject.to_ruby(:foo_bar).should == :foo_bar
31
- subject.to_ruby(:foo_bar_1).should == :foo_bar_1
29
+ expect(subject.to_ruby(:foo_bar)).to eq :foo_bar
30
+ expect(subject.to_ruby(:foo_bar_1)).to eq :foo_bar_1
32
31
  end
33
32
  end
34
-
35
33
  end
@@ -6,8 +6,8 @@ describe Postmark::Json do
6
6
  shared_examples "json parser" do
7
7
  it 'encodes and decodes data correctly' do
8
8
  hash = Postmark::Json.decode(Postmark::Json.encode(data))
9
- hash.should have_key("bar")
10
- hash.should have_key("foo")
9
+ expect(hash).to have_key("bar")
10
+ expect(hash).to have_key("foo")
11
11
  end
12
12
  end
13
13
 
@@ -2,23 +2,22 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Postmark::MailMessageConverter do
5
-
6
- subject { Postmark::MailMessageConverter }
5
+ subject {Postmark::MailMessageConverter}
7
6
 
8
7
  let(:mail_message) do
9
8
  Mail.new do
10
- from "sheldon@bigbangtheory.com"
11
- to "lenard@bigbangtheory.com"
9
+ from "sheldon@bigbangtheory.com"
10
+ to "lenard@bigbangtheory.com"
12
11
  subject "Hello!"
13
- body "Hello Sheldon!"
12
+ body "Hello Sheldon!"
14
13
  end
15
14
  end
16
15
 
17
16
  let(:mail_html_message) do
18
17
  Mail.new do
19
- from "sheldon@bigbangtheory.com"
20
- to "lenard@bigbangtheory.com"
21
- subject "Hello!"
18
+ from "sheldon@bigbangtheory.com"
19
+ to "lenard@bigbangtheory.com"
20
+ subject "Hello!"
22
21
  content_type 'text/html; charset=UTF-8'
23
22
  body "<b>Hello Sheldon!</b>"
24
23
  end
@@ -26,41 +25,41 @@ describe Postmark::MailMessageConverter do
26
25
 
27
26
  let(:mail_message_with_open_tracking) do
28
27
  Mail.new do
29
- from "sheldon@bigbangtheory.com"
30
- to "lenard@bigbangtheory.com"
31
- subject "Hello!"
32
- content_type 'text/html; charset=UTF-8'
33
- body "<b>Hello Sheldon!</b>"
34
- track_opens true
28
+ from "sheldon@bigbangtheory.com"
29
+ to "lenard@bigbangtheory.com"
30
+ subject "Hello!"
31
+ content_type 'text/html; charset=UTF-8'
32
+ body "<b>Hello Sheldon!</b>"
33
+ track_opens true
35
34
  end
36
35
  end
37
36
 
38
37
  let(:mail_message_with_open_tracking_disabled) do
39
38
  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
39
+ from "sheldon@bigbangtheory.com"
40
+ to "lenard@bigbangtheory.com"
41
+ subject "Hello!"
42
+ content_type 'text/html; charset=UTF-8'
43
+ body "<b>Hello Sheldon!</b>"
44
+ track_opens false
46
45
  end
47
46
  end
48
47
 
49
48
  let(:mail_message_with_open_tracking_set_variable) do
50
49
  mail = mail_html_message
51
- mail.track_opens=true
50
+ mail.track_opens = true
52
51
  mail
53
52
  end
54
53
 
55
54
  let(:mail_message_with_open_tracking_disabled_set_variable) do
56
55
  mail = mail_html_message
57
- mail.track_opens=false
56
+ mail.track_opens = false
58
57
  mail
59
58
  end
60
59
 
61
60
  let(:mail_message_with_link_tracking_all) do
62
61
  mail = mail_html_message
63
- mail.track_links :html_and_text
62
+ mail.track_links :html_and_text
64
63
  mail
65
64
  end
66
65
 
@@ -84,73 +83,73 @@ describe Postmark::MailMessageConverter do
84
83
 
85
84
  let(:tagged_mail_message) do
86
85
  Mail.new do
87
- from "sheldon@bigbangtheory.com"
88
- to "lenard@bigbangtheory.com"
86
+ from "sheldon@bigbangtheory.com"
87
+ to "lenard@bigbangtheory.com"
89
88
  subject "Hello!"
90
- body "Hello Sheldon!"
91
- tag "sheldon"
89
+ body "Hello Sheldon!"
90
+ tag "sheldon"
92
91
  end
93
92
  end
94
93
 
95
94
  let(:mail_message_without_body) do
96
95
  Mail.new do
97
- from "sheldon@bigbangtheory.com"
98
- to "lenard@bigbangtheory.com"
96
+ from "sheldon@bigbangtheory.com"
97
+ to "lenard@bigbangtheory.com"
99
98
  subject "Hello!"
100
99
  end
101
100
  end
102
101
 
103
102
  let(:mail_multipart_message) do
104
103
  Mail.new do
105
- from "sheldon@bigbangtheory.com"
106
- to "lenard@bigbangtheory.com"
107
- subject "Hello!"
104
+ from "sheldon@bigbangtheory.com"
105
+ to "lenard@bigbangtheory.com"
106
+ subject "Hello!"
108
107
  text_part do
109
- body "Hello Sheldon!"
108
+ body "Hello Sheldon!"
110
109
  end
111
110
  html_part do
112
- body "<b>Hello Sheldon!</b>"
111
+ body "<b>Hello Sheldon!</b>"
113
112
  end
114
113
  end
115
114
  end
116
115
 
117
116
  let(:mail_message_with_attachment) do
118
117
  Mail.new do
119
- from "sheldon@bigbangtheory.com"
120
- to "lenard@bigbangtheory.com"
118
+ from "sheldon@bigbangtheory.com"
119
+ to "lenard@bigbangtheory.com"
121
120
  subject "Hello!"
122
- body "Hello Sheldon!"
121
+ body "Hello Sheldon!"
123
122
  add_file empty_gif_path
124
123
  end
125
124
  end
126
125
 
127
126
  let(:mail_message_with_named_addresses) do
128
127
  Mail.new do
129
- from "Sheldon <sheldon@bigbangtheory.com>"
130
- to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
128
+ from "Sheldon <sheldon@bigbangtheory.com>"
129
+ to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
131
130
  subject "Hello!"
132
- body "Hello Sheldon!"
131
+ body "Hello Sheldon!"
133
132
  reply_to '"Penny The Neighbor" <penny@bigbangtheory.com>'
134
133
  end
135
134
  end
136
135
 
137
136
  let(:mail_message_quoted_printable) do
138
137
  Mail.new do
139
- from "Sheldon <sheldon@bigbangtheory.com>"
140
- to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
138
+ from "Sheldon <sheldon@bigbangtheory.com>"
139
+ to "\"Leonard Hofstadter\" <leonard@bigbangtheory.com>"
141
140
  subject "Hello!"
142
141
  content_type 'text/plain; charset=utf-8'
143
142
  content_transfer_encoding 'quoted-printable'
144
- body 'Он здесь бывал: еще не в галифе.'
143
+ body 'Он здесь бывал: еще не в галифе.'
145
144
  reply_to '"Penny The Neighbor" <penny@bigbangtheory.com>'
146
145
  end
147
146
  end
148
147
 
149
148
  let(:multipart_message_quoted_printable) do
150
149
  Mail.new do
151
- from "sheldon@bigbangtheory.com"
152
- to "lenard@bigbangtheory.com"
153
- subject "Hello!"
150
+ from "sheldon@bigbangtheory.com"
151
+ to "lenard@bigbangtheory.com"
152
+ subject "Hello!"
154
153
  text_part do
155
154
  content_type 'text/plain; charset=utf-8'
156
155
  content_transfer_encoding 'quoted-printable'
@@ -166,80 +165,80 @@ describe Postmark::MailMessageConverter do
166
165
 
167
166
  let(:templated_message) do
168
167
  Mail.new do
169
- from "sheldon@bigbangtheory.com"
170
- to "lenard@bigbangtheory.com"
171
- template_alias "hello"
172
- template_model :name => "Sheldon"
168
+ from "sheldon@bigbangtheory.com"
169
+ to "lenard@bigbangtheory.com"
170
+ template_alias "hello"
171
+ template_model :name => "Sheldon"
173
172
  end
174
173
  end
175
174
 
176
175
  it 'converts plain text messages correctly' do
177
- subject.new(mail_message).run.should == {
176
+ expect(subject.new(mail_message).run).to eq ({
178
177
  "From" => "sheldon@bigbangtheory.com",
179
178
  "Subject" => "Hello!",
180
179
  "TextBody" => "Hello Sheldon!",
181
- "To" => "lenard@bigbangtheory.com"}
180
+ "To" => "lenard@bigbangtheory.com"})
182
181
  end
183
182
 
184
183
  it 'converts tagged text messages correctly' do
185
- subject.new(tagged_mail_message).run.should == {
184
+ expect(subject.new(tagged_mail_message).run).to eq ({
186
185
  "From" => "sheldon@bigbangtheory.com",
187
186
  "Subject" => "Hello!",
188
187
  "TextBody" => "Hello Sheldon!",
189
188
  "Tag" => "sheldon",
190
- "To"=>"lenard@bigbangtheory.com"}
189
+ "To" => "lenard@bigbangtheory.com"})
191
190
  end
192
191
 
193
192
  it 'converts plain text messages without body correctly' do
194
- subject.new(mail_message_without_body).run.should == {
193
+ expect(subject.new(mail_message_without_body).run).to eq ({
195
194
  "From" => "sheldon@bigbangtheory.com",
196
195
  "Subject" => "Hello!",
197
- "To" => "lenard@bigbangtheory.com"}
196
+ "To" => "lenard@bigbangtheory.com"})
198
197
  end
199
198
 
200
199
  it 'converts html messages correctly' do
201
- subject.new(mail_html_message).run.should == {
200
+ expect(subject.new(mail_html_message).run).to eq ({
202
201
  "From" => "sheldon@bigbangtheory.com",
203
202
  "Subject" => "Hello!",
204
203
  "HtmlBody" => "<b>Hello Sheldon!</b>",
205
- "To" => "lenard@bigbangtheory.com"}
204
+ "To" => "lenard@bigbangtheory.com"})
206
205
  end
207
206
 
208
207
  it 'converts multipart messages correctly' do
209
- subject.new(mail_multipart_message).run.should == {
208
+ expect(subject.new(mail_multipart_message).run).to eq ({
210
209
  "From" => "sheldon@bigbangtheory.com",
211
210
  "Subject" => "Hello!",
212
211
  "HtmlBody" => "<b>Hello Sheldon!</b>",
213
212
  "TextBody" => "Hello Sheldon!",
214
- "To" => "lenard@bigbangtheory.com"}
213
+ "To" => "lenard@bigbangtheory.com"})
215
214
  end
216
215
 
217
216
  it 'converts messages with attachments correctly' do
218
- subject.new(mail_message_with_attachment).run.should == {
217
+ expect(subject.new(mail_message_with_attachment).run).to eq ({
219
218
  "From" => "sheldon@bigbangtheory.com",
220
219
  "Subject" => "Hello!",
221
- "Attachments" => [{"Name"=>"empty.gif",
222
- "Content"=>encoded_empty_gif_data,
223
- "ContentType"=>"image/gif"}],
224
- "TextBody"=>"Hello Sheldon!",
225
- "To"=>"lenard@bigbangtheory.com"}
220
+ "Attachments" => [{"Name" => "empty.gif",
221
+ "Content" => encoded_empty_gif_data,
222
+ "ContentType" => "image/gif"}],
223
+ "TextBody" => "Hello Sheldon!",
224
+ "To" => "lenard@bigbangtheory.com"})
226
225
  end
227
226
 
228
227
  it 'converts messages with named addresses correctly' do
229
- subject.new(mail_message_with_named_addresses).run.should == {
228
+ expect(subject.new(mail_message_with_named_addresses).run).to eq ({
230
229
  "From" => "Sheldon <sheldon@bigbangtheory.com>",
231
230
  "Subject" => "Hello!",
232
231
  "TextBody" => "Hello Sheldon!",
233
232
  "To" => "Leonard Hofstadter <leonard@bigbangtheory.com>",
234
- "ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>'}
233
+ "ReplyTo" => 'Penny The Neighbor <penny@bigbangtheory.com>'})
235
234
  end
236
235
 
237
236
  it 'convertes templated messages correctly' do
238
- expect(subject.new(templated_message).run).
239
- to eq("From" => "sheldon@bigbangtheory.com",
240
- "TemplateAlias" => "hello",
241
- "TemplateModel" => { :name => "Sheldon" },
242
- "To" => "lenard@bigbangtheory.com")
237
+ expect(subject.new(templated_message).run).to eq({
238
+ "From" => "sheldon@bigbangtheory.com",
239
+ "TemplateAlias" => "hello",
240
+ "TemplateModel" => {:name => "Sheldon"},
241
+ "To" => "lenard@bigbangtheory.com"})
243
242
  end
244
243
 
245
244
  context 'open tracking' do
@@ -345,7 +344,7 @@ describe Postmark::MailMessageConverter do
345
344
 
346
345
  it 'converts multiple metadata fields' do
347
346
  metadata = {}
348
- 10.times { |i| metadata["test#{i+1}"] = "t"*80 }
347
+ 10.times {|i| metadata["test#{i + 1}"] = "t" * 80}
349
348
  msg = mail_html_message
350
349
  msg.metadata = metadata
351
350
  expect(subject.new(msg).run).to include('Metadata' => metadata)
@@ -353,28 +352,26 @@ describe Postmark::MailMessageConverter do
353
352
  end
354
353
 
355
354
  it 'correctly decodes unicode in messages transfered as quoted-printable' do
356
- subject.new(mail_message_quoted_printable).run.should \
357
- include('TextBody' => 'Он здесь бывал: еще не в галифе.')
355
+ expect(subject.new(mail_message_quoted_printable).run).to include('TextBody' => 'Он здесь бывал: еще не в галифе.')
358
356
  end
359
357
 
360
358
  it 'correctly decodes unicode in multipart quoted-printable messages' do
361
- subject.new(multipart_message_quoted_printable).run.should \
362
- include('TextBody' => 'Загадочное послание.',
363
- 'HtmlBody' => '<b>Загадочное послание.</b>')
359
+ expect(subject.new(multipart_message_quoted_printable).run).to include(
360
+ 'TextBody' => 'Загадочное послание.',
361
+ 'HtmlBody' => '<b>Загадочное послание.</b>')
364
362
  end
365
363
 
366
364
  context 'when bcc is empty' do
367
365
  it 'excludes bcc from message' do
368
366
  mail_message.bcc = nil
369
- mail_message.to_postmark_hash.keys.should_not include('Bcc')
367
+ expect(mail_message.to_postmark_hash.keys).not_to include('Bcc')
370
368
  end
371
369
  end
372
370
 
373
371
  context 'when cc is empty' do
374
372
  it 'excludes cc from message' do
375
373
  mail_message.cc = nil
376
- mail_message.to_postmark_hash.keys.should_not include('Cc')
374
+ expect(mail_message.to_postmark_hash.keys).not_to include('Cc')
377
375
  end
378
376
  end
379
-
380
377
  end