restful_resource 2.8.0 → 2.9.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -22
- data/lib/restful_resource/base.rb +1 -1
- data/lib/restful_resource/rails_validations.rb +4 -1
- data/lib/restful_resource/version.rb +1 -1
- data/restful_resource.gemspec +1 -1
- data/spec/restful_resource/http_client_spec.rb +60 -146
- data/spec/restful_resource/rails_validations_spec.rb +52 -3
- data/spec/spec_helper.rb +7 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f91745b5168b3296b8088ea1c102145b894680ae31fa008527f301324ae37730
|
4
|
+
data.tar.gz: f431b9d44f4d187ac6ef6fb11cd1ada2cb2a3b8fde7778a89f99b195cb4028d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f385b176d47a81a6f72a5181aa57a96942e50df3441b29aa41609a1dbb530baea1c8e16e7669a295e8cb5d6a9bf190bb12ffed2805ee97be58e4649f27721af7
|
7
|
+
data.tar.gz: 618550d814e19931476b14a8c645f3583432618152ca8d17c15ecd83dff192c23a62e3e7848d3ac4efb1a38c9a854131578ec2da0c656e93a402c699b4c9349d
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
restful_resource (2.
|
4
|
+
restful_resource (2.9.1)
|
5
5
|
activesupport
|
6
|
-
faraday (
|
6
|
+
faraday (>= 0.15, < 1.1)
|
7
7
|
faraday-cdn-metrics
|
8
8
|
faraday-encoding
|
9
9
|
faraday-http-cache
|
@@ -15,15 +15,15 @@ PATH
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (6.0.1)
|
18
|
+
activesupport (6.0.2.1)
|
19
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
20
|
i18n (>= 0.7, < 2)
|
21
21
|
minitest (~> 5.1)
|
22
22
|
tzinfo (~> 1.1)
|
23
23
|
zeitwerk (~> 2.2)
|
24
24
|
ast (2.4.0)
|
25
|
-
carwow_rubocop (3.
|
26
|
-
rubocop (>= 0.
|
25
|
+
carwow_rubocop (3.2.1)
|
26
|
+
rubocop (>= 0.78)
|
27
27
|
rubocop-performance
|
28
28
|
rubocop-rspec
|
29
29
|
coderay (1.1.2)
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
diff-lcs (1.3)
|
32
32
|
ethon (0.12.0)
|
33
33
|
ffi (>= 1.3.0)
|
34
|
-
faraday (0.
|
34
|
+
faraday (0.17.3)
|
35
35
|
multipart-post (>= 1.2, < 3)
|
36
36
|
faraday-cdn-metrics (0.1.0)
|
37
37
|
faraday (~> 0.11)
|
@@ -39,25 +39,25 @@ GEM
|
|
39
39
|
faraday
|
40
40
|
faraday-http-cache (2.0.0)
|
41
41
|
faraday (~> 0.8)
|
42
|
-
faraday_middleware (0.
|
42
|
+
faraday_middleware (0.14.0)
|
43
43
|
faraday (>= 0.7.4, < 1.0)
|
44
|
-
ffi (1.
|
45
|
-
i18n (1.
|
44
|
+
ffi (1.12.1)
|
45
|
+
i18n (1.8.2)
|
46
46
|
concurrent-ruby (~> 1.0)
|
47
|
-
jaro_winkler (1.5.
|
47
|
+
jaro_winkler (1.5.4)
|
48
48
|
link_header (0.0.8)
|
49
49
|
method_source (0.9.2)
|
50
|
-
minitest (5.
|
50
|
+
minitest (5.14.0)
|
51
51
|
multipart-post (2.1.1)
|
52
|
-
parallel (1.
|
53
|
-
parser (2.
|
52
|
+
parallel (1.19.1)
|
53
|
+
parser (2.7.0.2)
|
54
54
|
ast (~> 2.4.0)
|
55
55
|
pry (0.12.2)
|
56
56
|
coderay (~> 1.1.0)
|
57
57
|
method_source (~> 0.9.0)
|
58
|
-
rack (2.
|
58
|
+
rack (2.1.2)
|
59
59
|
rainbow (3.0.0)
|
60
|
-
rake (13.0.
|
60
|
+
rake (13.0.1)
|
61
61
|
rspec (3.9.0)
|
62
62
|
rspec-core (~> 3.9.0)
|
63
63
|
rspec-expectations (~> 3.9.0)
|
@@ -76,25 +76,25 @@ GEM
|
|
76
76
|
rspec-support (3.9.0)
|
77
77
|
rspec_junit_formatter (0.4.1)
|
78
78
|
rspec-core (>= 2, < 4, != 2.12.0)
|
79
|
-
rubocop (0.
|
79
|
+
rubocop (0.79.0)
|
80
80
|
jaro_winkler (~> 1.5.1)
|
81
81
|
parallel (~> 1.10)
|
82
|
-
parser (>= 2.
|
82
|
+
parser (>= 2.7.0.1)
|
83
83
|
rainbow (>= 2.2.2, < 4.0)
|
84
84
|
ruby-progressbar (~> 1.7)
|
85
85
|
unicode-display_width (>= 1.4.0, < 1.7)
|
86
|
-
rubocop-performance (1.5.
|
86
|
+
rubocop-performance (1.5.2)
|
87
87
|
rubocop (>= 0.71.0)
|
88
|
-
rubocop-rspec (1.
|
88
|
+
rubocop-rspec (1.37.1)
|
89
89
|
rubocop (>= 0.68.1)
|
90
90
|
ruby-progressbar (1.10.1)
|
91
91
|
thread_safe (0.3.6)
|
92
92
|
typhoeus (1.3.1)
|
93
93
|
ethon (>= 0.9.0)
|
94
|
-
tzinfo (1.2.
|
94
|
+
tzinfo (1.2.6)
|
95
95
|
thread_safe (~> 0.1)
|
96
96
|
unicode-display_width (1.6.0)
|
97
|
-
zeitwerk (2.2.
|
97
|
+
zeitwerk (2.2.2)
|
98
98
|
|
99
99
|
PLATFORMS
|
100
100
|
ruby
|
@@ -110,4 +110,4 @@ DEPENDENCIES
|
|
110
110
|
rspec_junit_formatter
|
111
111
|
|
112
112
|
BUNDLED WITH
|
113
|
-
2.
|
113
|
+
2.1.4
|
@@ -58,7 +58,7 @@ module RestfulResource
|
|
58
58
|
def self.delete(id, **params)
|
59
59
|
params_without_options, options = format_params(params)
|
60
60
|
response = http.delete(member_url(id, params_without_options), **options)
|
61
|
-
|
61
|
+
new(parse_json(response.body))
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.patch(id, data: {}, headers: {}, **params)
|
@@ -17,13 +17,16 @@ module RestfulResource
|
|
17
17
|
with_validations { super }
|
18
18
|
end
|
19
19
|
|
20
|
+
def delete(*)
|
21
|
+
with_validations { super }
|
22
|
+
end
|
23
|
+
|
20
24
|
private
|
21
25
|
|
22
26
|
def with_validations(id = nil, data: {})
|
23
27
|
yield
|
24
28
|
rescue HttpClient::UnprocessableEntity => e
|
25
29
|
errors = parse_json(e.response.body)
|
26
|
-
result = nil
|
27
30
|
result = if errors.is_a?(Hash) && errors.key?('errors')
|
28
31
|
data.merge(errors)
|
29
32
|
else
|
data/restful_resource.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'rspec-its'
|
27
27
|
|
28
28
|
spec.add_dependency 'activesupport'
|
29
|
-
spec.add_dependency 'faraday', '
|
29
|
+
spec.add_dependency 'faraday', '>= 0.15', '< 1.1'
|
30
30
|
spec.add_dependency 'faraday-cdn-metrics'
|
31
31
|
spec.add_dependency 'faraday-encoding'
|
32
32
|
spec.add_dependency 'faraday-http-cache'
|
@@ -16,175 +16,97 @@ RSpec.describe RestfulResource::HttpClient do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'Basic HTTP' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
response = http_client(connection).get('http://httpbin.org/get')
|
25
|
-
expect(response.status).to eq 200
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'executes patch' do
|
29
|
-
connection = faraday_connection do |stubs|
|
30
|
-
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
31
|
-
stubs.patch('http://httpbin.org/patch', 'name=Alfred') { |_env| [200, {}, nil] }
|
32
|
-
end
|
33
|
-
|
34
|
-
response = http_client(connection).patch('http://httpbin.org/patch', data: { name: 'Alfred' })
|
35
|
-
expect(response.status).to eq 200
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'executes put' do
|
39
|
-
connection = faraday_connection do |stubs|
|
40
|
-
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
41
|
-
stubs.put('http://httpbin.org/put', 'name=Alfred') { |_env| [200, {}, nil] }
|
42
|
-
end
|
43
|
-
|
44
|
-
response = http_client(connection).put('http://httpbin.org/put', data: { name: 'Alfred' })
|
45
|
-
expect(response.status).to eq 200
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'executes post' do
|
49
|
-
connection = faraday_connection do |stubs|
|
50
|
-
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
51
|
-
stubs.post('http://httpbin.org/post', 'name=Alfred') { |_env| [200, {}, %("name": "Alfred")] }
|
52
|
-
end
|
53
|
-
|
54
|
-
response = http_client(connection).post('http://httpbin.org/post', data: { name: 'Alfred' })
|
55
|
-
|
56
|
-
expect(response.body).to include 'name": "Alfred'
|
57
|
-
expect(response.status).to eq 200
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'executes delete' do
|
61
|
-
connection = faraday_connection do |stubs|
|
62
|
-
stubs.delete('http://httpbin.org/delete') { |_env| [200, {}, nil] }
|
63
|
-
end
|
64
|
-
|
65
|
-
response = http_client(connection).delete('http://httpbin.org/delete')
|
66
|
-
|
67
|
-
expect(response.status).to eq 200
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'patch should raise error 409' do
|
71
|
-
connection = faraday_connection do |stubs|
|
72
|
-
stubs.patch('http://httpbin.org/status/409') { |_env| [409, {}, nil] }
|
73
|
-
end
|
19
|
+
shared_examples 'error codes throw exception' do |verb, status, exception_class|
|
20
|
+
it "should raise an error #{status}" do
|
21
|
+
url = "http://httpbin.org/status/#{status}"
|
74
22
|
|
75
|
-
|
76
|
-
|
23
|
+
connection = faraday_connection do |stubs|
|
24
|
+
stubs.send(verb, url) { [status, {}, nil] }
|
25
|
+
end
|
77
26
|
|
78
|
-
|
79
|
-
connection = faraday_connection do |stubs|
|
80
|
-
stubs.patch('http://httpbin.org/status/422') { |_env| [422, {}, nil] }
|
27
|
+
expect { http_client(connection).send(verb, url) }.to raise_error(exception_class)
|
81
28
|
end
|
82
|
-
|
83
|
-
expect { http_client(connection).patch('http://httpbin.org/status/422') }.to raise_error(RestfulResource::HttpClient::UnprocessableEntity)
|
84
29
|
end
|
85
30
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
31
|
+
shared_examples 'raise an exception on error responses' do |verb|
|
32
|
+
include_examples 'error codes throw exception', verb, 409, RestfulResource::HttpClient::Conflict
|
33
|
+
include_examples 'error codes throw exception', verb, 404, RestfulResource::HttpClient::ResourceNotFound
|
34
|
+
include_examples 'error codes throw exception', verb, 422, RestfulResource::HttpClient::UnprocessableEntity
|
35
|
+
include_examples 'error codes throw exception', verb, 429, RestfulResource::HttpClient::TooManyRequests
|
36
|
+
include_examples 'error codes throw exception', verb, 502, RestfulResource::HttpClient::BadGateway
|
37
|
+
include_examples 'error codes throw exception', verb, 503, RestfulResource::HttpClient::ServiceUnavailable
|
38
|
+
include_examples 'error codes throw exception', verb, 504, RestfulResource::HttpClient::GatewayTimeout
|
90
39
|
|
91
|
-
|
40
|
+
include_examples 'error codes throw exception', verb, 418, RestfulResource::HttpClient::OtherHttpError
|
92
41
|
end
|
93
42
|
|
94
|
-
|
95
|
-
|
96
|
-
stubs.put('http://httpbin.org/status/422') { |_env| [422, {}, nil] }
|
97
|
-
end
|
43
|
+
context 'GET' do
|
44
|
+
include_examples 'raise an exception on error responses', :get
|
98
45
|
|
99
|
-
|
100
|
-
|
46
|
+
it 'executes get' do
|
47
|
+
connection = faraday_connection do |stubs|
|
48
|
+
stubs.get('http://httpbin.org/get') { |_env| [200, {}, nil] }
|
49
|
+
end
|
101
50
|
|
102
|
-
|
103
|
-
|
104
|
-
stubs.post('http://httpbin.org/status/422') { |_env| [422, {}, nil] }
|
51
|
+
response = http_client(connection).get('http://httpbin.org/get')
|
52
|
+
expect(response.status).to eq 200
|
105
53
|
end
|
106
|
-
|
107
|
-
expect { http_client(connection).post('http://httpbin.org/status/422') }.to raise_error(RestfulResource::HttpClient::UnprocessableEntity)
|
108
54
|
end
|
109
55
|
|
110
|
-
|
111
|
-
|
112
|
-
stubs.post('http://httpbin.org/status/429') { |_env| [429, {}, nil] }
|
113
|
-
end
|
56
|
+
context 'PATCH' do
|
57
|
+
include_examples 'raise an exception on error responses', :patch
|
114
58
|
|
115
|
-
|
116
|
-
|
59
|
+
it 'executes patch' do
|
60
|
+
connection = faraday_connection do |stubs|
|
61
|
+
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
62
|
+
stubs.patch('http://httpbin.org/patch', 'name=Alfred') { |_env| [200, {}, nil] }
|
63
|
+
end
|
117
64
|
|
118
|
-
|
119
|
-
|
120
|
-
stubs.patch('http://httpbin.org/status/502') { |_env| [502, {}, nil] }
|
65
|
+
response = http_client(connection).patch('http://httpbin.org/patch', data: { name: 'Alfred' })
|
66
|
+
expect(response.status).to eq 200
|
121
67
|
end
|
122
|
-
|
123
|
-
expect { http_client(connection).patch('http://httpbin.org/status/502') }.to raise_error(RestfulResource::HttpClient::BadGateway)
|
124
68
|
end
|
125
69
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
70
|
+
context 'PUT' do
|
71
|
+
include_examples 'raise an exception on error responses', :put
|
72
|
+
it 'executes put' do
|
73
|
+
connection = faraday_connection do |stubs|
|
74
|
+
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
75
|
+
stubs.put('http://httpbin.org/put', 'name=Alfred') { |_env| [200, {}, nil] }
|
76
|
+
end
|
133
77
|
|
134
|
-
|
135
|
-
|
136
|
-
stubs.post('http://httpbin.org/status/502') { |_env| [502, {}, nil] }
|
78
|
+
response = http_client(connection).put('http://httpbin.org/put', data: { name: 'Alfred' })
|
79
|
+
expect(response.status).to eq 200
|
137
80
|
end
|
138
|
-
|
139
|
-
expect { http_client(connection).post('http://httpbin.org/status/502') }.to raise_error(RestfulResource::HttpClient::BadGateway)
|
140
81
|
end
|
141
82
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
83
|
+
context 'POST' do
|
84
|
+
include_examples 'raise an exception on error responses', :post
|
85
|
+
it 'executes post' do
|
86
|
+
connection = faraday_connection do |stubs|
|
87
|
+
# Note: request body is serialized as url-encoded so the stub body must be in the same format to match
|
88
|
+
stubs.post('http://httpbin.org/post', 'name=Alfred') { |_env| [200, {}, %("name": "Alfred")] }
|
89
|
+
end
|
146
90
|
|
147
|
-
|
148
|
-
end
|
91
|
+
response = http_client(connection).post('http://httpbin.org/post', data: { name: 'Alfred' })
|
149
92
|
|
150
|
-
|
151
|
-
|
152
|
-
stubs.put('http://httpbin.org/status/503') { |_env| [503, {}, nil] }
|
93
|
+
expect(response.body).to include 'name": "Alfred'
|
94
|
+
expect(response.status).to eq 200
|
153
95
|
end
|
154
|
-
|
155
|
-
expect { http_client(connection).put('http://httpbin.org/status/503') }.to raise_error(RestfulResource::HttpClient::ServiceUnavailable)
|
156
96
|
end
|
157
97
|
|
158
|
-
|
159
|
-
|
160
|
-
stubs.post('http://httpbin.org/status/503') { |_env| [503, {}, nil] }
|
161
|
-
end
|
162
|
-
|
163
|
-
expect { http_client(connection).post('http://httpbin.org/status/503') }.to raise_error(RestfulResource::HttpClient::ServiceUnavailable)
|
164
|
-
end
|
98
|
+
context 'DELETE' do
|
99
|
+
include_examples 'raise an exception on error responses', :delete
|
165
100
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
101
|
+
it 'executes delete' do
|
102
|
+
connection = faraday_connection do |stubs|
|
103
|
+
stubs.delete('http://httpbin.org/delete') { |_env| [200, {}, nil] }
|
104
|
+
end
|
170
105
|
|
171
|
-
|
172
|
-
end
|
106
|
+
response = http_client(connection).delete('http://httpbin.org/delete')
|
173
107
|
|
174
|
-
|
175
|
-
connection = faraday_connection do |stubs|
|
176
|
-
stubs.get('http://httpbin.org/status/404') { |_env| [404, {}, nil] }
|
177
|
-
stubs.post('http://httpbin.org/status/404') { |_env| [404, {}, nil] }
|
178
|
-
stubs.patch('http://httpbin.org/status/404') { |_env| [404, {}, nil] }
|
179
|
-
stubs.put('http://httpbin.org/status/404') { |_env| [404, {}, nil] }
|
180
|
-
stubs.delete('http://httpbin.org/status/404') { |_env| [404, {}, nil] }
|
108
|
+
expect(response.status).to eq 200
|
181
109
|
end
|
182
|
-
|
183
|
-
expect { http_client(connection).get('http://httpbin.org/status/404') }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
|
184
|
-
expect { http_client(connection).delete('http://httpbin.org/status/404') }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
|
185
|
-
expect { http_client(connection).patch('http://httpbin.org/status/404', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
|
186
|
-
expect { http_client(connection).put('http://httpbin.org/status/404', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
|
187
|
-
expect { http_client(connection).post('http://httpbin.org/status/404', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::ResourceNotFound)
|
188
110
|
end
|
189
111
|
|
190
112
|
it 'raises Faraday::ConnectionFailed errors' do
|
@@ -210,14 +132,6 @@ RSpec.describe RestfulResource::HttpClient do
|
|
210
132
|
|
211
133
|
expect { http_client(connection).get('https://localhost:3005') }.to raise_error(RestfulResource::HttpClient::ClientError)
|
212
134
|
end
|
213
|
-
|
214
|
-
it 'raises OtherHttpError for other status response codes' do
|
215
|
-
connection = faraday_connection do |stubs|
|
216
|
-
stubs.get('http://httpbin.org/status/418') { |_env| [418, {}, nil] }
|
217
|
-
end
|
218
|
-
|
219
|
-
expect { http_client(connection).get('http://httpbin.org/status/418') }.to raise_error(RestfulResource::HttpClient::OtherHttpError)
|
220
|
-
end
|
221
135
|
end
|
222
136
|
|
223
137
|
describe 'Authentication' do
|
@@ -72,13 +72,13 @@ RSpec.describe RestfulResource::RailsValidations do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context '#
|
75
|
+
context '#put without errors' do
|
76
76
|
before do
|
77
77
|
data = { name: 'Barak' }
|
78
78
|
expected_response = RestfulResource::Response.new(body: { name: 'Barak' }.to_json)
|
79
|
-
|
79
|
+
expect_put('http://api.carwow.co.uk/dealers/1', expected_response, data: data)
|
80
80
|
|
81
|
-
@object = Dealer.
|
81
|
+
@object = Dealer.put(1, data: data)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'returns object' do
|
@@ -239,4 +239,53 @@ RSpec.describe RestfulResource::RailsValidations do
|
|
239
239
|
expect(@object.errors).to eq @error
|
240
240
|
end
|
241
241
|
end
|
242
|
+
|
243
|
+
describe '#delete' do
|
244
|
+
subject { Dealer.delete(123) }
|
245
|
+
|
246
|
+
context 'without errors' do
|
247
|
+
before do
|
248
|
+
expected_response = RestfulResource::Response.new(body: { name: 'Barak' }.to_json)
|
249
|
+
expect_delete('http://api.carwow.co.uk/dealers/123', expected_response)
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'returns object' do
|
253
|
+
expect(subject.name).to eq 'Barak'
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'returns valid object' do
|
257
|
+
expect(subject).to be_valid
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'with errors' do
|
262
|
+
let(:errors) { { errors: ['Cannot use Ninja Turtles names'] } }
|
263
|
+
|
264
|
+
before do
|
265
|
+
expected_response = RestfulResource::Response.new(body: errors.to_json)
|
266
|
+
expect_delete_with_unprocessable_entity('http://api.carwow.co.uk/dealers/123', expected_response)
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'has an error' do
|
270
|
+
expect(subject.errors.count).to eq 1
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'has correct error' do
|
274
|
+
expect(subject.errors.first).to eq 'Cannot use Ninja Turtles names'
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'returns not valid object' do
|
278
|
+
expect(subject).not_to be_valid
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'when there is a single error' do
|
282
|
+
let(:errors) { 'Cannot use Ninja Turtles names' }
|
283
|
+
|
284
|
+
it 'handles errors returned as root object' do
|
285
|
+
expect(subject).not_to be_valid
|
286
|
+
expect(subject.errors).to eq errors
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
242
291
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -65,3 +65,10 @@ def expect_post_with_unprocessable_entity(url, response, data: {})
|
|
65
65
|
exception = RestfulResource::HttpClient::UnprocessableEntity.new(request, rest_client_response)
|
66
66
|
expect(@mock_http).to receive(:post).with(url, data: data, headers: {}, open_timeout: nil, timeout: nil).and_raise(exception)
|
67
67
|
end
|
68
|
+
|
69
|
+
def expect_delete_with_unprocessable_entity(url, response)
|
70
|
+
request = RestfulResource::Request.new(:delete, url)
|
71
|
+
rest_client_response = OpenStruct.new(body: response.body, headers: response.headers, code: response.status)
|
72
|
+
exception = RestfulResource::HttpClient::UnprocessableEntity.new(request, rest_client_response)
|
73
|
+
expect(@mock_http).to receive(:delete).with(url, headers: {}, open_timeout: nil, timeout: nil).and_raise(exception)
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santoro
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -113,16 +113,22 @@ dependencies:
|
|
113
113
|
name: faraday
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0.15'
|
119
|
+
- - "<"
|
117
120
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
121
|
+
version: '1.1'
|
119
122
|
type: :runtime
|
120
123
|
prerelease: false
|
121
124
|
version_requirements: !ruby/object:Gem::Requirement
|
122
125
|
requirements:
|
123
|
-
- - "
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0.15'
|
129
|
+
- - "<"
|
124
130
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
131
|
+
version: '1.1'
|
126
132
|
- !ruby/object:Gem::Dependency
|
127
133
|
name: faraday-cdn-metrics
|
128
134
|
requirement: !ruby/object:Gem::Requirement
|