Skip to content

Commit 93c45cb

Browse files
authored
Merge pull request #148 from gocardless/template-changes
Template changes
2 parents 6627aa8 + 0e9cd49 commit 93c45cb

File tree

5 files changed

+2
-282
lines changed

5 files changed

+2
-282
lines changed

lib/gocardless_pro/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def default_options
253253
'User-Agent' => "#{user_agent}",
254254
'Content-Type' => 'application/json',
255255
'GoCardless-Client-Library' => 'gocardless-pro-ruby',
256-
'GoCardless-Client-Version' => '4.1.0'
256+
'GoCardless-Client-Version' => '4.2.0'
257257
}
258258
}
259259
end

lib/gocardless_pro/services/negative_balance_limits_service.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,6 @@ def all(options = {})
3939
).enumerator
4040
end
4141

42-
# Creates a new negative balance limit, which replaces the existing limit (if
43-
# present) for that currency and creditor combination.
44-
#
45-
# Example URL: /negative_balance_limits
46-
# @param options [Hash] parameters as a hash, under a params key.
47-
def create(options = {})
48-
path = '/negative_balance_limits'
49-
50-
params = options.delete(:params) || {}
51-
options[:params] = {}
52-
options[:params][envelope_key] = params
53-
54-
options[:retry_failures] = true
55-
56-
response = make_request(:post, path, options)
57-
58-
return if response.body.nil?
59-
60-
Resources::NegativeBalanceLimit.new(unenvelope_body(response.body), response)
61-
end
62-
6342
private
6443

6544
# Unenvelope the response of the body using the service's `envelope_key`

lib/gocardless_pro/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module GoCardlessPro
33

44
module GoCardlessPro
55
# Current version of the GC gem
6-
VERSION = '4.1.0'
6+
VERSION = '4.2.0'
77
end

spec/resources/negative_balance_limit_spec.rb

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -105,122 +105,4 @@
105105
expect(second_response_stub).to have_been_requested
106106
end
107107
end
108-
109-
describe '#create' do
110-
subject(:post_create_response) { client.negative_balance_limits.create(params: new_resource) }
111-
context 'with a valid request' do
112-
let(:new_resource) do
113-
{
114-
115-
'balance_limit' => 'balance_limit-input',
116-
'created_at' => 'created_at-input',
117-
'currency' => 'currency-input',
118-
'id' => 'id-input',
119-
'links' => 'links-input'
120-
}
121-
end
122-
123-
before do
124-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits})
125-
.with(
126-
body: {
127-
'negative_balance_limits' => {
128-
129-
'balance_limit' => 'balance_limit-input',
130-
'created_at' => 'created_at-input',
131-
'currency' => 'currency-input',
132-
'id' => 'id-input',
133-
'links' => 'links-input'
134-
}
135-
}
136-
)
137-
.to_return(
138-
body: {
139-
'negative_balance_limits' =>
140-
141-
{
142-
143-
'balance_limit' => 'balance_limit-input',
144-
'created_at' => 'created_at-input',
145-
'currency' => 'currency-input',
146-
'id' => 'id-input',
147-
'links' => 'links-input'
148-
}
149-
150-
}.to_json,
151-
headers: response_headers
152-
)
153-
end
154-
155-
it 'creates and returns the resource' do
156-
expect(post_create_response).to be_a(GoCardlessPro::Resources::NegativeBalanceLimit)
157-
end
158-
end
159-
160-
context 'with a request that returns a validation error' do
161-
let(:new_resource) { {} }
162-
163-
before do
164-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits}).to_return(
165-
body: {
166-
error: {
167-
type: 'validation_failed',
168-
code: 422,
169-
errors: [
170-
{ message: 'test error message', field: 'test_field' }
171-
]
172-
}
173-
}.to_json,
174-
headers: response_headers,
175-
status: 422
176-
)
177-
end
178-
179-
it 'throws the correct error' do
180-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
181-
end
182-
end
183-
184-
context 'with a request that returns an idempotent creation conflict error' do
185-
let(:id) { 'ID123' }
186-
187-
let(:new_resource) do
188-
{
189-
190-
'balance_limit' => 'balance_limit-input',
191-
'created_at' => 'created_at-input',
192-
'currency' => 'currency-input',
193-
'id' => 'id-input',
194-
'links' => 'links-input'
195-
}
196-
end
197-
198-
let!(:post_stub) do
199-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits}).to_return(
200-
body: {
201-
error: {
202-
type: 'invalid_state',
203-
code: 409,
204-
errors: [
205-
{
206-
message: 'A resource has already been created with this idempotency key',
207-
reason: 'idempotent_creation_conflict',
208-
links: {
209-
conflicting_resource_id: id
210-
}
211-
}
212-
]
213-
}
214-
}.to_json,
215-
headers: response_headers,
216-
status: 409
217-
)
218-
end
219-
220-
it 'raises an InvalidStateError' do
221-
expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
222-
expect(post_stub).to have_been_requested
223-
end
224-
end
225-
end
226108
end

spec/services/negative_balance_limits_service_spec.rb

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -229,145 +229,4 @@
229229
end
230230
end
231231
end
232-
233-
describe '#create' do
234-
subject(:post_create_response) { client.negative_balance_limits.create(params: new_resource) }
235-
context 'with a valid request' do
236-
let(:new_resource) do
237-
{
238-
239-
'balance_limit' => 'balance_limit-input',
240-
'created_at' => 'created_at-input',
241-
'currency' => 'currency-input',
242-
'id' => 'id-input',
243-
'links' => 'links-input'
244-
}
245-
end
246-
247-
before do
248-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits})
249-
.with(
250-
body: {
251-
'negative_balance_limits' => {
252-
253-
'balance_limit' => 'balance_limit-input',
254-
'created_at' => 'created_at-input',
255-
'currency' => 'currency-input',
256-
'id' => 'id-input',
257-
'links' => 'links-input'
258-
}
259-
}
260-
)
261-
.to_return(
262-
body: {
263-
'negative_balance_limits' =>
264-
265-
{
266-
267-
'balance_limit' => 'balance_limit-input',
268-
'created_at' => 'created_at-input',
269-
'currency' => 'currency-input',
270-
'id' => 'id-input',
271-
'links' => 'links-input'
272-
}
273-
274-
}.to_json,
275-
headers: response_headers
276-
)
277-
end
278-
279-
it 'creates and returns the resource' do
280-
expect(post_create_response).to be_a(GoCardlessPro::Resources::NegativeBalanceLimit)
281-
end
282-
283-
describe 'retry behaviour' do
284-
before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
285-
286-
it 'retries timeouts' do
287-
stub = stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits})
288-
.to_timeout.then.to_return({ status: 200, headers: response_headers })
289-
290-
post_create_response
291-
expect(stub).to have_been_requested.twice
292-
end
293-
294-
it 'retries 5XX errors' do
295-
stub = stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits})
296-
.to_return({ status: 502,
297-
headers: { 'Content-Type' => 'text/html' },
298-
body: '<html><body>Response from Cloudflare</body></html>' })
299-
.then.to_return({ status: 200, headers: response_headers })
300-
301-
post_create_response
302-
expect(stub).to have_been_requested.twice
303-
end
304-
end
305-
end
306-
307-
context 'with a request that returns a validation error' do
308-
let(:new_resource) { {} }
309-
310-
before do
311-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits}).to_return(
312-
body: {
313-
error: {
314-
type: 'validation_failed',
315-
code: 422,
316-
errors: [
317-
{ message: 'test error message', field: 'test_field' }
318-
]
319-
}
320-
}.to_json,
321-
headers: response_headers,
322-
status: 422
323-
)
324-
end
325-
326-
it 'throws the correct error' do
327-
expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
328-
end
329-
end
330-
331-
context 'with a request that returns an idempotent creation conflict error' do
332-
let(:id) { 'ID123' }
333-
334-
let(:new_resource) do
335-
{
336-
337-
'balance_limit' => 'balance_limit-input',
338-
'created_at' => 'created_at-input',
339-
'currency' => 'currency-input',
340-
'id' => 'id-input',
341-
'links' => 'links-input'
342-
}
343-
end
344-
345-
let!(:post_stub) do
346-
stub_request(:post, %r{.*api.gocardless.com/negative_balance_limits}).to_return(
347-
body: {
348-
error: {
349-
type: 'invalid_state',
350-
code: 409,
351-
errors: [
352-
{
353-
message: 'A resource has already been created with this idempotency key',
354-
reason: 'idempotent_creation_conflict',
355-
links: {
356-
conflicting_resource_id: id
357-
}
358-
}
359-
]
360-
}
361-
}.to_json,
362-
headers: response_headers,
363-
status: 409
364-
)
365-
end
366-
367-
it 'raises an InvalidStateError' do
368-
expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
369-
expect(post_stub).to have_been_requested
370-
end
371-
end
372-
end
373232
end

0 commit comments

Comments
 (0)