lhs 5.0.3 → 5.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 812d60ade41ae3b99d23717d3f75834b142dd1e2
4
- data.tar.gz: bf7385f7f6ee9aead5ee9e55228f8a8cac056f26
3
+ metadata.gz: fc7129b170c58d2a2ecee0756ca0d33cdd2126fa
4
+ data.tar.gz: 58922bfe15024065b77b57adc09348cadfd3168c
5
5
  SHA512:
6
- metadata.gz: 99fb24cfddfa2f0c9bd46dbd4f7397b337314cd65530a9cb717189baf5f4b7012a27f3897aa346280bc2334a9659ea56e2d969277d8fe83a8f024f5ac1ca7bcd
7
- data.tar.gz: 992e9a078d281c5d283412b0963a54de5e83669e5560110c9a44a54cb802b447a1394fe622fa53be0f6297aab8337e523ec94e28b3cacc5b9c1281ab13265c7c
6
+ metadata.gz: 84dfc1caa23ff9932ff85bff35fab58bb5bbfdd08539ad9503bfb3926d1a44c0cb8d298ec1af94be0cf7841081a7d859aca989771a40df4c7681304a79364f81
7
+ data.tar.gz: 11f9058905e009790b21abf82e08f11e3a1b11126a2c356c71a39c437395926f69d6b0dba5d8c0afa8534293a3a16980bf0e755f3a03ad96cb3a76c77d1cac5c
@@ -33,8 +33,9 @@ class LHS::Collection < LHS::Proxy
33
33
  private
34
34
 
35
35
  def cast_item(item)
36
+ record_by_href = LHS::Record.for_url(item[:href]) if item[:href]
36
37
  data = LHS::Data.new(item, @parent, @record)
37
- return @record.new(data) if @record
38
+ return (record_by_href || @record).new(data) if record_by_href || @record
38
39
  data
39
40
  end
40
41
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "5.0.3"
2
+ VERSION = "5.0.4"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Record do
4
+ context 'cast nested data' do
5
+ let(:datastore) { 'http://local.ch/v2' }
6
+
7
+ before(:each) do
8
+ LHC.config.placeholder('datastore', datastore)
9
+ class Customer < LHS::Record
10
+ endpoint ':datastore/customers'
11
+ endpoint ':datastore/customers/:id'
12
+ end
13
+ class Contract < LHS::Record
14
+ endpoint ':datastore/contracts'
15
+ endpoint ':datastore/contracts/:id'
16
+ end
17
+ class Address < LHS::Record
18
+ endpoint ':datastore/addresses'
19
+ endpoint ':datastore/addresses/:id'
20
+ end
21
+ end
22
+
23
+ it 'casts nested data properly' do
24
+ stub_request(:get, "http://local.ch/v2/customers?limit=1")
25
+ .to_return(
26
+ body: {
27
+ items: [
28
+ {
29
+ href: "http://local.ch/v2/customers/12",
30
+ address: {
31
+ href: "http://local.ch/v2/addresses/3"
32
+ },
33
+ contracts: [
34
+ {
35
+ href: "http://local.ch/v2/contracts/2"
36
+ }
37
+ ]
38
+ }
39
+ ]
40
+ }.to_json
41
+ )
42
+ customer = Customer.first
43
+ expect(customer).to be_kind_of Customer
44
+ expect(customer.address).to be_kind_of Address
45
+ expect(customer.contracts.first).to be_kind_of Contract
46
+ end
47
+ end
48
+ 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: 5.0.3
4
+ version: 5.0.4
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: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -279,6 +279,7 @@ files:
279
279
  - spec/rails_helper.rb
280
280
  - spec/record/all_spec.rb
281
281
  - spec/record/build_spec.rb
282
+ - spec/record/cast_nested_data_spec.rb
282
283
  - spec/record/create_spec.rb
283
284
  - spec/record/creation_failed_spec.rb
284
285
  - spec/record/definitions_spec.rb
@@ -410,6 +411,7 @@ test_files:
410
411
  - spec/rails_helper.rb
411
412
  - spec/record/all_spec.rb
412
413
  - spec/record/build_spec.rb
414
+ - spec/record/cast_nested_data_spec.rb
413
415
  - spec/record/create_spec.rb
414
416
  - spec/record/creation_failed_spec.rb
415
417
  - spec/record/definitions_spec.rb