gocardless_pro 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/README.md +71 -28
  4. data/gocardless_pro.gemspec +1 -1
  5. data/lib/gocardless_pro/api_service.rb +4 -2
  6. data/lib/gocardless_pro/client.rb +2 -1
  7. data/lib/gocardless_pro/error.rb +12 -1
  8. data/lib/gocardless_pro/resources/mandate.rb +3 -0
  9. data/lib/gocardless_pro/resources/payout.rb +3 -0
  10. data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
  11. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
  12. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
  13. data/lib/gocardless_pro/services/creditors_service.rb +5 -2
  14. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
  15. data/lib/gocardless_pro/services/customers_service.rb +5 -2
  16. data/lib/gocardless_pro/services/events_service.rb +2 -1
  17. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
  18. data/lib/gocardless_pro/services/mandates_service.rb +10 -5
  19. data/lib/gocardless_pro/services/payments_service.rb +11 -6
  20. data/lib/gocardless_pro/services/payouts_service.rb +2 -1
  21. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
  22. data/lib/gocardless_pro/services/refunds_service.rb +5 -2
  23. data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
  24. data/lib/gocardless_pro/version.rb +1 -1
  25. data/spec/api_response_spec.rb +4 -4
  26. data/spec/api_service_spec.rb +41 -43
  27. data/spec/client_spec.rb +2 -2
  28. data/spec/error_spec.rb +27 -18
  29. data/spec/resources/bank_details_lookup_spec.rb +19 -34
  30. data/spec/resources/creditor_bank_account_spec.rb +54 -99
  31. data/spec/resources/creditor_spec.rb +66 -115
  32. data/spec/resources/customer_bank_account_spec.rb +54 -99
  33. data/spec/resources/customer_spec.rb +71 -138
  34. data/spec/resources/event_spec.rb +74 -107
  35. data/spec/resources/mandate_pdf_spec.rb +15 -26
  36. data/spec/resources/mandate_spec.rb +54 -87
  37. data/spec/resources/payment_spec.rb +70 -119
  38. data/spec/resources/payout_spec.rb +50 -79
  39. data/spec/resources/redirect_flow_spec.rb +58 -95
  40. data/spec/resources/refund_spec.rb +42 -75
  41. data/spec/resources/subscription_spec.rb +82 -155
  42. data/spec/response_spec.rb +45 -46
  43. data/spec/services/bank_details_lookups_service_spec.rb +55 -60
  44. data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
  45. data/spec/services/creditors_service_spec.rb +290 -333
  46. data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
  47. data/spec/services/customers_service_spec.rb +347 -400
  48. data/spec/services/events_service_spec.rb +154 -184
  49. data/spec/services/mandate_pdfs_service_spec.rb +52 -57
  50. data/spec/services/mandates_service_spec.rb +374 -410
  51. data/spec/services/payments_service_spec.rb +404 -461
  52. data/spec/services/payouts_service_spec.rb +161 -184
  53. data/spec/services/redirect_flows_service_spec.rb +188 -205
  54. data/spec/services/refunds_service_spec.rb +245 -280
  55. data/spec/services/subscriptions_service_spec.rb +423 -485
  56. data/spec/spec_helper.rb +46 -48
  57. metadata +22 -20
@@ -3,457 +3,409 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::CustomerBankAccountsService do
4
4
  let(:client) do
5
5
  GoCardlessPro::Client.new(
6
- access_token: "SECRET_TOKEN"
6
+ access_token: 'SECRET_TOKEN'
7
7
  )
8
8
  end
9
9
 
10
-
11
-
12
-
13
-
14
-
15
-
16
- describe "#create" do
10
+ describe '#create' do
17
11
  subject(:post_create_response) { client.customer_bank_accounts.create(params: new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "account_holder_name" => "account_holder_name-input",
23
- "account_number_ending" => "account_number_ending-input",
24
- "bank_name" => "bank_name-input",
25
- "country_code" => "country_code-input",
26
- "created_at" => "created_at-input",
27
- "currency" => "currency-input",
28
- "enabled" => "enabled-input",
29
- "id" => "id-input",
30
- "links" => "links-input",
31
- "metadata" => "metadata-input",
32
- }
33
- end
12
+ context 'with a valid request' do
13
+ let(:new_resource) do
14
+ {
15
+
16
+ 'account_holder_name' => 'account_holder_name-input',
17
+ 'account_number_ending' => 'account_number_ending-input',
18
+ 'bank_name' => 'bank_name-input',
19
+ 'country_code' => 'country_code-input',
20
+ 'created_at' => 'created_at-input',
21
+ 'currency' => 'currency-input',
22
+ 'enabled' => 'enabled-input',
23
+ 'id' => 'id-input',
24
+ 'links' => 'links-input',
25
+ 'metadata' => 'metadata-input'
26
+ }
27
+ end
34
28
 
35
- before do
36
- stub_request(:post, %r(.*api.gocardless.com/customer_bank_accounts)).
37
- with(
29
+ before do
30
+ stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts})
31
+ .with(
38
32
  body: {
39
- "customer_bank_accounts" => {
40
-
41
- "account_holder_name" => "account_holder_name-input",
42
- "account_number_ending" => "account_number_ending-input",
43
- "bank_name" => "bank_name-input",
44
- "country_code" => "country_code-input",
45
- "created_at" => "created_at-input",
46
- "currency" => "currency-input",
47
- "enabled" => "enabled-input",
48
- "id" => "id-input",
49
- "links" => "links-input",
50
- "metadata" => "metadata-input",
51
- }
33
+ 'customer_bank_accounts' => {
34
+
35
+ 'account_holder_name' => 'account_holder_name-input',
36
+ 'account_number_ending' => 'account_number_ending-input',
37
+ 'bank_name' => 'bank_name-input',
38
+ 'country_code' => 'country_code-input',
39
+ 'created_at' => 'created_at-input',
40
+ 'currency' => 'currency-input',
41
+ 'enabled' => 'enabled-input',
42
+ 'id' => 'id-input',
43
+ 'links' => 'links-input',
44
+ 'metadata' => 'metadata-input'
45
+ }
52
46
  }
53
- ).
54
- to_return(
47
+ )
48
+ .to_return(
55
49
  body: {
56
- "customer_bank_accounts" => {
57
-
58
- "account_holder_name" => "account_holder_name-input",
59
- "account_number_ending" => "account_number_ending-input",
60
- "bank_name" => "bank_name-input",
61
- "country_code" => "country_code-input",
62
- "created_at" => "created_at-input",
63
- "currency" => "currency-input",
64
- "enabled" => "enabled-input",
65
- "id" => "id-input",
66
- "links" => "links-input",
67
- "metadata" => "metadata-input",
50
+ 'customer_bank_accounts' =>
51
+
52
+ {
53
+
54
+ 'account_holder_name' => 'account_holder_name-input',
55
+ 'account_number_ending' => 'account_number_ending-input',
56
+ 'bank_name' => 'bank_name-input',
57
+ 'country_code' => 'country_code-input',
58
+ 'created_at' => 'created_at-input',
59
+ 'currency' => 'currency-input',
60
+ 'enabled' => 'enabled-input',
61
+ 'id' => 'id-input',
62
+ 'links' => 'links-input',
63
+ 'metadata' => 'metadata-input'
68
64
  }
69
- }.to_json,
70
- :headers => {'Content-Type' => 'application/json'}
71
- )
72
- end
73
-
74
- it "creates and returns the resource" do
75
- expect(post_create_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
76
- end
77
- end
78
-
79
- context "with a request that returns a validation error" do
80
- let(:new_resource) { {} }
81
65
 
82
- before do
83
- stub_request(:post, %r(.*api.gocardless.com/customer_bank_accounts)).to_return(
84
- body: {
85
- error: {
86
- type: 'validation_failed',
87
- code: 422,
88
- errors: [
89
- { message: 'test error message', field: 'test_field' }
90
- ]
91
- }
92
66
  }.to_json,
93
- headers: {'Content-Type' => 'application/json'},
94
- status: 422
67
+ headers: { 'Content-Type' => 'application/json' }
95
68
  )
96
- end
97
-
98
- it "throws the correct error" do
99
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
100
- end
101
69
  end
102
- end
103
-
104
-
105
-
106
-
107
-
108
- describe "#list" do
109
- describe "with no filters" do
110
- subject(:get_list_response) { client.customer_bank_accounts.list }
111
70
 
112
- before do
113
- stub_request(:get, %r(.*api.gocardless.com/customer_bank_accounts)).to_return(
114
- body: {
115
- "customer_bank_accounts" => [{
116
-
117
- "account_holder_name" => "account_holder_name-input",
118
- "account_number_ending" => "account_number_ending-input",
119
- "bank_name" => "bank_name-input",
120
- "country_code" => "country_code-input",
121
- "created_at" => "created_at-input",
122
- "currency" => "currency-input",
123
- "enabled" => "enabled-input",
124
- "id" => "id-input",
125
- "links" => "links-input",
126
- "metadata" => "metadata-input",
127
- }],
128
- meta: {
129
- cursors: {
130
- before: nil,
131
- after: "ABC123"
132
- }
133
- }
134
- }.to_json,
135
- :headers => {'Content-Type' => 'application/json'}
136
- )
137
- end
138
-
139
- it "wraps each item in the resource class" do
140
- expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::CustomerBankAccount)
141
-
142
-
143
-
144
- expect(get_list_response.records.first.account_holder_name).to eq("account_holder_name-input")
145
-
146
-
147
-
148
- expect(get_list_response.records.first.account_number_ending).to eq("account_number_ending-input")
149
-
150
-
151
-
152
- expect(get_list_response.records.first.bank_name).to eq("bank_name-input")
153
-
154
-
155
-
156
- expect(get_list_response.records.first.country_code).to eq("country_code-input")
157
-
158
-
159
-
160
- expect(get_list_response.records.first.created_at).to eq("created_at-input")
161
-
162
-
163
-
164
- expect(get_list_response.records.first.currency).to eq("currency-input")
165
-
166
-
167
-
168
- expect(get_list_response.records.first.enabled).to eq("enabled-input")
169
-
170
-
171
-
172
- expect(get_list_response.records.first.id).to eq("id-input")
173
-
174
-
175
-
176
-
177
-
178
- expect(get_list_response.records.first.metadata).to eq("metadata-input")
179
-
180
-
181
- end
182
-
183
- it "exposes the cursors for before and after" do
184
- expect(get_list_response.before).to eq(nil)
185
- expect(get_list_response.after).to eq("ABC123")
186
- end
187
-
188
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
71
+ it 'creates and returns the resource' do
72
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
189
73
  end
190
74
  end
191
75
 
192
- describe "#all" do
193
- let!(:first_response_stub) do
194
- stub_request(:get, %r(.*api.gocardless.com/customer_bank_accounts$)).to_return(
76
+ context 'with a request that returns a validation error' do
77
+ let(:new_resource) { {} }
78
+
79
+ before do
80
+ stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).to_return(
195
81
  body: {
196
- "customer_bank_accounts" => [{
197
-
198
- "account_holder_name" => "account_holder_name-input",
199
- "account_number_ending" => "account_number_ending-input",
200
- "bank_name" => "bank_name-input",
201
- "country_code" => "country_code-input",
202
- "created_at" => "created_at-input",
203
- "currency" => "currency-input",
204
- "enabled" => "enabled-input",
205
- "id" => "id-input",
206
- "links" => "links-input",
207
- "metadata" => "metadata-input",
208
- }],
209
- meta: {
210
- cursors: { after: 'AB345' },
211
- limit: 1
82
+ error: {
83
+ type: 'validation_failed',
84
+ code: 422,
85
+ errors: [
86
+ { message: 'test error message', field: 'test_field' }
87
+ ]
212
88
  }
213
89
  }.to_json,
214
- :headers => {'Content-Type' => 'application/json'}
90
+ headers: { 'Content-Type' => 'application/json' },
91
+ status: 422
215
92
  )
216
93
  end
217
94
 
218
- let!(:second_response_stub) do
219
- stub_request(:get, %r(.*api.gocardless.com/customer_bank_accounts\?after=AB345)).to_return(
95
+ it 'throws the correct error' do
96
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '#list' do
102
+ describe 'with no filters' do
103
+ subject(:get_list_response) { client.customer_bank_accounts.list }
104
+
105
+ before do
106
+ stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts}).to_return(
220
107
  body: {
221
- "customer_bank_accounts" => [{
222
-
223
- "account_holder_name" => "account_holder_name-input",
224
- "account_number_ending" => "account_number_ending-input",
225
- "bank_name" => "bank_name-input",
226
- "country_code" => "country_code-input",
227
- "created_at" => "created_at-input",
228
- "currency" => "currency-input",
229
- "enabled" => "enabled-input",
230
- "id" => "id-input",
231
- "links" => "links-input",
232
- "metadata" => "metadata-input",
108
+ 'customer_bank_accounts' => [{
109
+
110
+ 'account_holder_name' => 'account_holder_name-input',
111
+ 'account_number_ending' => 'account_number_ending-input',
112
+ 'bank_name' => 'bank_name-input',
113
+ 'country_code' => 'country_code-input',
114
+ 'created_at' => 'created_at-input',
115
+ 'currency' => 'currency-input',
116
+ 'enabled' => 'enabled-input',
117
+ 'id' => 'id-input',
118
+ 'links' => 'links-input',
119
+ 'metadata' => 'metadata-input'
233
120
  }],
234
121
  meta: {
235
- limit: 2,
236
- cursors: {}
122
+ cursors: {
123
+ before: nil,
124
+ after: 'ABC123'
125
+ }
237
126
  }
238
127
  }.to_json,
239
- :headers => {'Content-Type' => 'application/json'}
128
+ headers: { 'Content-Type' => 'application/json' }
240
129
  )
241
130
  end
242
131
 
243
- it "automatically makes the extra requests" do
244
- expect(client.customer_bank_accounts.all.to_a.length).to eq(2)
245
- expect(first_response_stub).to have_been_requested
246
- expect(second_response_stub).to have_been_requested
132
+ it 'wraps each item in the resource class' do
133
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::CustomerBankAccount)
134
+
135
+ expect(get_list_response.records.first.account_holder_name).to eq('account_holder_name-input')
136
+
137
+ expect(get_list_response.records.first.account_number_ending).to eq('account_number_ending-input')
138
+
139
+ expect(get_list_response.records.first.bank_name).to eq('bank_name-input')
140
+
141
+ expect(get_list_response.records.first.country_code).to eq('country_code-input')
142
+
143
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
144
+
145
+ expect(get_list_response.records.first.currency).to eq('currency-input')
146
+
147
+ expect(get_list_response.records.first.enabled).to eq('enabled-input')
148
+
149
+ expect(get_list_response.records.first.id).to eq('id-input')
150
+
151
+ expect(get_list_response.records.first.metadata).to eq('metadata-input')
152
+ end
153
+
154
+ it 'exposes the cursors for before and after' do
155
+ expect(get_list_response.before).to eq(nil)
156
+ expect(get_list_response.after).to eq('ABC123')
247
157
  end
158
+
159
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
248
160
  end
161
+ end
249
162
 
250
-
251
-
252
-
163
+ describe '#all' do
164
+ let!(:first_response_stub) do
165
+ stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts$}).to_return(
166
+ body: {
167
+ 'customer_bank_accounts' => [{
168
+
169
+ 'account_holder_name' => 'account_holder_name-input',
170
+ 'account_number_ending' => 'account_number_ending-input',
171
+ 'bank_name' => 'bank_name-input',
172
+ 'country_code' => 'country_code-input',
173
+ 'created_at' => 'created_at-input',
174
+ 'currency' => 'currency-input',
175
+ 'enabled' => 'enabled-input',
176
+ 'id' => 'id-input',
177
+ 'links' => 'links-input',
178
+ 'metadata' => 'metadata-input'
179
+ }],
180
+ meta: {
181
+ cursors: { after: 'AB345' },
182
+ limit: 1
183
+ }
184
+ }.to_json,
185
+ headers: { 'Content-Type' => 'application/json' }
186
+ )
187
+ end
253
188
 
254
-
255
- describe "#get" do
256
- let(:id) { "ID123" }
189
+ let!(:second_response_stub) do
190
+ stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts\?after=AB345}).to_return(
191
+ body: {
192
+ 'customer_bank_accounts' => [{
193
+
194
+ 'account_holder_name' => 'account_holder_name-input',
195
+ 'account_number_ending' => 'account_number_ending-input',
196
+ 'bank_name' => 'bank_name-input',
197
+ 'country_code' => 'country_code-input',
198
+ 'created_at' => 'created_at-input',
199
+ 'currency' => 'currency-input',
200
+ 'enabled' => 'enabled-input',
201
+ 'id' => 'id-input',
202
+ 'links' => 'links-input',
203
+ 'metadata' => 'metadata-input'
204
+ }],
205
+ meta: {
206
+ limit: 2,
207
+ cursors: {}
208
+ }
209
+ }.to_json,
210
+ headers: { 'Content-Type' => 'application/json' }
211
+ )
212
+ end
257
213
 
258
- subject(:get_response) { client.customer_bank_accounts.get(id) }
214
+ it 'automatically makes the extra requests' do
215
+ expect(client.customer_bank_accounts.all.to_a.length).to eq(2)
216
+ expect(first_response_stub).to have_been_requested
217
+ expect(second_response_stub).to have_been_requested
218
+ end
219
+ end
259
220
 
260
- context "passing in a custom header" do
261
- let!(:stub) do
262
- stub_url = "/customer_bank_accounts/:identity".gsub(':identity', id)
263
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
264
- with(headers: { 'Foo' => 'Bar' }).
265
- to_return(
266
- body: {
267
- "customer_bank_accounts" => {
268
-
269
- "account_holder_name" => "account_holder_name-input",
270
- "account_number_ending" => "account_number_ending-input",
271
- "bank_name" => "bank_name-input",
272
- "country_code" => "country_code-input",
273
- "created_at" => "created_at-input",
274
- "currency" => "currency-input",
275
- "enabled" => "enabled-input",
276
- "id" => "id-input",
277
- "links" => "links-input",
278
- "metadata" => "metadata-input",
279
- }
280
- }.to_json,
281
- :headers => {'Content-Type' => 'application/json'}
282
- )
283
- end
284
-
285
- subject(:get_response) do
286
- client.customer_bank_accounts.get(id, headers: {
287
- 'Foo' => 'Bar'
288
- })
289
- end
290
-
291
- it "includes the header" do
292
- get_response
293
- expect(stub).to have_been_requested
294
- end
295
- end
221
+ describe '#get' do
222
+ let(:id) { 'ID123' }
296
223
 
297
- context "when there is a customer_bank_account to return" do
298
- before do
299
- stub_url = "/customer_bank_accounts/:identity".gsub(':identity', id)
300
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
224
+ subject(:get_response) { client.customer_bank_accounts.get(id) }
225
+
226
+ context 'passing in a custom header' do
227
+ let!(:stub) do
228
+ stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
229
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
230
+ .with(headers: { 'Foo' => 'Bar' })
231
+ .to_return(
301
232
  body: {
302
- "customer_bank_accounts" => {
303
-
304
- "account_holder_name" => "account_holder_name-input",
305
- "account_number_ending" => "account_number_ending-input",
306
- "bank_name" => "bank_name-input",
307
- "country_code" => "country_code-input",
308
- "created_at" => "created_at-input",
309
- "currency" => "currency-input",
310
- "enabled" => "enabled-input",
311
- "id" => "id-input",
312
- "links" => "links-input",
313
- "metadata" => "metadata-input",
233
+ 'customer_bank_accounts' => {
234
+
235
+ 'account_holder_name' => 'account_holder_name-input',
236
+ 'account_number_ending' => 'account_number_ending-input',
237
+ 'bank_name' => 'bank_name-input',
238
+ 'country_code' => 'country_code-input',
239
+ 'created_at' => 'created_at-input',
240
+ 'currency' => 'currency-input',
241
+ 'enabled' => 'enabled-input',
242
+ 'id' => 'id-input',
243
+ 'links' => 'links-input',
244
+ 'metadata' => 'metadata-input'
314
245
  }
315
246
  }.to_json,
316
- :headers => {'Content-Type' => 'application/json'}
247
+ headers: { 'Content-Type' => 'application/json' }
317
248
  )
318
- end
319
-
320
- it "wraps the response in a resource" do
321
- expect(get_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
322
- end
323
249
  end
324
250
 
325
- context "when nothing is returned" do
326
- before do
327
- stub_url = "/customer_bank_accounts/:identity".gsub(':identity', id)
328
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
329
- body: "",
330
- headers: { 'Content-Type' => 'application/json' }
331
- )
332
- end
251
+ subject(:get_response) do
252
+ client.customer_bank_accounts.get(id, headers: {
253
+ 'Foo' => 'Bar'
254
+ })
255
+ end
333
256
 
334
- it "returns nil" do
335
- expect(get_response).to be_nil
336
- end
257
+ it 'includes the header' do
258
+ get_response
259
+ expect(stub).to have_been_requested
337
260
  end
338
261
  end
339
262
 
340
-
341
-
342
-
343
-
344
-
345
- describe "#update" do
346
- subject(:put_update_response) { client.customer_bank_accounts.update(id, params: update_params) }
347
- let(:id) { "ABC123" }
263
+ context 'when there is a customer_bank_account to return' do
264
+ before do
265
+ stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
266
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
267
+ body: {
268
+ 'customer_bank_accounts' => {
269
+
270
+ 'account_holder_name' => 'account_holder_name-input',
271
+ 'account_number_ending' => 'account_number_ending-input',
272
+ 'bank_name' => 'bank_name-input',
273
+ 'country_code' => 'country_code-input',
274
+ 'created_at' => 'created_at-input',
275
+ 'currency' => 'currency-input',
276
+ 'enabled' => 'enabled-input',
277
+ 'id' => 'id-input',
278
+ 'links' => 'links-input',
279
+ 'metadata' => 'metadata-input'
280
+ }
281
+ }.to_json,
282
+ headers: { 'Content-Type' => 'application/json' }
283
+ )
284
+ end
348
285
 
349
- context "with a valid request" do
350
- let(:update_params) { { "hello" => "world" } }
286
+ it 'wraps the response in a resource' do
287
+ expect(get_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
288
+ end
289
+ end
351
290
 
352
- let!(:stub) do
353
- stub_url = "/customer_bank_accounts/:identity".gsub(':identity', id)
354
- stub_request(:put, %r(.*api.gocardless.com#{stub_url})).to_return(
355
- body: {
356
- "customer_bank_accounts" => {
357
-
358
- "account_holder_name" => "account_holder_name-input",
359
- "account_number_ending" => "account_number_ending-input",
360
- "bank_name" => "bank_name-input",
361
- "country_code" => "country_code-input",
362
- "created_at" => "created_at-input",
363
- "currency" => "currency-input",
364
- "enabled" => "enabled-input",
365
- "id" => "id-input",
366
- "links" => "links-input",
367
- "metadata" => "metadata-input",
368
- }
369
- }.to_json,
370
- :headers => {'Content-Type' => 'application/json'}
371
- )
372
- end
291
+ context 'when nothing is returned' do
292
+ before do
293
+ stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
294
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
295
+ body: '',
296
+ headers: { 'Content-Type' => 'application/json' }
297
+ )
298
+ end
373
299
 
374
- it "updates and returns the resource" do
375
- expect(put_update_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
376
- expect(stub).to have_been_requested
377
- end
300
+ it 'returns nil' do
301
+ expect(get_response).to be_nil
378
302
  end
379
303
  end
380
-
381
-
382
-
383
-
384
-
385
- describe "#disable" do
386
-
387
-
388
- subject(:post_response) { client.customer_bank_accounts.disable(resource_id) }
389
-
390
- let(:resource_id) { "ABC123" }
304
+ end
305
+
306
+ describe '#update' do
307
+ subject(:put_update_response) { client.customer_bank_accounts.update(id, params: update_params) }
308
+ let(:id) { 'ABC123' }
309
+
310
+ context 'with a valid request' do
311
+ let(:update_params) { { 'hello' => 'world' } }
391
312
 
392
313
  let!(:stub) do
393
- # /customer_bank_accounts/%v/actions/disable
394
- stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
395
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).to_return(
314
+ stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
315
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
396
316
  body: {
397
- "customer_bank_accounts" => {
398
-
399
- "account_holder_name" => "account_holder_name-input",
400
- "account_number_ending" => "account_number_ending-input",
401
- "bank_name" => "bank_name-input",
402
- "country_code" => "country_code-input",
403
- "created_at" => "created_at-input",
404
- "currency" => "currency-input",
405
- "enabled" => "enabled-input",
406
- "id" => "id-input",
407
- "links" => "links-input",
408
- "metadata" => "metadata-input",
317
+ 'customer_bank_accounts' => {
318
+
319
+ 'account_holder_name' => 'account_holder_name-input',
320
+ 'account_number_ending' => 'account_number_ending-input',
321
+ 'bank_name' => 'bank_name-input',
322
+ 'country_code' => 'country_code-input',
323
+ 'created_at' => 'created_at-input',
324
+ 'currency' => 'currency-input',
325
+ 'enabled' => 'enabled-input',
326
+ 'id' => 'id-input',
327
+ 'links' => 'links-input',
328
+ 'metadata' => 'metadata-input'
409
329
  }
410
330
  }.to_json,
411
- headers: {'Content-Type' => 'application/json'},
331
+ headers: { 'Content-Type' => 'application/json' }
412
332
  )
413
333
  end
414
334
 
415
- it "wraps the response and calls the right endpoint" do
416
- expect(post_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
417
-
335
+ it 'updates and returns the resource' do
336
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
418
337
  expect(stub).to have_been_requested
419
338
  end
339
+ end
340
+ end
420
341
 
421
- context "when the request needs a body and custom header" do
422
-
423
- let(:body) { { foo: 'bar' } }
424
- let(:headers) { { 'Foo' => 'Bar' } }
425
- subject(:post_response) { client.customer_bank_accounts.disable(resource_id, body, headers) }
426
-
427
- let(:resource_id) { "ABC123" }
428
-
429
- let!(:stub) do
430
- # /customer_bank_accounts/%v/actions/disable
431
- stub_url = "/customer_bank_accounts/:identity/actions/disable".gsub(':identity', resource_id)
432
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).
433
- with(
342
+ describe '#disable' do
343
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id) }
344
+
345
+ let(:resource_id) { 'ABC123' }
346
+
347
+ let!(:stub) do
348
+ # /customer_bank_accounts/%v/actions/disable
349
+ stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
350
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
351
+ body: {
352
+ 'customer_bank_accounts' => {
353
+
354
+ 'account_holder_name' => 'account_holder_name-input',
355
+ 'account_number_ending' => 'account_number_ending-input',
356
+ 'bank_name' => 'bank_name-input',
357
+ 'country_code' => 'country_code-input',
358
+ 'created_at' => 'created_at-input',
359
+ 'currency' => 'currency-input',
360
+ 'enabled' => 'enabled-input',
361
+ 'id' => 'id-input',
362
+ 'links' => 'links-input',
363
+ 'metadata' => 'metadata-input'
364
+ }
365
+ }.to_json,
366
+ headers: { 'Content-Type' => 'application/json' }
367
+ )
368
+ end
369
+
370
+ it 'wraps the response and calls the right endpoint' do
371
+ expect(post_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
372
+
373
+ expect(stub).to have_been_requested
374
+ end
375
+
376
+ context 'when the request needs a body and custom header' do
377
+ let(:body) { { foo: 'bar' } }
378
+ let(:headers) { { 'Foo' => 'Bar' } }
379
+ subject(:post_response) { client.customer_bank_accounts.disable(resource_id, body, headers) }
380
+
381
+ let(:resource_id) { 'ABC123' }
382
+
383
+ let!(:stub) do
384
+ # /customer_bank_accounts/%v/actions/disable
385
+ stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
386
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/)
387
+ .with(
434
388
  body: { foo: 'bar' },
435
389
  headers: { 'Foo' => 'Bar' }
436
390
  ).to_return(
437
391
  body: {
438
- "customer_bank_accounts" => {
439
-
440
- "account_holder_name" => "account_holder_name-input",
441
- "account_number_ending" => "account_number_ending-input",
442
- "bank_name" => "bank_name-input",
443
- "country_code" => "country_code-input",
444
- "created_at" => "created_at-input",
445
- "currency" => "currency-input",
446
- "enabled" => "enabled-input",
447
- "id" => "id-input",
448
- "links" => "links-input",
449
- "metadata" => "metadata-input",
392
+ 'customer_bank_accounts' => {
393
+
394
+ 'account_holder_name' => 'account_holder_name-input',
395
+ 'account_number_ending' => 'account_number_ending-input',
396
+ 'bank_name' => 'bank_name-input',
397
+ 'country_code' => 'country_code-input',
398
+ 'created_at' => 'created_at-input',
399
+ 'currency' => 'currency-input',
400
+ 'enabled' => 'enabled-input',
401
+ 'id' => 'id-input',
402
+ 'links' => 'links-input',
403
+ 'metadata' => 'metadata-input'
450
404
  }
451
405
  }.to_json,
452
- headers: {'Content-Type' => 'application/json'},
406
+ headers: { 'Content-Type' => 'application/json' }
453
407
  )
454
- end
455
408
  end
456
409
  end
457
-
458
-
410
+ end
459
411
  end