lhs 14.3.1 → 14.3.2

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: 592b02ea75646240c5b91bedd2c780898ed87a4b
4
- data.tar.gz: b91803f278dbdc05c0b1c5405a75d7daa3191116
3
+ metadata.gz: 23918846d8c64e8753d97597980490a1e81727db
4
+ data.tar.gz: 0b7aa7f5dc6a6621959f76391aab092b69655b46
5
5
  SHA512:
6
- metadata.gz: 61c954708c2abf0147112c0d34ec044ef0f9dd4e53f75b26db3a26f430b138ff203127e1dc49a45066fe02c1cce9806a6b0dab7338fc207fc8b87547890aa29a
7
- data.tar.gz: 088c03a54f417a2844bc6a85e318e42ea0d2a12540cc3745a2c1c20940448848c2760413eb180a5b8c0154b829a737eb76a04ab4296036c45a1cabad487039ce
6
+ metadata.gz: ed8155be2929a3ba33c54f3f26b8f3c7d3dc55ab86a71b235eda98001e4132e4b979d2e294c6e066950aa770fc839ee9498461a554ae69123f5354fd4df15dfe
7
+ data.tar.gz: 85f20098c747b9e2f3596169ef1f48e2577f95e5f53cc0b97c39aeaaaa86c226b62a5db6c9d97357bf8f99c04624e9c677d9f41b9f248946396cba412c83ad65
@@ -34,12 +34,11 @@ class LHS::Item < LHS::Proxy
34
34
 
35
35
  def create_and_merge_data!(options)
36
36
  direct_response_data = record.request(options)
37
- nested_path = record.item_created_key ? record.item_created_key : nil
38
- _data.merge_raw!(direct_response_data, nested_path)
37
+ _data.merge_raw!(direct_response_data.unwrap(:item_created_key))
39
38
  response_headers = direct_response_data._request.response.headers
40
39
  if response_headers && response_headers['Location']
41
40
  location_data = record.request(options.merge(url: response_headers['Location'], method: :get, body: nil))
42
- _data.merge_raw!(location_data, nested_path)
41
+ _data.merge_raw!(location_data.unwrap(:item_created_key))
43
42
  end
44
43
  true
45
44
  end
@@ -26,8 +26,7 @@ class LHS::Item < LHS::Proxy
26
26
  def update!(params, options = {}, partial_update = false)
27
27
  options ||= {}
28
28
  partial_data = LHS::Data.new(params, _data.parent, record)
29
- nested_path = record.item_created_key ? record.item_created_key : nil
30
- _data.merge_raw!(partial_data, nested_path)
29
+ _data.merge_raw!(partial_data)
31
30
  data_sent = partial_update ? partial_data : _data
32
31
  url = href || record.find_endpoint(id: id).compile(id: id)
33
32
  response_data = record.request(
@@ -38,8 +37,7 @@ class LHS::Item < LHS::Proxy
38
37
  headers: { 'Content-Type' => 'application/json' }
39
38
  )
40
39
  )
41
- nested_path = record.item_created_key ? record.item_created_key : nil
42
- _data.merge_raw!(response_data, nested_path)
40
+ _data.merge_raw!(response_data.unwrap(:item_created_key))
43
41
  true
44
42
  end
45
43
  end
@@ -28,11 +28,18 @@ class LHS::Data
28
28
 
29
29
  # merging data
30
30
  # e.g. when loading remote data via link
31
- def merge_raw!(data, nested_path = nil)
31
+ def merge_raw!(data)
32
32
  return false if data.blank? || !data._raw.is_a?(Hash)
33
- raw = data._raw.dig(*nested_path) if nested_path
34
- raw ||= data._raw
35
- _raw.merge! raw
33
+ _raw.merge! data._raw
34
+ end
35
+
36
+ # Unwraps data for certain use cases
37
+ # like items_created_key for CREATE, UPDATED etc.
38
+ # like item_key for GET etc.
39
+ def unwrap(usecase)
40
+ nested_path = record.send(usecase) if record
41
+ return LHS::Data.new(dig(*nested_path) || _raw, nil, self.class) if nested_path
42
+ self
36
43
  end
37
44
 
38
45
  def _root
@@ -38,7 +38,7 @@ class LHS::Proxy
38
38
  data = _data.class.request(
39
39
  options.merge(method: :get).merge(reload_options)
40
40
  )
41
- _data.merge_raw!(data)
41
+ _data.merge_raw!(data.unwrap(:item_key))
42
42
  self._loaded = true
43
43
  return becomes(_record) if _record
44
44
  self
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '14.3.1'
2
+ VERSION = '14.3.2'
3
3
  end
@@ -21,4 +21,43 @@ describe LHS::Record do
21
21
  expect(record.reload!).to be_kind_of Record
22
22
  end
23
23
  end
24
+
25
+ context 'nested items' do
26
+
27
+ before(:each) do
28
+ class Location < LHS::Record
29
+ endpoint 'http://uberall/locations'
30
+ endpoint 'http://uberall/locations/:id'
31
+
32
+ configuration item_key: [:response, :location], items_key: [:response, :locations]
33
+ end
34
+ end
35
+
36
+ it 'merges reloads properly' do
37
+ stub_request(:get, "http://uberall/locations?identifier=http://places/1&limit=1")
38
+ .to_return(
39
+ body: {
40
+ response: {
41
+ locations: [{
42
+ id: 1,
43
+ name: 'Fridolin'
44
+ }]
45
+ }
46
+ }.to_json
47
+ )
48
+ location = Location.find_by(identifier: 'http://places/1')
49
+ stub_request(:get, "http://uberall/locations/1")
50
+ .to_return(
51
+ body: {
52
+ response: {
53
+ location: {
54
+ normalizationStatus: 'NORMALIZED'
55
+ }
56
+ }
57
+ }.to_json
58
+ )
59
+ location.reload!
60
+ expect(location.normalizationStatus).to eq 'NORMALIZED'
61
+ end
62
+ end
24
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.3.1
4
+ version: 14.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc