postmark 0.9.19 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.travis.yml +8 -0
  2. data/CHANGELOG.rdoc +20 -0
  3. data/Gemfile +6 -0
  4. data/README.md +351 -91
  5. data/VERSION +1 -1
  6. data/lib/postmark.rb +40 -132
  7. data/lib/postmark/api_client.rb +162 -0
  8. data/lib/postmark/bounce.rb +20 -17
  9. data/lib/postmark/handlers/mail.rb +10 -3
  10. data/lib/postmark/helpers/hash_helper.rb +35 -0
  11. data/lib/postmark/helpers/message_helper.rb +62 -0
  12. data/lib/postmark/http_client.rb +44 -28
  13. data/lib/postmark/inbound.rb +21 -0
  14. data/lib/postmark/inflector.rb +28 -0
  15. data/lib/postmark/message_extensions/mail.rb +50 -5
  16. data/lib/postmark/message_extensions/shared.rb +23 -28
  17. data/lib/postmark/version.rb +1 -1
  18. data/postmark.gemspec +4 -7
  19. data/spec/data/empty.gif +0 -0
  20. data/spec/integration/api_client_hashes_spec.rb +101 -0
  21. data/spec/integration/api_client_messages_spec.rb +127 -0
  22. data/spec/integration/mail_delivery_method_spec.rb +80 -0
  23. data/spec/spec_helper.rb +15 -5
  24. data/spec/support/helpers.rb +11 -0
  25. data/spec/{shared_examples.rb → support/shared_examples.rb} +0 -0
  26. data/spec/unit/postmark/api_client_spec.rb +246 -0
  27. data/spec/unit/postmark/bounce_spec.rb +142 -0
  28. data/spec/unit/postmark/handlers/mail_spec.rb +39 -0
  29. data/spec/unit/postmark/helpers/hash_helper_spec.rb +34 -0
  30. data/spec/unit/postmark/helpers/message_helper_spec.rb +115 -0
  31. data/spec/unit/postmark/http_client_spec.rb +204 -0
  32. data/spec/unit/postmark/inbound_spec.rb +88 -0
  33. data/spec/unit/postmark/inflector_spec.rb +35 -0
  34. data/spec/unit/postmark/json_spec.rb +37 -0
  35. data/spec/unit/postmark/message_extensions/mail_spec.rb +205 -0
  36. data/spec/unit/postmark_spec.rb +164 -0
  37. metadata +45 -93
  38. data/lib/postmark/attachments_fix_for_mail.rb +0 -48
  39. data/lib/postmark/message_extensions/tmail.rb +0 -115
  40. data/spec/bounce_spec.rb +0 -53
  41. data/spec/postmark_spec.rb +0 -253
Binary file
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sending messages as Ruby hashes with Postmark::ApiClient" do
4
+ let(:postmark_message_id_format) { /\w{8}\-\w{4}-\w{4}-\w{4}-\w{12}/ }
5
+ let(:api_client) { Postmark::ApiClient.new('POSTMARK_API_TEST') }
6
+
7
+ let(:message) {
8
+ {
9
+ :from => "sender@postmarkapp.com",
10
+ :to => "recipient@postmarkapp.com",
11
+ :subject => "Mail::Message object",
12
+ :text_body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " \
13
+ "sed do eiusmod tempor incididunt ut labore et dolore " \
14
+ "magna aliqua."
15
+ }
16
+ }
17
+
18
+ let(:message_with_no_body) {
19
+ {
20
+ :from => "sender@postmarkapp.com",
21
+ :to => "recipient@postmarkapp.com",
22
+ }
23
+ }
24
+
25
+ let(:message_with_attachment) {
26
+ message.tap do |m|
27
+ m[:attachments] = [File.open(empty_gif_path)]
28
+ end
29
+ }
30
+
31
+ let(:message_with_invalid_to) {
32
+ {
33
+ :from => "sender@postmarkapp.com",
34
+ :to => "@postmarkapp.com"
35
+ }
36
+ }
37
+
38
+ let(:valid_messages) { [message, message.dup] }
39
+ let(:partially_valid_messages) { [message, message.dup, message_with_no_body] }
40
+ let(:invalid_messages) { [message_with_no_body, message_with_no_body.dup] }
41
+
42
+ context "message by message" do
43
+ it 'delivers a plain text message' do
44
+ api_client.deliver(message).should have_key(:message_id)
45
+ end
46
+
47
+ it 'updates a message object with Message-ID' do
48
+ api_client.deliver(message)[:message_id].
49
+ should =~ postmark_message_id_format
50
+ end
51
+
52
+ it 'returns full Postmark response' do
53
+ api_client.deliver(message).should be_a Hash
54
+ end
55
+
56
+ it 'delivers a message with attachment' do
57
+ api_client.deliver(message_with_attachment).
58
+ should have_key(:message_id)
59
+ end
60
+
61
+ it 'fails to deliver a message without body' do
62
+ expect { api_client.deliver(message_with_no_body) }.
63
+ to raise_error(Postmark::InvalidMessageError)
64
+ end
65
+
66
+ it 'fails to deliver a message with invalid To address' do
67
+ expect { api_client.deliver(message_with_invalid_to) }.
68
+ to raise_error(Postmark::InvalidMessageError)
69
+ end
70
+ end
71
+
72
+ context "in batches" do
73
+ it 'returns as many responses as many messages were sent' do
74
+ api_client.deliver_in_batches(valid_messages).count.should == valid_messages.count
75
+ end
76
+
77
+ context "given custom max_batch_size" do
78
+ before do
79
+ api_client.max_batch_size = 1
80
+ end
81
+
82
+ it 'returns as many responses as many messages were sent' do
83
+ api_client.deliver_in_batches(valid_messages).count.should == valid_messages.count
84
+ end
85
+ end
86
+
87
+ it 'partially delivers a batch of partially valid Mail::Message objects' do
88
+ response = api_client.deliver_in_batches(partially_valid_messages)
89
+ expect(response).to satisfy { |r| r.count { |mr| mr[:error_code].to_i.zero? } == 2 }
90
+ end
91
+
92
+ it "doesn't deliver a batch of invalid Mail::Message objects" do
93
+ response = api_client.deliver_in_batches(invalid_messages)
94
+
95
+ expect(response).to satisfy { |r| r.all? { |mr| !!mr[:error_code] } }
96
+ end
97
+ end
98
+
99
+
100
+
101
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sending Mail::Messages with Postmark::ApiClient" do
4
+ let(:postmark_message_id_format) { /\w{8}\-\w{4}-\w{4}-\w{4}-\w{12}/ }
5
+ let(:api_client) { Postmark::ApiClient.new('POSTMARK_API_TEST') }
6
+
7
+ let(:message) {
8
+ Mail.new do
9
+ from "sender@postmarkapp.com"
10
+ to "recipient@postmarkapp.com"
11
+ subject "Mail::Message object"
12
+ body "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
13
+ "eiusmod tempor incididunt ut labore et dolore magna aliqua."
14
+ end
15
+ }
16
+
17
+ let(:message_with_no_body) {
18
+ Mail.new do
19
+ from "sender@postmarkapp.com"
20
+ to "recipient@postmarkapp.com"
21
+ end
22
+ }
23
+
24
+ let(:message_with_attachment) {
25
+ message.tap do |msg|
26
+ msg.attachments["test.gif"] = File.read(empty_gif_path)
27
+ end
28
+ }
29
+
30
+ let(:message_with_invalid_to) {
31
+ Mail.new do
32
+ from "sender@postmarkapp.com"
33
+ to "@postmarkapp.com"
34
+ end
35
+ }
36
+
37
+ let(:valid_messages) { [message, message.dup] }
38
+ let(:partially_valid_messages) { [message, message.dup, message_with_no_body] }
39
+ let(:invalid_messages) { [message_with_no_body, message_with_no_body.dup] }
40
+
41
+ context "message by message" do
42
+ it 'delivers a plain text message' do
43
+ api_client.deliver_message(message).should have_key(:message_id)
44
+ end
45
+
46
+ it 'updates a message object with Message-ID' do
47
+ api_client.deliver_message(message)[:message_id].
48
+ should =~ postmark_message_id_format
49
+ end
50
+
51
+ it 'returns full Postmark response' do
52
+ api_client.deliver_message(message).should be_a Hash
53
+ end
54
+
55
+ it 'delivers a message with attachment' do
56
+ api_client.deliver_message(message_with_attachment).
57
+ should have_key(:message_id)
58
+ end
59
+
60
+ it 'fails to deliver a message without body' do
61
+ expect { api_client.deliver_message(message_with_no_body) }.
62
+ to raise_error(Postmark::InvalidMessageError)
63
+ end
64
+
65
+ it 'fails to deliver a message with invalid To address' do
66
+ expect { api_client.deliver_message(message_with_invalid_to) }.
67
+ to raise_error(Postmark::InvalidMessageError)
68
+ end
69
+ end
70
+
71
+ context "in batches" do
72
+ it 'delivers a batch of valid Mail::Message objects' do
73
+ expect { api_client.deliver_messages(valid_messages) }.
74
+ to change{valid_messages.all? { |m| m.delivered? }}.
75
+ to true
76
+ end
77
+
78
+ it 'updates delivered messages with Message-IDs' do
79
+ api_client.deliver_messages(valid_messages)
80
+
81
+ expect(valid_messages.all? { |m| m.message_id =~ postmark_message_id_format }).
82
+ to be_true
83
+ end
84
+
85
+ it 'updates delivered messages with related Postmark responses' do
86
+ api_client.deliver_messages(valid_messages)
87
+
88
+ expect(valid_messages.all? { |m| m.postmark_response["To"] == m.to[0] }).
89
+ to be_true
90
+ end
91
+
92
+ it 'returns as many responses as many messages were sent' do
93
+ api_client.deliver_messages(valid_messages).count.should == valid_messages.count
94
+ end
95
+
96
+ context "given custom max_batch_size" do
97
+ before do
98
+ api_client.max_batch_size = 1
99
+ end
100
+
101
+ it 'updates delivered messages with related Postmark responses' do
102
+ api_client.deliver_messages(valid_messages)
103
+
104
+ expect(valid_messages.all? { |m| m.postmark_response["To"] == m.to[0] }).
105
+ to be_true
106
+ end
107
+
108
+ it 'returns as many responses as many messages were sent' do
109
+ api_client.deliver_messages(valid_messages).count.should == valid_messages.count
110
+ end
111
+ end
112
+
113
+ it 'partially delivers a batch of partially valid Mail::Message objects' do
114
+ expect { api_client.deliver_messages(partially_valid_messages) }.
115
+ to change{partially_valid_messages.select { |m| m.delivered? }.count}.
116
+ to 2
117
+ end
118
+
119
+ it "doesn't deliver a batch of invalid Mail::Message objects" do
120
+ expect { api_client.deliver_messages(invalid_messages) }.
121
+ to change{invalid_messages.all? { |m| m.delivered? == false }}.
122
+ to true
123
+
124
+ invalid_messages.should satisfy { |ms| ms.all? { |m| !!m.postmark_response }}
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sending Mail::Messages with delivery_method Mail::Postmark" do
4
+ let(:postmark_message_id_format) { /\w{8}\-\w{4}-\w{4}-\w{4}-\w{12}/ }
5
+
6
+ let(:message) {
7
+ Mail.new do
8
+ from "sender@postmarkapp.com"
9
+ to "recipient@postmarkapp.com"
10
+ subject "Mail::Message object"
11
+ body "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
12
+ "eiusmod tempor incididunt ut labore et dolore magna aliqua."
13
+ delivery_method Mail::Postmark, :api_key => "POSTMARK_API_TEST"
14
+ end
15
+ }
16
+
17
+ let(:tagged_message) {
18
+ message.tap do |m|
19
+ m.tag "postmark-gem"
20
+ end
21
+ }
22
+
23
+ let(:message_with_no_body) {
24
+ Mail.new do
25
+ from "sender@postmarkapp.com"
26
+ to "recipient@postmarkapp.com"
27
+ delivery_method Mail::Postmark, :api_key => "POSTMARK_API_TEST"
28
+ end
29
+ }
30
+
31
+ let(:message_with_attachment) {
32
+ message.tap do |msg|
33
+ msg.attachments["test.gif"] = File.read(File.join(File.dirname(__FILE__), '..', 'data', 'empty.gif'))
34
+ end
35
+ }
36
+
37
+ let(:message_with_invalid_to) {
38
+ Mail.new do
39
+ from "sender@postmarkapp.com"
40
+ to "@postmarkapp.com"
41
+ delivery_method Mail::Postmark, :api_key => "POSTMARK_API_TEST"
42
+ end
43
+ }
44
+
45
+ it 'delivers a plain text message' do
46
+ expect { message.deliver }.to change{message.delivered?}.to(true)
47
+ end
48
+
49
+ it 'updates a message object with Message-ID' do
50
+ expect { message.deliver }.
51
+ to change{message['Message-ID'].to_s}.to(postmark_message_id_format)
52
+ end
53
+
54
+ it 'updates a message object with full postmark response' do
55
+ expect { message.deliver }.
56
+ to change{message.postmark_response}.from(nil)
57
+ end
58
+
59
+ it 'delivers a tagged message' do
60
+ expect { tagged_message.deliver }.
61
+ to change{message.delivered?}.to(true)
62
+ end
63
+
64
+ it 'delivers a message with attachment' do
65
+ expect { message_with_attachment.deliver }.
66
+ to change{message_with_attachment.delivered?}.to(true)
67
+ end
68
+
69
+ it 'fails to deliver a message without body' do
70
+ expect { message_with_no_body.deliver! }.
71
+ to raise_error(Postmark::InvalidMessageError)
72
+ message_with_no_body.should_not be_delivered
73
+ end
74
+
75
+ it 'fails to deliver a message with invalid To address' do
76
+ expect { message_with_invalid_to.deliver! }.
77
+ to raise_error(Postmark::InvalidMessageError)
78
+ message_with_invalid_to.should_not be_delivered
79
+ end
80
+ end
@@ -4,16 +4,15 @@ require 'rubygems'
4
4
  require 'bundler'
5
5
  Bundler.setup(:development)
6
6
  require 'mail'
7
- #require 'tmail'
8
7
  require 'postmark'
9
8
  require 'active_support'
10
9
  require 'json'
11
10
  require 'fakeweb'
12
11
  require 'fakeweb_matcher'
13
- require 'timecop'
14
12
  require 'rspec'
15
13
  require 'rspec/autorun'
16
- require File.join(File.expand_path(File.dirname(__FILE__)), 'shared_examples.rb')
14
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'support', 'shared_examples.rb')
15
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'support', 'helpers.rb')
17
16
 
18
17
  if ENV['JSONGEM']
19
18
  # `JSONGEM=Yajl rake spec`
@@ -22,9 +21,20 @@ if ENV['JSONGEM']
22
21
  end
23
22
 
24
23
  RSpec.configure do |config|
25
- config.filter_run_excluding :ruby => lambda { |version|
26
- RUBY_VERSION.to_s !~ /^#{version.to_s}/
24
+ include Postmark::RSpecHelpers
25
+
26
+ config.filter_run_excluding :skip_for_platform => lambda { |platform|
27
+ RUBY_PLATFORM.to_s =~ /^#{platform.to_s}/
27
28
  }
29
+
30
+ config.before(:each) do
31
+ %w(api_client response_parser_class secure api_key proxy_host proxy_port
32
+ proxy_user proxy_pass host port path_prefix http_open_timeout
33
+ http_read_timeout max_retries).each do |var|
34
+ Postmark.instance_variable_set(:"@#{var}", nil)
35
+ end
36
+ Postmark.response_parser_class = nil
37
+ end
28
38
  end
29
39
 
30
40
  RSpec::Matchers.define :be_serialized_to do |json|
@@ -0,0 +1,11 @@
1
+ module Postmark
2
+ module RSpecHelpers
3
+ def empty_gif_path
4
+ File.join(File.dirname(__FILE__), '..', 'data', 'empty.gif')
5
+ end
6
+
7
+ def encoded_empty_gif_data
8
+ Postmark::MessageHelper.encode_in_base64(File.read(empty_gif_path))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+
3
+ describe Postmark::ApiClient do
4
+
5
+ let(:api_key) { "provided-api-key" }
6
+ let(:max_retries) { 42 }
7
+ let(:message_hash) {
8
+ {
9
+ :from => "support@postmarkapp.com"
10
+ }
11
+ }
12
+ let(:message) {
13
+ Mail.new do
14
+ from "support@postmarkapp.com"
15
+ delivery_method Mail::Postmark
16
+ end
17
+ }
18
+
19
+ let(:api_client) { Postmark::ApiClient.new(api_key) }
20
+ subject { api_client }
21
+
22
+ context "attr readers" do
23
+ it { should respond_to(:http_client) }
24
+ it { should respond_to(:max_retries) }
25
+ end
26
+
27
+ context "when it's created without options" do
28
+
29
+ its(:max_retries) { should eq 3 }
30
+
31
+ end
32
+
33
+ context "when it's created with user options" do
34
+
35
+ subject { Postmark::ApiClient.new(api_key, :max_retries => max_retries,
36
+ :foo => :bar)}
37
+
38
+ its(:max_retries) { should eq max_retries }
39
+
40
+ it 'passes other options to HttpClient instance' do
41
+ Postmark::HttpClient.should_receive(:new).with(api_key, :foo => :bar)
42
+ subject.should be
43
+ end
44
+
45
+ end
46
+
47
+ describe "#api_key=" do
48
+
49
+ let(:api_key) { "new-api-key-value" }
50
+
51
+ it 'assigns the api key to the http client instance' do
52
+ subject.api_key = api_key
53
+ subject.http_client.api_key.should == api_key
54
+ end
55
+
56
+ end
57
+
58
+ describe "#deliver" do
59
+ let(:email) { Postmark::MessageHelper.to_postmark(message_hash) }
60
+ let(:email_json) { Postmark::Json.encode(email) }
61
+ let(:http_client) { subject.http_client }
62
+ let(:response) { {"MessageID" => 42} }
63
+
64
+ it 'converts message hash to Postmark format and posts it to /email' do
65
+ http_client.should_receive(:post).with('email', email_json) { response }
66
+ subject.deliver(message_hash)
67
+ end
68
+
69
+ it 'retries 3 times' do
70
+ 2.times do
71
+ http_client.should_receive(:post).and_raise(Postmark::InternalServerError)
72
+ end
73
+ http_client.should_receive(:post) { response }
74
+ expect { subject.deliver(message_hash) }.not_to raise_error
75
+ end
76
+
77
+ it 'converts response to ruby format' do
78
+ http_client.should_receive(:post).with('email', email_json) { response }
79
+ r = subject.deliver(message_hash)
80
+ r.should have_key(:message_id)
81
+ end
82
+ end
83
+
84
+ describe "#deliver_in_batches" do
85
+ let(:email) { Postmark::MessageHelper.to_postmark(message_hash) }
86
+ let(:emails) { [email, email, email] }
87
+ let(:emails_json) { Postmark::Json.encode(emails) }
88
+ let(:http_client) { subject.http_client }
89
+ let(:response) { [{'ErrorCode' => 0}, {'ErrorCode' => 0}, {'ErrorCode' => 0}] }
90
+
91
+ it 'turns array of messages into a JSON document and posts it to /email/batch' do
92
+ http_client.should_receive(:post).with('email/batch', emails_json) { response }
93
+ subject.deliver_in_batches([message_hash, message_hash, message_hash])
94
+ end
95
+
96
+ it 'converts response to ruby format' do
97
+ http_client.should_receive(:post).with('email/batch', emails_json) { response }
98
+ response = subject.deliver_in_batches([message_hash, message_hash, message_hash])
99
+ response.first.should have_key(:error_code)
100
+ end
101
+ end
102
+
103
+ describe "#deliver_message" do
104
+ let(:email) { message.to_postmark_hash }
105
+ let(:email_json) { JSON.dump(email) }
106
+ let(:http_client) { subject.http_client }
107
+
108
+ it 'turns message into a JSON document and posts it to /email' do
109
+ http_client.should_receive(:post).with('email', email_json)
110
+ subject.deliver_message(message)
111
+ end
112
+
113
+ it "should retry 3 times" do
114
+ 2.times do
115
+ http_client.should_receive(:post).and_raise(Postmark::InternalServerError)
116
+ end
117
+ http_client.should_receive(:post)
118
+ expect { subject.deliver_message(message) }.not_to raise_error
119
+ end
120
+
121
+ it "should retry on timeout" do
122
+ http_client.should_receive(:post).and_raise(Postmark::TimeoutError)
123
+ http_client.should_receive(:post)
124
+ expect { subject.deliver_message(message) }.not_to raise_error
125
+ end
126
+
127
+ end
128
+
129
+ describe "#deliver_messages" do
130
+
131
+ let(:email) { message.to_postmark_hash }
132
+ let(:emails) { [email, email, email] }
133
+ let(:emails_json) { JSON.dump(emails) }
134
+ let(:http_client) { subject.http_client }
135
+ let(:response) { [{}, {}, {}] }
136
+
137
+ it 'turns array of messages into a JSON document and posts it to /email/batch' do
138
+ http_client.should_receive(:post).with('email/batch', emails_json) { response }
139
+ subject.deliver_messages([message, message, message])
140
+ end
141
+
142
+ it "should retry 3 times" do
143
+ 2.times do
144
+ http_client.should_receive(:post).and_raise(Postmark::InternalServerError)
145
+ end
146
+ http_client.should_receive(:post) { response }
147
+ expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
148
+ end
149
+
150
+ it "should retry on timeout" do
151
+ http_client.should_receive(:post).and_raise(Postmark::TimeoutError)
152
+ http_client.should_receive(:post) { response }
153
+ expect { subject.deliver_messages([message, message, message]) }.not_to raise_error
154
+ end
155
+
156
+ end
157
+
158
+ describe "#delivery_stats" do
159
+ let(:http_client) { subject.http_client }
160
+ let(:response) { {"Bounces" => [{"Foo" => "Bar"}]} }
161
+
162
+ it 'requests data at /deliverystats' do
163
+ http_client.should_receive(:get).with("deliverystats") { response }
164
+ subject.delivery_stats.should have_key(:bounces)
165
+ end
166
+ end
167
+
168
+ describe "#get_bounces" do
169
+ let(:http_client) { subject.http_client }
170
+ let(:options) { {:foo => :bar} }
171
+ let(:response) { {"Bounces" => []} }
172
+
173
+ it 'requests data at /bounces' do
174
+ http_client.should_receive(:get).with("bounces", options) { response }
175
+ subject.get_bounces(options).should be_an Array
176
+ end
177
+ end
178
+
179
+ describe "#get_bounced_tags" do
180
+ let(:http_client) { subject.http_client }
181
+
182
+ it 'requests data at /bounces/tags' do
183
+ http_client.should_receive(:get).with("bounces/tags")
184
+ subject.get_bounced_tags
185
+ end
186
+ end
187
+
188
+ describe "#get_bounce" do
189
+ let(:http_client) { subject.http_client }
190
+ let(:id) { 42 }
191
+
192
+ it 'requests a single bounce by ID at /bounces/:id' do
193
+ http_client.should_receive(:get).with("bounces/#{id}")
194
+ subject.get_bounce(id)
195
+ end
196
+ end
197
+
198
+ describe "#dump_bounce" do
199
+ let(:http_client) { subject.http_client }
200
+ let(:id) { 42 }
201
+
202
+ it 'requests a specific bounce data at /bounces/:id/dump' do
203
+ http_client.should_receive(:get).with("bounces/#{id}/dump")
204
+ subject.dump_bounce(id)
205
+ end
206
+ end
207
+
208
+ describe "#activate_bounce" do
209
+ let(:http_client) { subject.http_client }
210
+ let(:id) { 42 }
211
+ let(:response) { {"Bounce" => {}} }
212
+
213
+ it 'activates a specific bounce by sending a PUT request to /bounces/:id/activate' do
214
+ http_client.should_receive(:put).with("bounces/#{id}/activate") { response }
215
+ subject.activate_bounce(id)
216
+ end
217
+ end
218
+
219
+ describe "#server_info" do
220
+ let(:http_client) { subject.http_client }
221
+ let(:response) { {"Name" => "Testing",
222
+ "Color" => "blue",
223
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
224
+ "SmtpApiActivated" => true} }
225
+
226
+ it 'requests server info from Postmark and converts it to ruby format' do
227
+ http_client.should_receive(:get).with('server') { response }
228
+ subject.server_info.should have_key(:inbound_hash)
229
+ end
230
+ end
231
+
232
+ describe "#update_server_info" do
233
+ let(:http_client) { subject.http_client }
234
+ let(:response) { {"Name" => "Testing",
235
+ "Color" => "blue",
236
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
237
+ "SmtpApiActivated" => false} }
238
+ let(:update) { {:smtp_api_activated => false} }
239
+
240
+ it 'updates server info in Postmark and converts it to ruby format' do
241
+ http_client.should_receive(:post).with('server', anything) { response }
242
+ subject.update_server_info(update)[:smtp_api_activated].should be_false
243
+ end
244
+ end
245
+
246
+ end