ddy_remote_resource 1.0.0.rc2 → 1.0.0.rc3
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/README.md +125 -114
- data/lib/remote_resource/base.rb +11 -11
- data/lib/remote_resource/builder.rb +13 -25
- data/lib/remote_resource/collection.rb +25 -10
- data/lib/remote_resource/request.rb +1 -1
- data/lib/remote_resource/response.rb +33 -51
- data/lib/remote_resource/version.rb +1 -1
- data/spec/lib/remote_resource/base_spec.rb +62 -50
- data/spec/lib/remote_resource/builder_spec.rb +169 -173
- data/spec/lib/remote_resource/collection_spec.rb +94 -27
- data/spec/lib/remote_resource/request_spec.rb +14 -4
- data/spec/lib/remote_resource/response_spec.rb +102 -169
- data/spec/lib/remote_resource/version_spec.rb +1 -1
- metadata +2 -2
@@ -8,27 +8,27 @@ RSpec.describe RemoteResource::Collection do
|
|
8
8
|
|
9
9
|
self.site = 'https://foobar.com'
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :name
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:dummy_class) { RemoteResource::CollectionDummy }
|
16
16
|
let(:dummy) { dummy_class.new }
|
17
17
|
|
18
|
-
let(:
|
19
|
-
let(:
|
20
|
-
let(:
|
21
|
-
{
|
18
|
+
let(:request) { instance_double(RemoteResource::Request) }
|
19
|
+
let(:response) { instance_double(RemoteResource::Response) }
|
20
|
+
let(:options) do
|
21
|
+
{ last_request: request, last_response: response, meta: { 'total' => 10 } }
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:resources_collection) do
|
25
25
|
[
|
26
|
-
{ id
|
27
|
-
{ id
|
26
|
+
{ 'id' => 1, 'name' => 'mies_1' },
|
27
|
+
{ 'id' => 2, 'name' => 'mies_2' }
|
28
28
|
]
|
29
29
|
end
|
30
30
|
|
31
|
-
let(:collection) { described_class.new
|
31
|
+
let(:collection) { described_class.new(dummy_class, resources_collection, options) }
|
32
32
|
|
33
33
|
specify { expect(described_class).to include Enumerable }
|
34
34
|
|
@@ -66,9 +66,9 @@ RSpec.describe RemoteResource::Collection do
|
|
66
66
|
|
67
67
|
describe '#each' do
|
68
68
|
context 'when the resources_collection is an Array' do
|
69
|
-
it 'instantiates each element in the resources_collection as resource' do
|
70
|
-
expect(dummy_class).to receive(:new).with(resources_collection[0].merge(
|
71
|
-
expect(dummy_class).to receive(:new).with(resources_collection[1].merge(
|
69
|
+
it 'instantiates each element in the resources_collection as resource with the given options' do
|
70
|
+
expect(dummy_class).to receive(:new).with(resources_collection[0].merge(options)).and_call_original
|
71
|
+
expect(dummy_class).to receive(:new).with(resources_collection[1].merge(options)).and_call_original
|
72
72
|
collection.all?
|
73
73
|
end
|
74
74
|
|
@@ -78,24 +78,38 @@ RSpec.describe RemoteResource::Collection do
|
|
78
78
|
|
79
79
|
context 'Enumerable' do
|
80
80
|
it 'includes the resources' do
|
81
|
-
|
82
|
-
|
81
|
+
aggregate_failures do
|
82
|
+
expect(collection[0]).to be_a RemoteResource::CollectionDummy
|
83
|
+
expect(collection[1]).to be_a RemoteResource::CollectionDummy
|
84
|
+
end
|
83
85
|
end
|
84
86
|
|
85
87
|
it 'includes the instantiated resources' do
|
86
|
-
|
87
|
-
|
88
|
+
aggregate_failures do
|
89
|
+
expect(collection[0].id).to eql 1
|
90
|
+
expect(collection[0].name).to eql 'mies_1'
|
91
|
+
|
92
|
+
expect(collection[1].id).to eql 2
|
93
|
+
expect(collection[1].name).to eql 'mies_2'
|
94
|
+
end
|
88
95
|
end
|
89
96
|
|
90
|
-
it 'includes the
|
91
|
-
|
92
|
-
|
97
|
+
it 'includes the last request, last response and meta information in the instantiated resources' do
|
98
|
+
aggregate_failures do
|
99
|
+
expect(collection[0].last_request).to eql request
|
100
|
+
expect(collection[0].last_response).to eql response
|
101
|
+
expect(collection[0].meta).to eql({ 'total' => 10 })
|
102
|
+
|
103
|
+
expect(collection[1].last_request).to eql request
|
104
|
+
expect(collection[1].last_response).to eql response
|
105
|
+
expect(collection[1].meta).to eql({ 'total' => 10 })
|
106
|
+
end
|
93
107
|
end
|
94
108
|
end
|
95
109
|
|
96
110
|
it 'returns the same objects each time' do
|
97
111
|
expected = collection.collect(&:object_id)
|
98
|
-
actual
|
112
|
+
actual = collection.collect(&:object_id)
|
99
113
|
|
100
114
|
aggregate_failures do
|
101
115
|
expect(expected.length).to eq(2)
|
@@ -138,26 +152,79 @@ RSpec.describe RemoteResource::Collection do
|
|
138
152
|
end
|
139
153
|
|
140
154
|
describe '#success?' do
|
141
|
-
context 'when response is successful' do
|
142
|
-
before { allow(response).to receive(:success?) { true } }
|
143
|
-
|
155
|
+
context 'when last response is successful' do
|
144
156
|
it 'returns true' do
|
157
|
+
collection.last_response = instance_double(RemoteResource::Response, success?: true)
|
158
|
+
|
145
159
|
expect(collection.success?).to eql true
|
146
160
|
end
|
147
161
|
end
|
148
162
|
|
149
|
-
context 'when response is NOT successful' do
|
150
|
-
before { allow(response).to receive(:success?) { false } }
|
151
|
-
|
163
|
+
context 'when last response is NOT successful' do
|
152
164
|
it 'returns false' do
|
165
|
+
collection.last_response = instance_double(RemoteResource::Response, success?: false)
|
166
|
+
|
153
167
|
expect(collection.success?).to eql false
|
154
168
|
end
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
172
|
+
describe '#last_request' do
|
173
|
+
context 'when last request is in the options' do
|
174
|
+
it 'returns the last request of the options' do
|
175
|
+
expect(collection.last_request).to eql request
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'when last request is set' do
|
180
|
+
let(:other_request) { instance_double(RemoteResource::Request) }
|
181
|
+
|
182
|
+
it 'returns the set request' do
|
183
|
+
collection.last_request = other_request
|
184
|
+
|
185
|
+
expect(collection.last_request).to eql other_request
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#last_response' do
|
191
|
+
context 'when last response is in the options' do
|
192
|
+
it 'returns the last response of the options' do
|
193
|
+
expect(collection.last_response).to eql response
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when last response is set' do
|
198
|
+
let(:other_response) { instance_double(RemoteResource::Response) }
|
199
|
+
|
200
|
+
it 'returns the set response' do
|
201
|
+
collection.last_response = other_response
|
202
|
+
|
203
|
+
expect(collection.last_response).to eql other_response
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
158
208
|
describe '#meta' do
|
159
|
-
|
160
|
-
|
209
|
+
context 'when meta information is in the options' do
|
210
|
+
it 'returns the meta information of the options' do
|
211
|
+
expect(collection.meta).to eql({ 'total' => 10 })
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when meta is set' do
|
216
|
+
it 'returns the set meta information' do
|
217
|
+
collection.meta = { 'total' => 15 }
|
218
|
+
|
219
|
+
expect(collection.meta).to eql({ 'total' => 15 })
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe '#_response' do
|
225
|
+
it 'warns that the method is deprecated' do
|
226
|
+
expect(collection).to receive(:warn).with('[DEPRECATION] `._response` is deprecated. Please use `.last_response` instead.')
|
227
|
+
collection._response
|
161
228
|
end
|
162
229
|
end
|
163
230
|
|
@@ -118,16 +118,26 @@ RSpec.describe RemoteResource::Request do
|
|
118
118
|
|
119
119
|
shared_examples 'a conditional construct for the response' do
|
120
120
|
context 'when the response is #success?' do
|
121
|
-
it 'returns a RemoteResource::Response object' do
|
122
|
-
|
121
|
+
it 'returns a RemoteResource::Response object with the request' do
|
122
|
+
aggregate_failures do
|
123
|
+
result = request.perform
|
124
|
+
|
125
|
+
expect(result).to be_a RemoteResource::Response
|
126
|
+
expect(result.request).to eql request
|
127
|
+
end
|
123
128
|
end
|
124
129
|
end
|
125
130
|
|
126
131
|
context 'when the response is #unprocessable_entity? (response_code=422)' do
|
127
132
|
let(:response_code) { 422 }
|
128
133
|
|
129
|
-
it 'returns a RemoteResource::Response object' do
|
130
|
-
|
134
|
+
it 'returns a RemoteResource::Response object with the request' do
|
135
|
+
aggregate_failures do
|
136
|
+
result = request.perform
|
137
|
+
|
138
|
+
expect(result).to be_a RemoteResource::Response
|
139
|
+
expect(result.request).to eql request
|
140
|
+
end
|
131
141
|
end
|
132
142
|
end
|
133
143
|
|
@@ -2,252 +2,185 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe RemoteResource::Response do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module RemoteResource
|
6
|
+
class ResponseDummy
|
7
|
+
include RemoteResource::Base
|
8
|
+
|
9
|
+
self.site = 'http://www.foobar.com'
|
10
|
+
|
11
|
+
attr_accessor :name
|
12
|
+
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
let(:dummy_class) { RemoteResource::ResponseDummy }
|
17
|
+
let(:dummy) { dummy_class.new(id: '12') }
|
18
|
+
|
19
|
+
let(:connection_options) do
|
20
|
+
{ collection: true }
|
15
21
|
end
|
22
|
+
let(:request) { RemoteResource::Request.new(dummy_class, :post, { name: 'Mies' }, connection_options) }
|
23
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 201, body: { id: 12, name: 'Mies' }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
24
|
+
let(:connection_request) { Typhoeus::Request.new('http://www.foobar.com/response_dummies.json', method: :post, body: { name: 'Mies' }.to_json, headers: { 'Content-Type' => 'application/json' }) }
|
16
25
|
|
17
|
-
|
18
|
-
let(:typhoeus_options) { { body: 'typhoeus_response_body', code: 200, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' } } }
|
19
|
-
let(:typhoeus_response) { Typhoeus::Response.new typhoeus_options }
|
20
|
-
let(:response) { described_class.new typhoeus_response }
|
26
|
+
let(:response) { described_class.new(connection_response, connection_options.merge(request: request, connection_request: connection_request)) }
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
response.
|
28
|
+
describe '#request' do
|
29
|
+
it 'returns the RemoteResource::Request' do
|
30
|
+
aggregate_failures do
|
31
|
+
expect(response.request).to be_a RemoteResource::Request
|
32
|
+
expect(response.request).to eql request
|
26
33
|
end
|
27
34
|
end
|
35
|
+
end
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
describe '#success?' do
|
38
|
+
context 'when the response is successful' do
|
39
|
+
it 'returns true' do
|
40
|
+
expect(response.success?).to eql true
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
expect(response.response_code).to eql 200
|
38
|
-
end
|
39
|
-
end
|
44
|
+
context 'when the response is NOT successful' do
|
45
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 422, body: { errors: { name: ['is invalid'] } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
expect(response.response_headers).to eql({ 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' })
|
47
|
+
it 'returns false' do
|
48
|
+
expect(response.success?).to eql false
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
describe '#unprocessable_entity?' do
|
49
|
-
let(:response) { described_class.new double.as_null_object }
|
50
|
-
|
51
54
|
context 'when the response code is 422' do
|
52
|
-
|
53
|
-
allow(response).to receive(:response_code) { 422 }
|
55
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 422, body: { errors: { name: ['is invalid'] } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
54
56
|
|
55
|
-
|
57
|
+
it 'returns true' do
|
58
|
+
expect(response.unprocessable_entity?).to eql true
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
62
|
context 'when the response code is NOT 422' do
|
60
63
|
it 'returns false' do
|
61
|
-
|
62
|
-
|
63
|
-
expect(response.unprocessable_entity?).to be_falsey
|
64
|
+
expect(response.unprocessable_entity?).to eql false
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
describe '#
|
69
|
-
|
69
|
+
describe '#response_code' do
|
70
|
+
it 'returns the response code' do
|
71
|
+
expect(response.response_code).to eql 201
|
72
|
+
end
|
73
|
+
end
|
70
74
|
|
71
|
-
|
75
|
+
describe '#headers' do
|
76
|
+
it 'returns the response headers' do
|
77
|
+
expect(response.headers).to eql({ 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' })
|
78
|
+
end
|
79
|
+
end
|
72
80
|
|
73
|
-
|
74
|
-
|
81
|
+
describe '#body' do
|
82
|
+
it 'returns the response body' do
|
83
|
+
expect(response.body).to eql '{"id":12,"name":"Mies"}'
|
84
|
+
end
|
85
|
+
end
|
75
86
|
|
76
|
-
|
77
|
-
|
78
|
-
|
87
|
+
describe '#parsed_body' do
|
88
|
+
it 'returns the parsed JSON of the response body' do
|
89
|
+
expect(response.parsed_body).to eql({ 'id' => 12, 'name' => 'Mies' })
|
79
90
|
end
|
80
91
|
|
81
|
-
context 'when
|
82
|
-
let(:
|
92
|
+
context 'when the response body is nil' do
|
93
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: nil, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
83
94
|
|
84
95
|
it 'returns an empty Hash' do
|
85
|
-
expect(response.
|
96
|
+
expect(response.parsed_body).to eql({})
|
86
97
|
end
|
87
98
|
end
|
88
99
|
|
89
|
-
context 'when
|
90
|
-
let(:
|
91
|
-
|
92
|
-
before { allow(JSON).to receive(:parse).and_raise JSON::ParserError }
|
100
|
+
context 'when the response body is empty' do
|
101
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: '', headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
93
102
|
|
94
103
|
it 'returns an empty Hash' do
|
95
|
-
expect(response.
|
104
|
+
expect(response.parsed_body).to eql({})
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
99
|
-
context 'when
|
100
|
-
|
101
|
-
let(:connection_options) { { root_element: :foobar } }
|
102
|
-
let(:response) { described_class.new double.as_null_object, connection_options }
|
103
|
-
|
104
|
-
let(:response_body) { '{"foobar":{"id":"12"}}' }
|
108
|
+
context 'when the response body is NOT JSON' do
|
109
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: 'foo', headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
105
110
|
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'and the connection_options do NOT contain a root_element' do
|
112
|
-
let(:response_body) { '{"id":"12"}' }
|
113
|
-
|
114
|
-
it 'returns the parsed response_body' do
|
115
|
-
expect(response.sanitized_response_body).to match({ "id" => "12" })
|
116
|
-
end
|
111
|
+
it 'returns an empty Hash' do
|
112
|
+
expect(response.parsed_body).to eql({})
|
117
113
|
end
|
118
114
|
end
|
119
115
|
end
|
120
116
|
|
121
|
-
describe '#
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
describe '#attributes' do
|
118
|
+
it 'returns the attributes from the parsed response body' do
|
119
|
+
expect(response.attributes).to eql({ 'id' => 12, 'name' => 'Mies' })
|
120
|
+
end
|
125
121
|
|
126
|
-
context 'when
|
127
|
-
let(:
|
122
|
+
context 'when connection_options[:root_element] is present' do
|
123
|
+
let(:connection_options) do
|
124
|
+
{ root_element: :data, collection: true }
|
125
|
+
end
|
126
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 201, body: { data: { id: 12, name: 'Mies' } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
128
127
|
|
129
|
-
it 'returns
|
130
|
-
expect(response.
|
128
|
+
it 'returns the attributes wrapped in the connection_options[:root_element] from the parsed response body' do
|
129
|
+
expect(response.attributes).to eql({ 'id' => 12, 'name' => 'Mies' })
|
131
130
|
end
|
132
131
|
end
|
133
132
|
|
134
|
-
context 'when
|
135
|
-
let(:
|
133
|
+
context 'when the parsed response body is NOT present' do
|
134
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: '', headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
136
135
|
|
137
136
|
it 'returns an empty Hash' do
|
138
|
-
expect(response.
|
137
|
+
expect(response.attributes).to eql({})
|
139
138
|
end
|
140
139
|
end
|
140
|
+
end
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
before { allow(JSON).to receive(:parse).and_raise JSON::ParserError }
|
142
|
+
describe '#errors' do
|
143
|
+
context 'when the parsed response body contains "errors"' do
|
144
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 422, body: { errors: { name: ['is invalid'] } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
146
145
|
|
147
|
-
it 'returns
|
148
|
-
expect(response.
|
146
|
+
it 'returns the errors from the parsed response body' do
|
147
|
+
expect(response.errors).to eql({ 'name' => ['is invalid'] })
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
152
|
-
context 'when
|
153
|
-
|
154
|
-
|
155
|
-
let(:response) { described_class.new double.as_null_object, connection_options }
|
156
|
-
|
157
|
-
let(:response_body) { '{"foobar":{"id":"12"},"meta":{"total":"1"}}' }
|
158
|
-
|
159
|
-
it 'returns the parsed meta from root' do
|
160
|
-
expect(response.sanitized_response_meta).to match({ 'total' => '1' })
|
161
|
-
end
|
151
|
+
context 'when the attributes contains "errors", e.g. when connection_options[:root_element] is present' do
|
152
|
+
let(:connection_options) do
|
153
|
+
{ root_element: :data, collection: true }
|
162
154
|
end
|
155
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 422, body: { data: { errors: { name: ['is invalid'] } } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
163
156
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
it 'returns the parsed meta from root' do
|
168
|
-
expect(response.sanitized_response_meta).to match({ 'total' => '1' })
|
169
|
-
end
|
157
|
+
it 'returns the errors from the attributes' do
|
158
|
+
expect(response.errors).to eql({ 'name' => ['is invalid'] })
|
170
159
|
end
|
171
160
|
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#error_messages_response_body' do
|
175
|
-
let(:response) { described_class.new double.as_null_object }
|
176
|
-
|
177
|
-
before { allow(response).to receive(:response_body) { response_body } }
|
178
|
-
|
179
|
-
context 'when response_body is nil' do
|
180
|
-
let(:response_body) { nil }
|
181
161
|
|
162
|
+
context 'when the "errors" are NOT present' do
|
182
163
|
it 'returns an empty Hash' do
|
183
|
-
expect(response.
|
164
|
+
expect(response.errors).to eql({})
|
184
165
|
end
|
185
166
|
end
|
167
|
+
end
|
186
168
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
expect(response.error_messages_response_body).to eql({})
|
169
|
+
describe '#meta' do
|
170
|
+
context 'when the parsed response body contains "meta"' do
|
171
|
+
let(:connection_options) do
|
172
|
+
{ root_element: :data, collection: true }
|
192
173
|
end
|
193
|
-
|
174
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 201, body: { data: { id: 12, name: 'Mies' }, meta: { total: 10 } }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
194
175
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
before { allow(JSON).to receive(:parse).and_raise JSON::ParserError }
|
199
|
-
|
200
|
-
it 'returns an empty Hash' do
|
201
|
-
expect(response.error_messages_response_body).to eql({})
|
176
|
+
it 'returns the meta information from the parsed response body' do
|
177
|
+
expect(response.meta).to eql({ 'total' => 10 })
|
202
178
|
end
|
203
179
|
end
|
204
180
|
|
205
|
-
context 'when
|
206
|
-
|
207
|
-
|
208
|
-
let(:response) { described_class.new double.as_null_object, connection_options }
|
209
|
-
|
210
|
-
context 'and the response_body contains an error key' do
|
211
|
-
let(:response_body) { '{"errors":{"foo":["is required"]}}' }
|
212
|
-
|
213
|
-
it 'returns the error_messages in the parsed response_body' do
|
214
|
-
expect(response.error_messages_response_body).to eql({ "foo"=>["is required"] })
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
context 'and the response_body contains an error key packed in the root_element' do
|
219
|
-
let(:response_body) { '{"foobar":{"errors":{"foo":["is required"]}}}' }
|
220
|
-
|
221
|
-
it 'returns the error_messages in the parsed response_body unpacked from the root_element' do
|
222
|
-
expect(response.error_messages_response_body).to eql({ "foo"=>["is required"] })
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
context 'and the response_body does NOT contain an error key' do
|
227
|
-
let(:response_body) { '{"id":"12"}' }
|
228
|
-
|
229
|
-
it 'returns an empty Hash' do
|
230
|
-
expect(response.error_messages_response_body).to eql({})
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context 'and the connection_options do NOT contain a root_element' do
|
236
|
-
context 'and the response_body contains an error key' do
|
237
|
-
let(:response_body) { '{"errors":{"foo":["is required"]}}' }
|
238
|
-
|
239
|
-
it 'returns the error_messages in the parsed response_body' do
|
240
|
-
expect(response.error_messages_response_body).to eql({ "foo"=>["is required"] })
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context 'and the response_body does NOT contain an error key' do
|
245
|
-
let(:response_body) { '{"id":"12"}' }
|
246
|
-
|
247
|
-
it 'returns an empty Hash' do
|
248
|
-
expect(response.error_messages_response_body).to eql({})
|
249
|
-
end
|
250
|
-
end
|
181
|
+
context 'when the parsed response body does NOT contain "meta"' do
|
182
|
+
it 'returns an empty Hash' do
|
183
|
+
expect(response.meta).to eql({})
|
251
184
|
end
|
252
185
|
end
|
253
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddy_remote_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan van der Pas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|