esendex 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/esendex/application_controller.rb +4 -4
  3. data/app/controllers/esendex/inbound_messages_controller.rb +11 -11
  4. data/app/controllers/esendex/message_delivered_events_controller.rb +11 -11
  5. data/app/controllers/esendex/message_failed_events_controller.rb +11 -11
  6. data/app/controllers/esendex/push_notification_handler.rb +41 -41
  7. data/config/routes.rb +5 -5
  8. data/lib/esendex.rb +63 -62
  9. data/lib/esendex/account.rb +44 -44
  10. data/lib/esendex/api_connection.rb +29 -29
  11. data/lib/esendex/dispatcher_result.rb +25 -25
  12. data/lib/esendex/engine.rb +4 -4
  13. data/lib/esendex/exceptions.rb +25 -25
  14. data/lib/esendex/hash_serialisation.rb +23 -23
  15. data/lib/esendex/inbound_message.rb +30 -30
  16. data/lib/esendex/message.rb +38 -38
  17. data/lib/esendex/message_batch_submission.rb +50 -50
  18. data/lib/esendex/message_delivered_event.rb +29 -29
  19. data/lib/esendex/message_failed_event.rb +29 -29
  20. data/lib/esendex/railtie.rb +11 -11
  21. data/lib/esendex/version.rb +3 -3
  22. data/lib/esendex/voice_message.rb +25 -0
  23. data/lib/tasks/esendex.rake +29 -29
  24. data/licence.txt +23 -23
  25. data/readme.md +186 -186
  26. data/spec/account_spec.rb +211 -211
  27. data/spec/api_connection_spec.rb +78 -78
  28. data/spec/controllers/message_delivered_events_controller_spec.rb +29 -29
  29. data/spec/controllers/push_notification_handler_spec.rb +96 -96
  30. data/spec/dummy/README.rdoc +261 -261
  31. data/spec/dummy/Rakefile +7 -7
  32. data/spec/dummy/app/assets/javascripts/application.js +15 -15
  33. data/spec/dummy/app/assets/stylesheets/application.css +13 -13
  34. data/spec/dummy/app/controllers/application_controller.rb +3 -3
  35. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  37. data/spec/dummy/config.ru +4 -4
  38. data/spec/dummy/config/application.rb +66 -66
  39. data/spec/dummy/config/boot.rb +9 -9
  40. data/spec/dummy/config/environment.rb +5 -5
  41. data/spec/dummy/config/environments/development.rb +37 -37
  42. data/spec/dummy/config/environments/production.rb +67 -67
  43. data/spec/dummy/config/environments/test.rb +39 -39
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  45. data/spec/dummy/config/initializers/inflections.rb +15 -15
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -5
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -7
  48. data/spec/dummy/config/initializers/session_store.rb +8 -8
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  50. data/spec/dummy/config/locales/en.yml +5 -5
  51. data/spec/dummy/config/routes.rb +4 -4
  52. data/spec/dummy/public/404.html +26 -26
  53. data/spec/dummy/public/422.html +26 -26
  54. data/spec/dummy/public/500.html +25 -25
  55. data/spec/dummy/script/rails +6 -6
  56. data/spec/hash_serialisation_spec.rb +52 -52
  57. data/spec/inbound_message_spec.rb +42 -42
  58. data/spec/message_batch_submission_spec.rb +54 -54
  59. data/spec/message_delivered_event_spec.rb +32 -32
  60. data/spec/message_failed_event_spec.rb +32 -32
  61. data/spec/message_spec.rb +49 -49
  62. data/spec/spec_helper.rb +41 -41
  63. data/spec/voice_message_spec.rb +29 -0
  64. metadata +12 -9
@@ -1,211 +1,211 @@
1
- require 'spec_helper'
2
-
3
- describe Account do
4
- let(:account_reference) { random_string }
5
- let(:account) { Account.new(account_reference) }
6
- let(:messages_remaining) { random_integer }
7
- let(:account_xml) {
8
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>
9
- <accounts xmlns=\"http://api.esendex.com/ns/\">
10
- <account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\">
11
- <balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining>
12
- <reference>not this one</reference>
13
- <address>447786204254</address>
14
- <type>Professional</type>
15
- <messagesremaining>1234</messagesremaining>
16
- <expireson>2015-12-31T00:00:00</expireson>
17
- <role>PowerUser</role>
18
- <defaultdialcode>44</defaultdialcode>
19
- <settings uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c/settings\" />
20
- </account>
21
- <account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\">
22
- <balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining>
23
- <reference>#{account_reference}</reference>
24
- <address>447786204254</address>
25
- <type>Professional</type>
26
- <messagesremaining>#{messages_remaining}</messagesremaining>
27
- <expireson>2015-12-31T00:00:00</expireson>
28
- <role>PowerUser</role>
29
- <defaultdialcode>44</defaultdialcode>
30
- <settings uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c/settings\" />
31
- </account>
32
- </accounts>"
33
- }
34
- let(:api_connection) { mock("Connection", :get => mock('Response', :body => account_xml), :post => true )}
35
-
36
- before(:each) do
37
- account.stub(:api_connection) { api_connection }
38
- end
39
-
40
- describe "#messages_remaining" do
41
- subject { account.messages_remaining }
42
-
43
- it "should get the account resource" do
44
- api_connection.should_receive(:get).with("/v1.0/accounts")
45
- subject
46
- end
47
-
48
- it "should get the messages remaining from the document" do
49
- subject.should eq(messages_remaining)
50
- end
51
-
52
- context "with invalid reference" do
53
- before(:each) do
54
- account.reference = "invalid"
55
- end
56
-
57
- it "should raise AccountReferenceError" do
58
- expect { account.messages_remaining }.to raise_error(AccountReferenceError)
59
- end
60
- end
61
- end
62
-
63
- describe "#send_message" do
64
- let(:batch_id) { random_string }
65
- let(:send_response_xml) {
66
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>
67
- <messageheaders batchid=\"#{batch_id}\" xmlns=\"http://api.esendex.com/ns/\">
68
- <messageheader\ uri=\"http://api.esendex.com/v1.0/MessageHeaders/00000000-0000-0000-0000-000000000001\" id=\"00000000-0000-0000-0000-000000000001\" />
69
- </messageheaders>"
70
- }
71
-
72
- before(:each) do
73
- api_connection.stub(:post) { mock('Response', :body => send_response_xml) }
74
- end
75
-
76
- subject { account.send_message(to: "447815777555", body: "Hello from the Esendex Ruby Gem") }
77
-
78
- it "should post to the message dispatcher resource" do
79
- api_connection.should_receive(:post).with("/v1.0/messagedispatcher", anything)
80
- subject
81
- end
82
-
83
- it "should return the batch_id when treated as string" do
84
- subject.to_s.should eq(batch_id)
85
- end
86
-
87
- it "should return the batch_id in the result" do
88
- subject.batch_id.should eq(batch_id)
89
- end
90
-
91
- it "should provide a list of messages with a single message" do
92
- subject.messages.should have(1).items
93
- end
94
- end
95
-
96
- describe "#send_messages" do
97
- let(:batch_id) { random_string }
98
- let(:uri_prefix) { "https://api.esendex.com/messages/" }
99
- let(:message_one_id) { random_guid }
100
- let(:message_two_id) { random_guid }
101
- let(:send_response_xml) {
102
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>
103
- <messageheaders batchid=\"#{batch_id}\" xmlns=\"http://api.esendex.com/ns/\">
104
- <messageheader\ uri=\"#{uri_prefix}#{message_one_id}\" id=\"#{message_one_id}\" />
105
- <messageheader\ uri=\"#{uri_prefix}#{message_two_id}\" id=\"#{message_two_id}\" />
106
- </messageheaders>"
107
- }
108
-
109
- before(:each) do
110
- api_connection.stub(:post) { mock('Response', :body => send_response_xml) }
111
- end
112
-
113
- subject { account.send_message(to: "447815777555", body: "Hello from the Esendex Ruby Gem") }
114
-
115
- it "should post to the message dispatcher resource" do
116
- api_connection.should_receive(:post).with("/v1.0/messagedispatcher", anything)
117
- subject
118
- end
119
-
120
- it "should provide a list containing two messages" do
121
- subject.messages.should have(2).items
122
- end
123
-
124
- it "should have message one in the message list" do
125
- subject.messages.should include(id: "#{message_one_id}", uri: "#{uri_prefix}#{message_one_id}")
126
- end
127
-
128
- it "should have message two in the message list" do
129
- subject.messages.should include(id: "#{message_two_id}", uri: "#{uri_prefix}#{message_two_id}")
130
- end
131
- end
132
-
133
- describe "#sent_messages" do
134
- let(:sent_message_client) { stub("sent_message_client") }
135
- let(:sent_messages_result) { Class.new }
136
-
137
- before(:each) do
138
- stub_const("Esendex::SentMessageClient", sent_message_client)
139
- sent_message_client
140
- .should_receive(:new)
141
- .with(api_connection)
142
- .and_return(sent_message_client)
143
- end
144
-
145
- context "with no args" do
146
- before(:each) do
147
- sent_message_client
148
- .should_receive(:get_messages)
149
- .with({account_reference: account_reference})
150
- .and_return(sent_messages_result)
151
- end
152
-
153
- subject { account.sent_messages() }
154
-
155
- it "should return expected result" do
156
- subject.should eq(sent_messages_result)
157
- end
158
- end
159
-
160
- context "with start and finish dates" do
161
- it "should pass dates without adjustment" do
162
- start_date = DateTime.now - 30
163
- finish_date = DateTime.now - 15
164
- sent_message_client
165
- .should_receive(:get_messages)
166
- .with({account_reference: account_reference, start: start_date, finish: finish_date})
167
- .and_return(sent_messages_result)
168
-
169
- account.sent_messages({start: start_date, finish: finish_date}).should_not be_nil
170
- end
171
- end
172
-
173
- context "with start date" do
174
- it "should specify start date and default finish date" do
175
- start_date = DateTime.now - 1
176
- sent_message_client
177
- .should_receive(:get_messages)
178
- .with({account_reference: account_reference, start: start_date})
179
- .and_return(sent_messages_result)
180
-
181
- account.sent_messages({start: start_date}).should_not be_nil
182
- end
183
- end
184
-
185
- context "with finish date" do
186
- it "should specify default start date and finish date" do
187
- finish_date = DateTime.now - 1
188
- start_date = finish_date - 90
189
- sent_message_client
190
- .should_receive(:get_messages)
191
- .with({account_reference: account_reference, finish: finish_date})
192
- .and_return(sent_messages_result)
193
-
194
- account.sent_messages({finish: finish_date}).should_not be_nil
195
- end
196
- end
197
-
198
- context "with start index and count" do
199
- it "should pass expected arguments" do
200
- start_index = 3
201
- count = 35
202
- sent_message_client
203
- .should_receive(:get_messages)
204
- .with({account_reference: account_reference, start_index: start_index, count: count})
205
- .and_return(sent_messages_result)
206
-
207
- account.sent_messages({start_index: start_index, count: count}).should_not be_nil
208
- end
209
- end
210
- end
211
- end
1
+ require 'spec_helper'
2
+
3
+ describe Account do
4
+ let(:account_reference) { random_string }
5
+ let(:account) { Account.new(account_reference) }
6
+ let(:messages_remaining) { random_integer }
7
+ let(:account_xml) {
8
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>
9
+ <accounts xmlns=\"http://api.esendex.com/ns/\">
10
+ <account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\">
11
+ <balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining>
12
+ <reference>not this one</reference>
13
+ <address>447786204254</address>
14
+ <type>Professional</type>
15
+ <messagesremaining>1234</messagesremaining>
16
+ <expireson>2015-12-31T00:00:00</expireson>
17
+ <role>PowerUser</role>
18
+ <defaultdialcode>44</defaultdialcode>
19
+ <settings uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c/settings\" />
20
+ </account>
21
+ <account id=\"2b4a326c-41de-4a57-a577-c7d742dc145c\" uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c\">
22
+ <balanceremaining domesticmessages=\"100\" internationalmessages=\"100\">$0.00</balanceremaining>
23
+ <reference>#{account_reference}</reference>
24
+ <address>447786204254</address>
25
+ <type>Professional</type>
26
+ <messagesremaining>#{messages_remaining}</messagesremaining>
27
+ <expireson>2015-12-31T00:00:00</expireson>
28
+ <role>PowerUser</role>
29
+ <defaultdialcode>44</defaultdialcode>
30
+ <settings uri=\"http://api.esendex.com/v1.0/accounts/2b4a326c-41de-4a57-a577-c7d742dc145c/settings\" />
31
+ </account>
32
+ </accounts>"
33
+ }
34
+ let(:api_connection) { mock("Connection", :get => mock('Response', :body => account_xml), :post => true )}
35
+
36
+ before(:each) do
37
+ account.stub(:api_connection) { api_connection }
38
+ end
39
+
40
+ describe "#messages_remaining" do
41
+ subject { account.messages_remaining }
42
+
43
+ it "should get the account resource" do
44
+ api_connection.should_receive(:get).with("/v1.0/accounts")
45
+ subject
46
+ end
47
+
48
+ it "should get the messages remaining from the document" do
49
+ subject.should eq(messages_remaining)
50
+ end
51
+
52
+ context "with invalid reference" do
53
+ before(:each) do
54
+ account.reference = "invalid"
55
+ end
56
+
57
+ it "should raise AccountReferenceError" do
58
+ expect { account.messages_remaining }.to raise_error(AccountReferenceError)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "#send_message" do
64
+ let(:batch_id) { random_string }
65
+ let(:send_response_xml) {
66
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>
67
+ <messageheaders batchid=\"#{batch_id}\" xmlns=\"http://api.esendex.com/ns/\">
68
+ <messageheader\ uri=\"http://api.esendex.com/v1.0/MessageHeaders/00000000-0000-0000-0000-000000000001\" id=\"00000000-0000-0000-0000-000000000001\" />
69
+ </messageheaders>"
70
+ }
71
+
72
+ before(:each) do
73
+ api_connection.stub(:post) { mock('Response', :body => send_response_xml) }
74
+ end
75
+
76
+ subject { account.send_message(to: "447815777555", body: "Hello from the Esendex Ruby Gem") }
77
+
78
+ it "should post to the message dispatcher resource" do
79
+ api_connection.should_receive(:post).with("/v1.0/messagedispatcher", anything)
80
+ subject
81
+ end
82
+
83
+ it "should return the batch_id when treated as string" do
84
+ subject.to_s.should eq(batch_id)
85
+ end
86
+
87
+ it "should return the batch_id in the result" do
88
+ subject.batch_id.should eq(batch_id)
89
+ end
90
+
91
+ it "should provide a list of messages with a single message" do
92
+ subject.messages.should have(1).items
93
+ end
94
+ end
95
+
96
+ describe "#send_messages" do
97
+ let(:batch_id) { random_string }
98
+ let(:uri_prefix) { "https://api.esendex.com/messages/" }
99
+ let(:message_one_id) { random_guid }
100
+ let(:message_two_id) { random_guid }
101
+ let(:send_response_xml) {
102
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>
103
+ <messageheaders batchid=\"#{batch_id}\" xmlns=\"http://api.esendex.com/ns/\">
104
+ <messageheader\ uri=\"#{uri_prefix}#{message_one_id}\" id=\"#{message_one_id}\" />
105
+ <messageheader\ uri=\"#{uri_prefix}#{message_two_id}\" id=\"#{message_two_id}\" />
106
+ </messageheaders>"
107
+ }
108
+
109
+ before(:each) do
110
+ api_connection.stub(:post) { mock('Response', :body => send_response_xml) }
111
+ end
112
+
113
+ subject { account.send_message(to: "447815777555", body: "Hello from the Esendex Ruby Gem") }
114
+
115
+ it "should post to the message dispatcher resource" do
116
+ api_connection.should_receive(:post).with("/v1.0/messagedispatcher", anything)
117
+ subject
118
+ end
119
+
120
+ it "should provide a list containing two messages" do
121
+ subject.messages.should have(2).items
122
+ end
123
+
124
+ it "should have message one in the message list" do
125
+ subject.messages.should include(id: "#{message_one_id}", uri: "#{uri_prefix}#{message_one_id}")
126
+ end
127
+
128
+ it "should have message two in the message list" do
129
+ subject.messages.should include(id: "#{message_two_id}", uri: "#{uri_prefix}#{message_two_id}")
130
+ end
131
+ end
132
+
133
+ describe "#sent_messages" do
134
+ let(:sent_message_client) { stub("sent_message_client") }
135
+ let(:sent_messages_result) { Class.new }
136
+
137
+ before(:each) do
138
+ stub_const("Esendex::SentMessageClient", sent_message_client)
139
+ sent_message_client
140
+ .should_receive(:new)
141
+ .with(api_connection)
142
+ .and_return(sent_message_client)
143
+ end
144
+
145
+ context "with no args" do
146
+ before(:each) do
147
+ sent_message_client
148
+ .should_receive(:get_messages)
149
+ .with({account_reference: account_reference})
150
+ .and_return(sent_messages_result)
151
+ end
152
+
153
+ subject { account.sent_messages() }
154
+
155
+ it "should return expected result" do
156
+ subject.should eq(sent_messages_result)
157
+ end
158
+ end
159
+
160
+ context "with start and finish dates" do
161
+ it "should pass dates without adjustment" do
162
+ start_date = DateTime.now - 30
163
+ finish_date = DateTime.now - 15
164
+ sent_message_client
165
+ .should_receive(:get_messages)
166
+ .with({account_reference: account_reference, start: start_date, finish: finish_date})
167
+ .and_return(sent_messages_result)
168
+
169
+ account.sent_messages({start: start_date, finish: finish_date}).should_not be_nil
170
+ end
171
+ end
172
+
173
+ context "with start date" do
174
+ it "should specify start date and default finish date" do
175
+ start_date = DateTime.now - 1
176
+ sent_message_client
177
+ .should_receive(:get_messages)
178
+ .with({account_reference: account_reference, start: start_date})
179
+ .and_return(sent_messages_result)
180
+
181
+ account.sent_messages({start: start_date}).should_not be_nil
182
+ end
183
+ end
184
+
185
+ context "with finish date" do
186
+ it "should specify default start date and finish date" do
187
+ finish_date = DateTime.now - 1
188
+ start_date = finish_date - 90
189
+ sent_message_client
190
+ .should_receive(:get_messages)
191
+ .with({account_reference: account_reference, finish: finish_date})
192
+ .and_return(sent_messages_result)
193
+
194
+ account.sent_messages({finish: finish_date}).should_not be_nil
195
+ end
196
+ end
197
+
198
+ context "with start index and count" do
199
+ it "should pass expected arguments" do
200
+ start_index = 3
201
+ count = 35
202
+ sent_message_client
203
+ .should_receive(:get_messages)
204
+ .with({account_reference: account_reference, start_index: start_index, count: count})
205
+ .and_return(sent_messages_result)
206
+
207
+ account.sent_messages({start_index: start_index, count: count}).should_not be_nil
208
+ end
209
+ end
210
+ end
211
+ end
@@ -1,79 +1,79 @@
1
- require 'spec_helper'
2
-
3
- describe ApiConnection do
4
- let(:api_connection) { ApiConnection.new }
5
-
6
- before(:each) do
7
- @connection = Nestful::Connection.new Esendex::API_HOST
8
- Nestful::Connection.stub(:new) { @connection }
9
- @connection.stub(:get) {}
10
- @connection.stub(:post) {}
11
- Esendex.configure do |config|
12
- config.username = random_string
13
- config.password = random_string
14
- end
15
- end
16
-
17
- describe "#initialise" do
18
- subject { ApiConnection.new }
19
-
20
- it "should set the username" do
21
- subject
22
- @connection.user.should eq(Esendex.username)
23
- end
24
-
25
- it "should set the password" do
26
- subject
27
- @connection.password.should eq(Esendex.password)
28
- end
29
-
30
- it "should set the auth to basic" do
31
- subject
32
- @connection.auth_type.should eq(:basic)
33
- end
34
- end
35
-
36
-
37
- describe "#get" do
38
- let(:url) { random_string }
39
-
40
- subject { api_connection.get url }
41
-
42
- it "should call get with headers" do
43
- @connection.should_receive(:get).with(url, api_connection.default_headers)
44
- subject
45
- end
46
-
47
- context "when 403 raised" do
48
- before(:each) do
49
- @connection.stub(:get) { raise Nestful::ForbiddenAccess.new(nil) }
50
- end
51
-
52
- it "raises an ForbiddenError" do
53
- expect { subject }.to raise_error(ForbiddenError)
54
- end
55
- end
56
- end
57
-
58
- describe "#post" do
59
- let(:url) { random_string }
60
- let(:body) { random_string }
61
-
62
- subject { api_connection.post url, body }
63
-
64
- it "should call post with headers" do
65
- @connection.should_receive(:post).with(url, body, api_connection.default_headers)
66
- subject
67
- end
68
-
69
- context "when 403 raised" do
70
- before(:each) do
71
- @connection.stub(:post) { raise Nestful::ForbiddenAccess.new(nil) }
72
- end
73
-
74
- it "raises an ForbiddenError" do
75
- expect { subject }.to raise_error(ForbiddenError)
76
- end
77
- end
78
- end
1
+ require 'spec_helper'
2
+
3
+ describe ApiConnection do
4
+ let(:api_connection) { ApiConnection.new }
5
+
6
+ before(:each) do
7
+ @connection = Nestful::Connection.new Esendex::API_HOST
8
+ Nestful::Connection.stub(:new) { @connection }
9
+ @connection.stub(:get) {}
10
+ @connection.stub(:post) {}
11
+ Esendex.configure do |config|
12
+ config.username = random_string
13
+ config.password = random_string
14
+ end
15
+ end
16
+
17
+ describe "#initialise" do
18
+ subject { ApiConnection.new }
19
+
20
+ it "should set the username" do
21
+ subject
22
+ @connection.user.should eq(Esendex.username)
23
+ end
24
+
25
+ it "should set the password" do
26
+ subject
27
+ @connection.password.should eq(Esendex.password)
28
+ end
29
+
30
+ it "should set the auth to basic" do
31
+ subject
32
+ @connection.auth_type.should eq(:basic)
33
+ end
34
+ end
35
+
36
+
37
+ describe "#get" do
38
+ let(:url) { random_string }
39
+
40
+ subject { api_connection.get url }
41
+
42
+ it "should call get with headers" do
43
+ @connection.should_receive(:get).with(url, api_connection.default_headers)
44
+ subject
45
+ end
46
+
47
+ context "when 403 raised" do
48
+ before(:each) do
49
+ @connection.stub(:get) { raise Nestful::ForbiddenAccess.new(nil) }
50
+ end
51
+
52
+ it "raises an ForbiddenError" do
53
+ expect { subject }.to raise_error(ForbiddenError)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#post" do
59
+ let(:url) { random_string }
60
+ let(:body) { random_string }
61
+
62
+ subject { api_connection.post url, body }
63
+
64
+ it "should call post with headers" do
65
+ @connection.should_receive(:post).with(url, body, api_connection.default_headers)
66
+ subject
67
+ end
68
+
69
+ context "when 403 raised" do
70
+ before(:each) do
71
+ @connection.stub(:post) { raise Nestful::ForbiddenAccess.new(nil) }
72
+ end
73
+
74
+ it "raises an ForbiddenError" do
75
+ expect { subject }.to raise_error(ForbiddenError)
76
+ end
77
+ end
78
+ end
79
79
  end