restful_resource 0.8.23 → 0.8.24
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e2b83be86b56f31f8e1b4186c4a1784c01e39de
|
4
|
+
data.tar.gz: cb04d1da2bc7ff5d77b2f25079002b676cf3d343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33294bdf10f2ea9e833b6b97b71c191b9832235880c9cb7177a17f27c15639ea6394e860906a08e9edd836d97291ae767d81f290c641de65817a0402cf6bf539
|
7
|
+
data.tar.gz: 806b7711995ed7baf3d62309efe42e7948c79943937e7044bfecd15faa359e8e530137d2bc0354f97c8c0b7ac9fbf3c2be22fd27e6d6366e1632b32c9dcd7eb9
|
@@ -6,7 +6,14 @@ module RestfulResource
|
|
6
6
|
super(id, data: data, **params)
|
7
7
|
rescue HttpClient::UnprocessableEntity => e
|
8
8
|
errors = parse_json(e.response.body)
|
9
|
-
result =
|
9
|
+
result = nil
|
10
|
+
if errors.is_a?(Hash) && errors.has_key?('errors')
|
11
|
+
result = data.merge(errors)
|
12
|
+
elsif errors.is_a?(Array)
|
13
|
+
result = data.merge(errors: errors)
|
14
|
+
else
|
15
|
+
result = data.merge(errors: [errors])
|
16
|
+
end
|
10
17
|
self.new(result)
|
11
18
|
end
|
12
19
|
end
|
@@ -16,7 +23,14 @@ module RestfulResource
|
|
16
23
|
super(data: data, **params)
|
17
24
|
rescue HttpClient::UnprocessableEntity => e
|
18
25
|
errors = parse_json(e.response.body)
|
19
|
-
result =
|
26
|
+
result = nil
|
27
|
+
if errors.is_a?(Hash) && errors.has_key?('errors')
|
28
|
+
result = data.merge(errors)
|
29
|
+
elsif errors.is_a?(Array)
|
30
|
+
result = data.merge(errors: errors)
|
31
|
+
else
|
32
|
+
result = data.merge(errors: [errors])
|
33
|
+
end
|
20
34
|
self.new(result)
|
21
35
|
end
|
22
36
|
end
|
@@ -50,6 +50,27 @@ describe RestfulResource::RailsValidations do
|
|
50
50
|
it 'should return not valid object' do
|
51
51
|
expect(@object.valid?).to be_falsey
|
52
52
|
end
|
53
|
+
|
54
|
+
it 'should handle errors returned as root array' do
|
55
|
+
data = {name: 'Michelangelo'}
|
56
|
+
expected_response = RestfulResource::Response.new(body: [@error].to_json)
|
57
|
+
expect_put_with_unprocessable_entity("http://api.carwow.co.uk/dealers/1", expected_response, data: data)
|
58
|
+
|
59
|
+
@object = Dealer.put(1, data: data)
|
60
|
+
expect(@object.errors.count).to eq 1
|
61
|
+
expect(@object.errors.first).to eq @error
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should handle errors returned as root object' do
|
65
|
+
data = {name: 'Michelangelo'}
|
66
|
+
expected_response = RestfulResource::Response.new(body: @error.to_json)
|
67
|
+
expect_put_with_unprocessable_entity("http://api.carwow.co.uk/dealers/1", expected_response, data: data)
|
68
|
+
|
69
|
+
@object = Dealer.put(1, data: data)
|
70
|
+
expect(@object.errors.count).to eq 1
|
71
|
+
expect(@object.errors.first).to eq @error
|
72
|
+
end
|
73
|
+
|
53
74
|
end
|
54
75
|
|
55
76
|
context "#post without errors" do
|
@@ -95,5 +116,25 @@ describe RestfulResource::RailsValidations do
|
|
95
116
|
it 'should return not valid object' do
|
96
117
|
expect(@object.valid?).to be_falsey
|
97
118
|
end
|
119
|
+
|
120
|
+
it 'should handle errors returned as root object' do
|
121
|
+
data = {name: 'Michelangelo'}
|
122
|
+
expected_response = RestfulResource::Response.new(body: [@error].to_json)
|
123
|
+
expect_post_with_unprocessable_entity("http://api.carwow.co.uk/dealers", expected_response, data: data)
|
124
|
+
|
125
|
+
@object = Dealer.post(data: data)
|
126
|
+
expect(@object.errors.count).to eq 1
|
127
|
+
expect(@object.errors.first).to eq @error
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should handle errors returned as root object' do
|
131
|
+
data = {name: 'Michelangelo'}
|
132
|
+
expected_response = RestfulResource::Response.new(body: @error.to_json)
|
133
|
+
expect_post_with_unprocessable_entity("http://api.carwow.co.uk/dealers", expected_response, data: data)
|
134
|
+
|
135
|
+
@object = Dealer.post(data: data)
|
136
|
+
expect(@object.errors.count).to eq 1
|
137
|
+
expect(@object.errors.first).to eq @error
|
138
|
+
end
|
98
139
|
end
|
99
140
|
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: 0.8.
|
4
|
+
version: 0.8.24
|
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: 2015-01-
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|