ddy_remote_resource 1.0.0.rc4 → 1.0.0.rc5

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: bccfcf5609907813018b9d01ee5c73c5e114a000
4
- data.tar.gz: 459e6e2e2378a785bf9e7ed9248113c713d26429
3
+ metadata.gz: d688cecc3f4a1d713c2527d47a99cf88f81c9bfb
4
+ data.tar.gz: 11a9c8c67d6ed14e4aa46dd9de09079204ca0507
5
5
  SHA512:
6
- metadata.gz: 71e2e8d6c00dfb31b27671c7d13c2057b90863f75bfd12e65986a53a9bb7240a1db85ef15a25357fbc4d808b35285973ad86b1921c85a311637b4ae162afb9d7
7
- data.tar.gz: 9d87d498ff3d0585abadacee169f7419c44af52a16c2af24ca62275da16e1bb9c72bf2a2c4f379a524895150edac78c3f938ead42af4aa838917fe090e045e82
6
+ metadata.gz: dc32aaed683143cf08c8a96b80adcf41d98a369cd7313ae1eabf9a527a0c9e861f41d468621b1518582d686593e097ce8e27209ae2ddbfbeaacb53cd0c4779aa
7
+ data.tar.gz: 1e47f7498e9f70cff6b708d73f1e1af8189e88c3c50b422989c33abecdec0beb7ac733877d244b9b5283ba65b508dd96997d085a5f02dd1db33e3db17c629578
@@ -45,7 +45,7 @@ module RemoteResource
45
45
  root_element = @connection_options[:root_element]
46
46
 
47
47
  if root_element.present?
48
- parsed_body[root_element.to_s]
48
+ parsed_body.try(:key?, root_element.to_s) && parsed_body[root_element.to_s]
49
49
  else
50
50
  parsed_body
51
51
  end.presence || {}
@@ -53,11 +53,11 @@ module RemoteResource
53
53
  end
54
54
 
55
55
  def errors
56
- @errors ||= parsed_body['errors'].presence || attributes['errors'].presence || {}
56
+ @errors ||= parsed_body.try(:key?, 'errors') && parsed_body['errors'].presence || attributes.try(:key?, 'errors') && attributes['errors'].presence || {}
57
57
  end
58
58
 
59
59
  def meta
60
- @meta ||= parsed_body['meta'].presence || {}
60
+ @meta ||= parsed_body.try(:key?, 'meta') && parsed_body['meta'].presence || {}
61
61
  end
62
62
 
63
63
  end
@@ -1,3 +1,3 @@
1
1
  module RemoteResource
2
- VERSION = '1.0.0.rc4'.freeze
2
+ VERSION = '1.0.0.rc5'.freeze
3
3
  end
@@ -130,6 +130,17 @@ RSpec.describe RemoteResource::Response do
130
130
  end
131
131
  end
132
132
 
133
+ context 'when connection_options[:root_element] is present and the parsed response body has NO keys' do
134
+ let(:connection_options) do
135
+ { root_element: :data, collection: true }
136
+ end
137
+ let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
138
+
139
+ it 'returns an empty Hash' do
140
+ expect(response.attributes).to eql({})
141
+ end
142
+ end
143
+
133
144
  context 'when the parsed response body is NOT present' do
134
145
  let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: '', headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
135
146
 
@@ -164,6 +175,25 @@ RSpec.describe RemoteResource::Response do
164
175
  expect(response.errors).to eql({})
165
176
  end
166
177
  end
178
+
179
+ context 'when the parsed response body does NOT contain keys' do
180
+ let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
181
+
182
+ it 'returns an empty Hash' do
183
+ expect(response.errors).to eql({})
184
+ end
185
+ end
186
+
187
+ context 'when the attributes do NOT contain keys, e.g. when connection_options[:root_element] is present' do
188
+ let(:connection_options) do
189
+ { root_element: :data, collection: true }
190
+ end
191
+ let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: { data: [{ id: 12, name: 'Mies' }] }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
192
+
193
+ it 'returns an empty Hash' do
194
+ expect(response.errors).to eql({})
195
+ end
196
+ end
167
197
  end
168
198
 
169
199
  describe '#meta' do
@@ -183,6 +213,14 @@ RSpec.describe RemoteResource::Response do
183
213
  expect(response.meta).to eql({})
184
214
  end
185
215
  end
216
+
217
+ context 'when the parsed response body does NOT contain keys' do
218
+ let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
219
+
220
+ it 'returns an empty Hash' do
221
+ expect(response.meta).to eql({})
222
+ end
223
+ end
186
224
  end
187
225
 
188
226
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RemoteResource::VERSION do
4
- it { is_expected.to eql '1.0.0.rc4' }
4
+ it { is_expected.to eql '1.0.0.rc5' }
5
5
  end
6
6
 
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddy_remote_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc4
4
+ version: 1.0.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan van der Pas