lhs 12.2.0 → 12.2.1
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/lib/lhs/proxy.rb +16 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/record/reload_by_id_spec.rb +41 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cf5dca801873de0a2f1dce552f1c0a0fed9193
|
4
|
+
data.tar.gz: cfcc3159765215d4319c26c8dca56cc82bca8263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3605514ae588fe9ddfd1fb2e4496d9e39512dcf2830873c86844dbddf118776baf7507ac3d949a279e6a8bebc1f28dd43a1cd14bf1435b1834a779582b2834b2
|
7
|
+
data.tar.gz: 9e10cc9fb96fc06dc42541908b1daec77bc0cedd1162d042fd92595c0a388226d22e47892dd9d7cb20e283624a6dfcb65d88c1ca3080a1ca4f50b8396c10f1f8
|
data/lib/lhs/proxy.rb
CHANGED
@@ -17,6 +17,7 @@ class LHS::Proxy
|
|
17
17
|
|
18
18
|
# prevent clashing with attributes of underlying data
|
19
19
|
attr_accessor :_data, :_loaded
|
20
|
+
delegate :_record, to: :_data, allow_nil: true
|
20
21
|
|
21
22
|
def initialize(data)
|
22
23
|
self._data = data
|
@@ -33,12 +34,24 @@ class LHS::Proxy
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def reload!(options = nil)
|
36
|
-
raise 'No href found' unless _data.href
|
37
37
|
options = {} if options.blank?
|
38
|
-
|
39
|
-
|
38
|
+
data = _data.class.request(
|
39
|
+
options.merge(method: :get).merge(reload_options)
|
40
|
+
)
|
40
41
|
_data.merge_raw!(data)
|
41
42
|
self._loaded = true
|
42
43
|
self
|
43
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def as_record
|
49
|
+
@as_record ||= becomes(_record)
|
50
|
+
end
|
51
|
+
|
52
|
+
def reload_options
|
53
|
+
return { url: _data.href } if _data.href
|
54
|
+
return { params: { id: as_record.id } } if as_record.id
|
55
|
+
{}
|
56
|
+
end
|
44
57
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
before(:each) do
|
5
|
+
class Record < LHS::Record
|
6
|
+
endpoint 'http://datastore/records'
|
7
|
+
endpoint 'http://datastore/records/:id'
|
8
|
+
end
|
9
|
+
|
10
|
+
class AnotherRecord < LHS::Record
|
11
|
+
endpoint 'http://datastore/otherrecords'
|
12
|
+
endpoint 'http://datastore/otherrecords/:id'
|
13
|
+
|
14
|
+
def id
|
15
|
+
another_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'reload!' do
|
21
|
+
it 'reloads the record by id' do
|
22
|
+
stub_request(:post, "http://datastore/records")
|
23
|
+
.to_return(body: { id: 1, name: 'Steve' }.to_json)
|
24
|
+
record = Record.create!(name: 'Steve')
|
25
|
+
stub_request(:get, "http://datastore/records/1")
|
26
|
+
.to_return(body: { id: 1, name: 'Steve', async: 'data' }.to_json)
|
27
|
+
record.reload!
|
28
|
+
expect(record.async).to eq 'data'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'reloads the record by id if a record method defines the actual id' do
|
32
|
+
stub_request(:post, "http://datastore/otherrecords")
|
33
|
+
.to_return(body: { another_id: 2, name: 'Can' }.to_json)
|
34
|
+
record = AnotherRecord.create!(name: 'Can')
|
35
|
+
stub_request(:get, "http://datastore/otherrecords/2")
|
36
|
+
.to_return(body: { id: 2, name: 'Can', async: 'data' }.to_json)
|
37
|
+
record.reload!
|
38
|
+
expect(record.async).to eq 'data'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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: 12.2.
|
4
|
+
version: 12.2.1
|
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-
|
11
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -373,6 +373,7 @@ files:
|
|
373
373
|
- spec/record/pagination_spec.rb
|
374
374
|
- spec/record/persisted_spec.rb
|
375
375
|
- spec/record/references_spec.rb
|
376
|
+
- spec/record/reload_by_id_spec.rb
|
376
377
|
- spec/record/request_spec.rb
|
377
378
|
- spec/record/save_spec.rb
|
378
379
|
- spec/record/scope_chains_spec.rb
|
@@ -543,6 +544,7 @@ test_files:
|
|
543
544
|
- spec/record/pagination_spec.rb
|
544
545
|
- spec/record/persisted_spec.rb
|
545
546
|
- spec/record/references_spec.rb
|
547
|
+
- spec/record/reload_by_id_spec.rb
|
546
548
|
- spec/record/request_spec.rb
|
547
549
|
- spec/record/save_spec.rb
|
548
550
|
- spec/record/scope_chains_spec.rb
|