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,562 +3,500 @@ require 'spec_helper'
3
3
  describe GoCardlessPro::Services::SubscriptionsService 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.subscriptions.create(params: new_resource) }
18
- context "with a valid request" do
19
- let(:new_resource) do
20
- {
21
-
22
- "amount" => "amount-input",
23
- "count" => "count-input",
24
- "created_at" => "created_at-input",
25
- "currency" => "currency-input",
26
- "day_of_month" => "day_of_month-input",
27
- "end_date" => "end_date-input",
28
- "id" => "id-input",
29
- "interval" => "interval-input",
30
- "interval_unit" => "interval_unit-input",
31
- "links" => "links-input",
32
- "metadata" => "metadata-input",
33
- "month" => "month-input",
34
- "name" => "name-input",
35
- "payment_reference" => "payment_reference-input",
36
- "start_date" => "start_date-input",
37
- "status" => "status-input",
38
- "upcoming_payments" => "upcoming_payments-input",
39
- }
40
- end
12
+ context 'with a valid request' do
13
+ let(:new_resource) do
14
+ {
15
+
16
+ 'amount' => 'amount-input',
17
+ 'count' => 'count-input',
18
+ 'created_at' => 'created_at-input',
19
+ 'currency' => 'currency-input',
20
+ 'day_of_month' => 'day_of_month-input',
21
+ 'end_date' => 'end_date-input',
22
+ 'id' => 'id-input',
23
+ 'interval' => 'interval-input',
24
+ 'interval_unit' => 'interval_unit-input',
25
+ 'links' => 'links-input',
26
+ 'metadata' => 'metadata-input',
27
+ 'month' => 'month-input',
28
+ 'name' => 'name-input',
29
+ 'payment_reference' => 'payment_reference-input',
30
+ 'start_date' => 'start_date-input',
31
+ 'status' => 'status-input',
32
+ 'upcoming_payments' => 'upcoming_payments-input'
33
+ }
34
+ end
41
35
 
42
- before do
43
- stub_request(:post, %r(.*api.gocardless.com/subscriptions)).
44
- with(
36
+ before do
37
+ stub_request(:post, %r{.*api.gocardless.com/subscriptions})
38
+ .with(
45
39
  body: {
46
- "subscriptions" => {
47
-
48
- "amount" => "amount-input",
49
- "count" => "count-input",
50
- "created_at" => "created_at-input",
51
- "currency" => "currency-input",
52
- "day_of_month" => "day_of_month-input",
53
- "end_date" => "end_date-input",
54
- "id" => "id-input",
55
- "interval" => "interval-input",
56
- "interval_unit" => "interval_unit-input",
57
- "links" => "links-input",
58
- "metadata" => "metadata-input",
59
- "month" => "month-input",
60
- "name" => "name-input",
61
- "payment_reference" => "payment_reference-input",
62
- "start_date" => "start_date-input",
63
- "status" => "status-input",
64
- "upcoming_payments" => "upcoming_payments-input",
65
- }
40
+ 'subscriptions' => {
41
+
42
+ 'amount' => 'amount-input',
43
+ 'count' => 'count-input',
44
+ 'created_at' => 'created_at-input',
45
+ 'currency' => 'currency-input',
46
+ 'day_of_month' => 'day_of_month-input',
47
+ 'end_date' => 'end_date-input',
48
+ 'id' => 'id-input',
49
+ 'interval' => 'interval-input',
50
+ 'interval_unit' => 'interval_unit-input',
51
+ 'links' => 'links-input',
52
+ 'metadata' => 'metadata-input',
53
+ 'month' => 'month-input',
54
+ 'name' => 'name-input',
55
+ 'payment_reference' => 'payment_reference-input',
56
+ 'start_date' => 'start_date-input',
57
+ 'status' => 'status-input',
58
+ 'upcoming_payments' => 'upcoming_payments-input'
59
+ }
66
60
  }
67
- ).
68
- to_return(
61
+ )
62
+ .to_return(
69
63
  body: {
70
- "subscriptions" => {
71
-
72
- "amount" => "amount-input",
73
- "count" => "count-input",
74
- "created_at" => "created_at-input",
75
- "currency" => "currency-input",
76
- "day_of_month" => "day_of_month-input",
77
- "end_date" => "end_date-input",
78
- "id" => "id-input",
79
- "interval" => "interval-input",
80
- "interval_unit" => "interval_unit-input",
81
- "links" => "links-input",
82
- "metadata" => "metadata-input",
83
- "month" => "month-input",
84
- "name" => "name-input",
85
- "payment_reference" => "payment_reference-input",
86
- "start_date" => "start_date-input",
87
- "status" => "status-input",
88
- "upcoming_payments" => "upcoming_payments-input",
64
+ 'subscriptions' =>
65
+
66
+ {
67
+
68
+ 'amount' => 'amount-input',
69
+ 'count' => 'count-input',
70
+ 'created_at' => 'created_at-input',
71
+ 'currency' => 'currency-input',
72
+ 'day_of_month' => 'day_of_month-input',
73
+ 'end_date' => 'end_date-input',
74
+ 'id' => 'id-input',
75
+ 'interval' => 'interval-input',
76
+ 'interval_unit' => 'interval_unit-input',
77
+ 'links' => 'links-input',
78
+ 'metadata' => 'metadata-input',
79
+ 'month' => 'month-input',
80
+ 'name' => 'name-input',
81
+ 'payment_reference' => 'payment_reference-input',
82
+ 'start_date' => 'start_date-input',
83
+ 'status' => 'status-input',
84
+ 'upcoming_payments' => 'upcoming_payments-input'
89
85
  }
90
- }.to_json,
91
- :headers => {'Content-Type' => 'application/json'}
92
- )
93
- end
94
-
95
- it "creates and returns the resource" do
96
- expect(post_create_response).to be_a(GoCardlessPro::Resources::Subscription)
97
- end
98
- end
99
86
 
100
- context "with a request that returns a validation error" do
101
- let(:new_resource) { {} }
102
-
103
- before do
104
- stub_request(:post, %r(.*api.gocardless.com/subscriptions)).to_return(
105
- body: {
106
- error: {
107
- type: 'validation_failed',
108
- code: 422,
109
- errors: [
110
- { message: 'test error message', field: 'test_field' }
111
- ]
112
- }
113
87
  }.to_json,
114
- headers: {'Content-Type' => 'application/json'},
115
- status: 422
88
+ headers: { 'Content-Type' => 'application/json' }
116
89
  )
117
- end
118
-
119
- it "throws the correct error" do
120
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
121
- end
122
90
  end
123
- end
124
-
125
-
126
-
127
-
128
-
129
- describe "#list" do
130
- describe "with no filters" do
131
- subject(:get_list_response) { client.subscriptions.list }
132
91
 
133
- before do
134
- stub_request(:get, %r(.*api.gocardless.com/subscriptions)).to_return(
135
- body: {
136
- "subscriptions" => [{
137
-
138
- "amount" => "amount-input",
139
- "count" => "count-input",
140
- "created_at" => "created_at-input",
141
- "currency" => "currency-input",
142
- "day_of_month" => "day_of_month-input",
143
- "end_date" => "end_date-input",
144
- "id" => "id-input",
145
- "interval" => "interval-input",
146
- "interval_unit" => "interval_unit-input",
147
- "links" => "links-input",
148
- "metadata" => "metadata-input",
149
- "month" => "month-input",
150
- "name" => "name-input",
151
- "payment_reference" => "payment_reference-input",
152
- "start_date" => "start_date-input",
153
- "status" => "status-input",
154
- "upcoming_payments" => "upcoming_payments-input",
155
- }],
156
- meta: {
157
- cursors: {
158
- before: nil,
159
- after: "ABC123"
160
- }
161
- }
162
- }.to_json,
163
- :headers => {'Content-Type' => 'application/json'}
164
- )
165
- end
166
-
167
- it "wraps each item in the resource class" do
168
- expect(get_list_response.records.map { |x| x.class }.uniq.first).to eq(GoCardlessPro::Resources::Subscription)
169
-
170
-
171
-
172
- expect(get_list_response.records.first.amount).to eq("amount-input")
173
-
174
-
175
-
176
- expect(get_list_response.records.first.count).to eq("count-input")
177
-
178
-
179
-
180
- expect(get_list_response.records.first.created_at).to eq("created_at-input")
181
-
182
-
183
-
184
- expect(get_list_response.records.first.currency).to eq("currency-input")
185
-
186
-
187
-
188
- expect(get_list_response.records.first.day_of_month).to eq("day_of_month-input")
189
-
190
-
191
-
192
- expect(get_list_response.records.first.end_date).to eq("end_date-input")
193
-
194
-
195
-
196
- expect(get_list_response.records.first.id).to eq("id-input")
197
-
198
-
199
-
200
- expect(get_list_response.records.first.interval).to eq("interval-input")
201
-
202
-
203
-
204
- expect(get_list_response.records.first.interval_unit).to eq("interval_unit-input")
205
-
206
-
207
-
208
-
209
-
210
- expect(get_list_response.records.first.metadata).to eq("metadata-input")
211
-
212
-
213
-
214
- expect(get_list_response.records.first.month).to eq("month-input")
215
-
216
-
217
-
218
- expect(get_list_response.records.first.name).to eq("name-input")
219
-
220
-
221
-
222
- expect(get_list_response.records.first.payment_reference).to eq("payment_reference-input")
223
-
224
-
225
-
226
- expect(get_list_response.records.first.start_date).to eq("start_date-input")
227
-
228
-
229
-
230
- expect(get_list_response.records.first.status).to eq("status-input")
231
-
232
-
233
-
234
- expect(get_list_response.records.first.upcoming_payments).to eq("upcoming_payments-input")
235
-
236
-
237
- end
238
-
239
- it "exposes the cursors for before and after" do
240
- expect(get_list_response.before).to eq(nil)
241
- expect(get_list_response.after).to eq("ABC123")
242
- end
243
-
244
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
92
+ it 'creates and returns the resource' do
93
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::Subscription)
245
94
  end
246
95
  end
247
96
 
248
- describe "#all" do
249
- let!(:first_response_stub) do
250
- stub_request(:get, %r(.*api.gocardless.com/subscriptions$)).to_return(
97
+ context 'with a request that returns a validation error' do
98
+ let(:new_resource) { {} }
99
+
100
+ before do
101
+ stub_request(:post, %r{.*api.gocardless.com/subscriptions}).to_return(
251
102
  body: {
252
- "subscriptions" => [{
253
-
254
- "amount" => "amount-input",
255
- "count" => "count-input",
256
- "created_at" => "created_at-input",
257
- "currency" => "currency-input",
258
- "day_of_month" => "day_of_month-input",
259
- "end_date" => "end_date-input",
260
- "id" => "id-input",
261
- "interval" => "interval-input",
262
- "interval_unit" => "interval_unit-input",
263
- "links" => "links-input",
264
- "metadata" => "metadata-input",
265
- "month" => "month-input",
266
- "name" => "name-input",
267
- "payment_reference" => "payment_reference-input",
268
- "start_date" => "start_date-input",
269
- "status" => "status-input",
270
- "upcoming_payments" => "upcoming_payments-input",
271
- }],
272
- meta: {
273
- cursors: { after: 'AB345' },
274
- limit: 1
103
+ error: {
104
+ type: 'validation_failed',
105
+ code: 422,
106
+ errors: [
107
+ { message: 'test error message', field: 'test_field' }
108
+ ]
275
109
  }
276
110
  }.to_json,
277
- :headers => {'Content-Type' => 'application/json'}
111
+ headers: { 'Content-Type' => 'application/json' },
112
+ status: 422
278
113
  )
279
114
  end
280
115
 
281
- let!(:second_response_stub) do
282
- stub_request(:get, %r(.*api.gocardless.com/subscriptions\?after=AB345)).to_return(
116
+ it 'throws the correct error' do
117
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '#list' do
123
+ describe 'with no filters' do
124
+ subject(:get_list_response) { client.subscriptions.list }
125
+
126
+ before do
127
+ stub_request(:get, %r{.*api.gocardless.com/subscriptions}).to_return(
283
128
  body: {
284
- "subscriptions" => [{
285
-
286
- "amount" => "amount-input",
287
- "count" => "count-input",
288
- "created_at" => "created_at-input",
289
- "currency" => "currency-input",
290
- "day_of_month" => "day_of_month-input",
291
- "end_date" => "end_date-input",
292
- "id" => "id-input",
293
- "interval" => "interval-input",
294
- "interval_unit" => "interval_unit-input",
295
- "links" => "links-input",
296
- "metadata" => "metadata-input",
297
- "month" => "month-input",
298
- "name" => "name-input",
299
- "payment_reference" => "payment_reference-input",
300
- "start_date" => "start_date-input",
301
- "status" => "status-input",
302
- "upcoming_payments" => "upcoming_payments-input",
129
+ 'subscriptions' => [{
130
+
131
+ 'amount' => 'amount-input',
132
+ 'count' => 'count-input',
133
+ 'created_at' => 'created_at-input',
134
+ 'currency' => 'currency-input',
135
+ 'day_of_month' => 'day_of_month-input',
136
+ 'end_date' => 'end_date-input',
137
+ 'id' => 'id-input',
138
+ 'interval' => 'interval-input',
139
+ 'interval_unit' => 'interval_unit-input',
140
+ 'links' => 'links-input',
141
+ 'metadata' => 'metadata-input',
142
+ 'month' => 'month-input',
143
+ 'name' => 'name-input',
144
+ 'payment_reference' => 'payment_reference-input',
145
+ 'start_date' => 'start_date-input',
146
+ 'status' => 'status-input',
147
+ 'upcoming_payments' => 'upcoming_payments-input'
303
148
  }],
304
149
  meta: {
305
- limit: 2,
306
- cursors: {}
150
+ cursors: {
151
+ before: nil,
152
+ after: 'ABC123'
153
+ }
307
154
  }
308
155
  }.to_json,
309
- :headers => {'Content-Type' => 'application/json'}
156
+ headers: { 'Content-Type' => 'application/json' }
310
157
  )
311
158
  end
312
159
 
313
- it "automatically makes the extra requests" do
314
- expect(client.subscriptions.all.to_a.length).to eq(2)
315
- expect(first_response_stub).to have_been_requested
316
- expect(second_response_stub).to have_been_requested
160
+ it 'wraps each item in the resource class' do
161
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Subscription)
162
+
163
+ expect(get_list_response.records.first.amount).to eq('amount-input')
164
+
165
+ expect(get_list_response.records.first.count).to eq('count-input')
166
+
167
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
168
+
169
+ expect(get_list_response.records.first.currency).to eq('currency-input')
170
+
171
+ expect(get_list_response.records.first.day_of_month).to eq('day_of_month-input')
172
+
173
+ expect(get_list_response.records.first.end_date).to eq('end_date-input')
174
+
175
+ expect(get_list_response.records.first.id).to eq('id-input')
176
+
177
+ expect(get_list_response.records.first.interval).to eq('interval-input')
178
+
179
+ expect(get_list_response.records.first.interval_unit).to eq('interval_unit-input')
180
+
181
+ expect(get_list_response.records.first.metadata).to eq('metadata-input')
182
+
183
+ expect(get_list_response.records.first.month).to eq('month-input')
184
+
185
+ expect(get_list_response.records.first.name).to eq('name-input')
186
+
187
+ expect(get_list_response.records.first.payment_reference).to eq('payment_reference-input')
188
+
189
+ expect(get_list_response.records.first.start_date).to eq('start_date-input')
190
+
191
+ expect(get_list_response.records.first.status).to eq('status-input')
192
+
193
+ expect(get_list_response.records.first.upcoming_payments).to eq('upcoming_payments-input')
194
+ end
195
+
196
+ it 'exposes the cursors for before and after' do
197
+ expect(get_list_response.before).to eq(nil)
198
+ expect(get_list_response.after).to eq('ABC123')
317
199
  end
200
+
201
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
202
+ end
203
+ end
204
+
205
+ describe '#all' do
206
+ let!(:first_response_stub) do
207
+ stub_request(:get, %r{.*api.gocardless.com/subscriptions$}).to_return(
208
+ body: {
209
+ 'subscriptions' => [{
210
+
211
+ 'amount' => 'amount-input',
212
+ 'count' => 'count-input',
213
+ 'created_at' => 'created_at-input',
214
+ 'currency' => 'currency-input',
215
+ 'day_of_month' => 'day_of_month-input',
216
+ 'end_date' => 'end_date-input',
217
+ 'id' => 'id-input',
218
+ 'interval' => 'interval-input',
219
+ 'interval_unit' => 'interval_unit-input',
220
+ 'links' => 'links-input',
221
+ 'metadata' => 'metadata-input',
222
+ 'month' => 'month-input',
223
+ 'name' => 'name-input',
224
+ 'payment_reference' => 'payment_reference-input',
225
+ 'start_date' => 'start_date-input',
226
+ 'status' => 'status-input',
227
+ 'upcoming_payments' => 'upcoming_payments-input'
228
+ }],
229
+ meta: {
230
+ cursors: { after: 'AB345' },
231
+ limit: 1
232
+ }
233
+ }.to_json,
234
+ headers: { 'Content-Type' => 'application/json' }
235
+ )
318
236
  end
319
237
 
320
-
321
-
322
-
238
+ let!(:second_response_stub) do
239
+ stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345}).to_return(
240
+ body: {
241
+ 'subscriptions' => [{
242
+
243
+ 'amount' => 'amount-input',
244
+ 'count' => 'count-input',
245
+ 'created_at' => 'created_at-input',
246
+ 'currency' => 'currency-input',
247
+ 'day_of_month' => 'day_of_month-input',
248
+ 'end_date' => 'end_date-input',
249
+ 'id' => 'id-input',
250
+ 'interval' => 'interval-input',
251
+ 'interval_unit' => 'interval_unit-input',
252
+ 'links' => 'links-input',
253
+ 'metadata' => 'metadata-input',
254
+ 'month' => 'month-input',
255
+ 'name' => 'name-input',
256
+ 'payment_reference' => 'payment_reference-input',
257
+ 'start_date' => 'start_date-input',
258
+ 'status' => 'status-input',
259
+ 'upcoming_payments' => 'upcoming_payments-input'
260
+ }],
261
+ meta: {
262
+ limit: 2,
263
+ cursors: {}
264
+ }
265
+ }.to_json,
266
+ headers: { 'Content-Type' => 'application/json' }
267
+ )
268
+ end
323
269
 
324
-
325
- describe "#get" do
326
- let(:id) { "ID123" }
270
+ it 'automatically makes the extra requests' do
271
+ expect(client.subscriptions.all.to_a.length).to eq(2)
272
+ expect(first_response_stub).to have_been_requested
273
+ expect(second_response_stub).to have_been_requested
274
+ end
275
+ end
327
276
 
328
- subject(:get_response) { client.subscriptions.get(id) }
277
+ describe '#get' do
278
+ let(:id) { 'ID123' }
329
279
 
330
- context "passing in a custom header" do
331
- let!(:stub) do
332
- stub_url = "/subscriptions/:identity".gsub(':identity', id)
333
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).
334
- with(headers: { 'Foo' => 'Bar' }).
335
- to_return(
336
- body: {
337
- "subscriptions" => {
338
-
339
- "amount" => "amount-input",
340
- "count" => "count-input",
341
- "created_at" => "created_at-input",
342
- "currency" => "currency-input",
343
- "day_of_month" => "day_of_month-input",
344
- "end_date" => "end_date-input",
345
- "id" => "id-input",
346
- "interval" => "interval-input",
347
- "interval_unit" => "interval_unit-input",
348
- "links" => "links-input",
349
- "metadata" => "metadata-input",
350
- "month" => "month-input",
351
- "name" => "name-input",
352
- "payment_reference" => "payment_reference-input",
353
- "start_date" => "start_date-input",
354
- "status" => "status-input",
355
- "upcoming_payments" => "upcoming_payments-input",
356
- }
357
- }.to_json,
358
- :headers => {'Content-Type' => 'application/json'}
359
- )
360
- end
361
-
362
- subject(:get_response) do
363
- client.subscriptions.get(id, headers: {
364
- 'Foo' => 'Bar'
365
- })
366
- end
367
-
368
- it "includes the header" do
369
- get_response
370
- expect(stub).to have_been_requested
371
- end
372
- end
280
+ subject(:get_response) { client.subscriptions.get(id) }
373
281
 
374
- context "when there is a subscription to return" do
375
- before do
376
- stub_url = "/subscriptions/:identity".gsub(':identity', id)
377
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
282
+ context 'passing in a custom header' do
283
+ let!(:stub) do
284
+ stub_url = '/subscriptions/:identity'.gsub(':identity', id)
285
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/)
286
+ .with(headers: { 'Foo' => 'Bar' })
287
+ .to_return(
378
288
  body: {
379
- "subscriptions" => {
380
-
381
- "amount" => "amount-input",
382
- "count" => "count-input",
383
- "created_at" => "created_at-input",
384
- "currency" => "currency-input",
385
- "day_of_month" => "day_of_month-input",
386
- "end_date" => "end_date-input",
387
- "id" => "id-input",
388
- "interval" => "interval-input",
389
- "interval_unit" => "interval_unit-input",
390
- "links" => "links-input",
391
- "metadata" => "metadata-input",
392
- "month" => "month-input",
393
- "name" => "name-input",
394
- "payment_reference" => "payment_reference-input",
395
- "start_date" => "start_date-input",
396
- "status" => "status-input",
397
- "upcoming_payments" => "upcoming_payments-input",
289
+ 'subscriptions' => {
290
+
291
+ 'amount' => 'amount-input',
292
+ 'count' => 'count-input',
293
+ 'created_at' => 'created_at-input',
294
+ 'currency' => 'currency-input',
295
+ 'day_of_month' => 'day_of_month-input',
296
+ 'end_date' => 'end_date-input',
297
+ 'id' => 'id-input',
298
+ 'interval' => 'interval-input',
299
+ 'interval_unit' => 'interval_unit-input',
300
+ 'links' => 'links-input',
301
+ 'metadata' => 'metadata-input',
302
+ 'month' => 'month-input',
303
+ 'name' => 'name-input',
304
+ 'payment_reference' => 'payment_reference-input',
305
+ 'start_date' => 'start_date-input',
306
+ 'status' => 'status-input',
307
+ 'upcoming_payments' => 'upcoming_payments-input'
398
308
  }
399
309
  }.to_json,
400
- :headers => {'Content-Type' => 'application/json'}
310
+ headers: { 'Content-Type' => 'application/json' }
401
311
  )
402
- end
403
-
404
- it "wraps the response in a resource" do
405
- expect(get_response).to be_a(GoCardlessPro::Resources::Subscription)
406
- end
407
312
  end
408
313
 
409
- context "when nothing is returned" do
410
- before do
411
- stub_url = "/subscriptions/:identity".gsub(':identity', id)
412
- stub_request(:get, %r(.*api.gocardless.com#{stub_url})).to_return(
413
- body: "",
414
- headers: { 'Content-Type' => 'application/json' }
415
- )
416
- end
314
+ subject(:get_response) do
315
+ client.subscriptions.get(id, headers: {
316
+ 'Foo' => 'Bar'
317
+ })
318
+ end
417
319
 
418
- it "returns nil" do
419
- expect(get_response).to be_nil
420
- end
320
+ it 'includes the header' do
321
+ get_response
322
+ expect(stub).to have_been_requested
421
323
  end
422
324
  end
423
325
 
424
-
425
-
426
-
427
-
428
-
429
- describe "#update" do
430
- subject(:put_update_response) { client.subscriptions.update(id, params: update_params) }
431
- let(:id) { "ABC123" }
326
+ context 'when there is a subscription to return' do
327
+ before do
328
+ stub_url = '/subscriptions/:identity'.gsub(':identity', id)
329
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
330
+ body: {
331
+ 'subscriptions' => {
332
+
333
+ 'amount' => 'amount-input',
334
+ 'count' => 'count-input',
335
+ 'created_at' => 'created_at-input',
336
+ 'currency' => 'currency-input',
337
+ 'day_of_month' => 'day_of_month-input',
338
+ 'end_date' => 'end_date-input',
339
+ 'id' => 'id-input',
340
+ 'interval' => 'interval-input',
341
+ 'interval_unit' => 'interval_unit-input',
342
+ 'links' => 'links-input',
343
+ 'metadata' => 'metadata-input',
344
+ 'month' => 'month-input',
345
+ 'name' => 'name-input',
346
+ 'payment_reference' => 'payment_reference-input',
347
+ 'start_date' => 'start_date-input',
348
+ 'status' => 'status-input',
349
+ 'upcoming_payments' => 'upcoming_payments-input'
350
+ }
351
+ }.to_json,
352
+ headers: { 'Content-Type' => 'application/json' }
353
+ )
354
+ end
432
355
 
433
- context "with a valid request" do
434
- let(:update_params) { { "hello" => "world" } }
356
+ it 'wraps the response in a resource' do
357
+ expect(get_response).to be_a(GoCardlessPro::Resources::Subscription)
358
+ end
359
+ end
435
360
 
436
- let!(:stub) do
437
- stub_url = "/subscriptions/:identity".gsub(':identity', id)
438
- stub_request(:put, %r(.*api.gocardless.com#{stub_url})).to_return(
439
- body: {
440
- "subscriptions" => {
441
-
442
- "amount" => "amount-input",
443
- "count" => "count-input",
444
- "created_at" => "created_at-input",
445
- "currency" => "currency-input",
446
- "day_of_month" => "day_of_month-input",
447
- "end_date" => "end_date-input",
448
- "id" => "id-input",
449
- "interval" => "interval-input",
450
- "interval_unit" => "interval_unit-input",
451
- "links" => "links-input",
452
- "metadata" => "metadata-input",
453
- "month" => "month-input",
454
- "name" => "name-input",
455
- "payment_reference" => "payment_reference-input",
456
- "start_date" => "start_date-input",
457
- "status" => "status-input",
458
- "upcoming_payments" => "upcoming_payments-input",
459
- }
460
- }.to_json,
461
- :headers => {'Content-Type' => 'application/json'}
462
- )
463
- end
361
+ context 'when nothing is returned' do
362
+ before do
363
+ stub_url = '/subscriptions/:identity'.gsub(':identity', id)
364
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
365
+ body: '',
366
+ headers: { 'Content-Type' => 'application/json' }
367
+ )
368
+ end
464
369
 
465
- it "updates and returns the resource" do
466
- expect(put_update_response).to be_a(GoCardlessPro::Resources::Subscription)
467
- expect(stub).to have_been_requested
468
- end
370
+ it 'returns nil' do
371
+ expect(get_response).to be_nil
469
372
  end
470
373
  end
471
-
472
-
473
-
474
-
475
-
476
- describe "#cancel" do
477
-
478
-
479
- subject(:post_response) { client.subscriptions.cancel(resource_id) }
480
-
481
- let(:resource_id) { "ABC123" }
374
+ end
375
+
376
+ describe '#update' do
377
+ subject(:put_update_response) { client.subscriptions.update(id, params: update_params) }
378
+ let(:id) { 'ABC123' }
379
+
380
+ context 'with a valid request' do
381
+ let(:update_params) { { 'hello' => 'world' } }
482
382
 
483
383
  let!(:stub) do
484
- # /subscriptions/%v/actions/cancel
485
- stub_url = "/subscriptions/:identity/actions/cancel".gsub(':identity', resource_id)
486
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).to_return(
384
+ stub_url = '/subscriptions/:identity'.gsub(':identity', id)
385
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
487
386
  body: {
488
- "subscriptions" => {
489
-
490
- "amount" => "amount-input",
491
- "count" => "count-input",
492
- "created_at" => "created_at-input",
493
- "currency" => "currency-input",
494
- "day_of_month" => "day_of_month-input",
495
- "end_date" => "end_date-input",
496
- "id" => "id-input",
497
- "interval" => "interval-input",
498
- "interval_unit" => "interval_unit-input",
499
- "links" => "links-input",
500
- "metadata" => "metadata-input",
501
- "month" => "month-input",
502
- "name" => "name-input",
503
- "payment_reference" => "payment_reference-input",
504
- "start_date" => "start_date-input",
505
- "status" => "status-input",
506
- "upcoming_payments" => "upcoming_payments-input",
387
+ 'subscriptions' => {
388
+
389
+ 'amount' => 'amount-input',
390
+ 'count' => 'count-input',
391
+ 'created_at' => 'created_at-input',
392
+ 'currency' => 'currency-input',
393
+ 'day_of_month' => 'day_of_month-input',
394
+ 'end_date' => 'end_date-input',
395
+ 'id' => 'id-input',
396
+ 'interval' => 'interval-input',
397
+ 'interval_unit' => 'interval_unit-input',
398
+ 'links' => 'links-input',
399
+ 'metadata' => 'metadata-input',
400
+ 'month' => 'month-input',
401
+ 'name' => 'name-input',
402
+ 'payment_reference' => 'payment_reference-input',
403
+ 'start_date' => 'start_date-input',
404
+ 'status' => 'status-input',
405
+ 'upcoming_payments' => 'upcoming_payments-input'
507
406
  }
508
407
  }.to_json,
509
- headers: {'Content-Type' => 'application/json'},
408
+ headers: { 'Content-Type' => 'application/json' }
510
409
  )
511
410
  end
512
411
 
513
- it "wraps the response and calls the right endpoint" do
514
- expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
515
-
412
+ it 'updates and returns the resource' do
413
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::Subscription)
516
414
  expect(stub).to have_been_requested
517
415
  end
416
+ end
417
+ end
518
418
 
519
- context "when the request needs a body and custom header" do
520
-
521
- let(:body) { { foo: 'bar' } }
522
- let(:headers) { { 'Foo' => 'Bar' } }
523
- subject(:post_response) { client.subscriptions.cancel(resource_id, body, headers) }
524
-
525
- let(:resource_id) { "ABC123" }
526
-
527
- let!(:stub) do
528
- # /subscriptions/%v/actions/cancel
529
- stub_url = "/subscriptions/:identity/actions/cancel".gsub(':identity', resource_id)
530
- stub_request(:post, %r(.*api.gocardless.com#{stub_url})).
531
- with(
419
+ describe '#cancel' do
420
+ subject(:post_response) { client.subscriptions.cancel(resource_id) }
421
+
422
+ let(:resource_id) { 'ABC123' }
423
+
424
+ let!(:stub) do
425
+ # /subscriptions/%v/actions/cancel
426
+ stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
427
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
428
+ body: {
429
+ 'subscriptions' => {
430
+
431
+ 'amount' => 'amount-input',
432
+ 'count' => 'count-input',
433
+ 'created_at' => 'created_at-input',
434
+ 'currency' => 'currency-input',
435
+ 'day_of_month' => 'day_of_month-input',
436
+ 'end_date' => 'end_date-input',
437
+ 'id' => 'id-input',
438
+ 'interval' => 'interval-input',
439
+ 'interval_unit' => 'interval_unit-input',
440
+ 'links' => 'links-input',
441
+ 'metadata' => 'metadata-input',
442
+ 'month' => 'month-input',
443
+ 'name' => 'name-input',
444
+ 'payment_reference' => 'payment_reference-input',
445
+ 'start_date' => 'start_date-input',
446
+ 'status' => 'status-input',
447
+ 'upcoming_payments' => 'upcoming_payments-input'
448
+ }
449
+ }.to_json,
450
+ headers: { 'Content-Type' => 'application/json' }
451
+ )
452
+ end
453
+
454
+ it 'wraps the response and calls the right endpoint' do
455
+ expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
456
+
457
+ expect(stub).to have_been_requested
458
+ end
459
+
460
+ context 'when the request needs a body and custom header' do
461
+ let(:body) { { foo: 'bar' } }
462
+ let(:headers) { { 'Foo' => 'Bar' } }
463
+ subject(:post_response) { client.subscriptions.cancel(resource_id, body, headers) }
464
+
465
+ let(:resource_id) { 'ABC123' }
466
+
467
+ let!(:stub) do
468
+ # /subscriptions/%v/actions/cancel
469
+ stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
470
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/)
471
+ .with(
532
472
  body: { foo: 'bar' },
533
473
  headers: { 'Foo' => 'Bar' }
534
474
  ).to_return(
535
475
  body: {
536
- "subscriptions" => {
537
-
538
- "amount" => "amount-input",
539
- "count" => "count-input",
540
- "created_at" => "created_at-input",
541
- "currency" => "currency-input",
542
- "day_of_month" => "day_of_month-input",
543
- "end_date" => "end_date-input",
544
- "id" => "id-input",
545
- "interval" => "interval-input",
546
- "interval_unit" => "interval_unit-input",
547
- "links" => "links-input",
548
- "metadata" => "metadata-input",
549
- "month" => "month-input",
550
- "name" => "name-input",
551
- "payment_reference" => "payment_reference-input",
552
- "start_date" => "start_date-input",
553
- "status" => "status-input",
554
- "upcoming_payments" => "upcoming_payments-input",
476
+ 'subscriptions' => {
477
+
478
+ 'amount' => 'amount-input',
479
+ 'count' => 'count-input',
480
+ 'created_at' => 'created_at-input',
481
+ 'currency' => 'currency-input',
482
+ 'day_of_month' => 'day_of_month-input',
483
+ 'end_date' => 'end_date-input',
484
+ 'id' => 'id-input',
485
+ 'interval' => 'interval-input',
486
+ 'interval_unit' => 'interval_unit-input',
487
+ 'links' => 'links-input',
488
+ 'metadata' => 'metadata-input',
489
+ 'month' => 'month-input',
490
+ 'name' => 'name-input',
491
+ 'payment_reference' => 'payment_reference-input',
492
+ 'start_date' => 'start_date-input',
493
+ 'status' => 'status-input',
494
+ 'upcoming_payments' => 'upcoming_payments-input'
555
495
  }
556
496
  }.to_json,
557
- headers: {'Content-Type' => 'application/json'},
497
+ headers: { 'Content-Type' => 'application/json' }
558
498
  )
559
- end
560
499
  end
561
500
  end
562
-
563
-
501
+ end
564
502
  end