lhs 18.0.1 → 18.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/concerns/proxy/accessors.rb +4 -4
- data/lib/lhs/concerns/record/request.rb +1 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/record/has_many_spec.rb +0 -1
- data/spec/record/has_one_spec.rb +0 -18
- data/spec/record/relation_caching_spec.rb +121 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8fbb44e36e8084a69be5ffd72ec91f10d6d76833aa7af2051da5a75078eb1cc
|
4
|
+
data.tar.gz: 606eee69ad3c2672d1a47b7a0fce0fa28d53ff4ebb7cb49fefbb3417fa6e9646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7de12cf03b8070bf8eacceb74f1ce517f4493d25cac3a96c3b6c7a829b1c9042a052a1569fc4e836e24efaf5e6dc24564b0e4b027d746527ba0ab515712d0e0f
|
7
|
+
data.tar.gz: b53a6aa74e78dbfcb55326c405c347bfe7dbb712dc740fcfc795164ca55c25018f85443ee92b7c622d1cefea50ce7a8f1aa3d6eee50abf5084f5158ab6f31819
|
@@ -12,6 +12,10 @@ class LHS::Proxy
|
|
12
12
|
|
13
13
|
delegate :dig, :fetch, to: :_raw, allow_nil: true
|
14
14
|
|
15
|
+
def clear_cache!
|
16
|
+
@cache = nil
|
17
|
+
end
|
18
|
+
|
15
19
|
private
|
16
20
|
|
17
21
|
def set(name, value)
|
@@ -117,9 +121,5 @@ class LHS::Proxy
|
|
117
121
|
def cache
|
118
122
|
@cache ||= Concurrent::Map.new
|
119
123
|
end
|
120
|
-
|
121
|
-
def clear_cache!
|
122
|
-
@cache = nil
|
123
|
-
end
|
124
124
|
end
|
125
125
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/has_one_spec.rb
CHANGED
@@ -20,7 +20,6 @@ describe LHS::Record do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'has_one' do
|
23
|
-
|
24
23
|
before do
|
25
24
|
class Transaction < LHS::Record
|
26
25
|
endpoint 'http://myservice/transactions'
|
@@ -49,23 +48,6 @@ describe LHS::Record do
|
|
49
48
|
expect(user._root._raw).to eq transaction._raw
|
50
49
|
expect(user.parent._raw).to eq transaction._raw
|
51
50
|
end
|
52
|
-
|
53
|
-
it 'caches the relation in memory' do
|
54
|
-
allow(LHS::Record).to receive(:for_url).and_return(User)
|
55
|
-
user_object_id = transaction.user.object_id
|
56
|
-
expect(transaction.user.object_id).to eql(user_object_id)
|
57
|
-
transaction2 = Transaction.find(2)
|
58
|
-
expect(transaction2.user.object_id).not_to eql(user_object_id)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'recalculates cache for relation when it was modified' do
|
62
|
-
allow(LHS::Record).to receive(:for_url).and_return(Comment)
|
63
|
-
expect(user.comments).to be_blank
|
64
|
-
comments_object_id = user.comments.object_id
|
65
|
-
user.comments = [Comment.new]
|
66
|
-
expect(user.comments.object_id).not_to eql(comments_object_id)
|
67
|
-
expect(user.comments).not_to be_blank
|
68
|
-
end
|
69
51
|
end
|
70
52
|
|
71
53
|
context 'custom class_name' do
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHS::Record do
|
6
|
+
context 'cache' do
|
7
|
+
let(:transaction) { Transaction.find(1) }
|
8
|
+
let(:user) { transaction.user }
|
9
|
+
|
10
|
+
before do
|
11
|
+
class Transaction < LHS::Record
|
12
|
+
endpoint 'http://myservice/transactions'
|
13
|
+
endpoint 'http://myservice/transactions/{id}'
|
14
|
+
has_one :user
|
15
|
+
end
|
16
|
+
|
17
|
+
class User < LHS::Record
|
18
|
+
has_many :comments
|
19
|
+
|
20
|
+
def email
|
21
|
+
self[:email_address]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Comment < LHS::Record
|
26
|
+
end
|
27
|
+
|
28
|
+
[1, 2].each do |id|
|
29
|
+
stub_request(:get, "http://myservice/transactions/#{id}")
|
30
|
+
.to_return(body: {
|
31
|
+
user: {
|
32
|
+
email_address: 'steve@local.ch',
|
33
|
+
comments: []
|
34
|
+
}
|
35
|
+
}.to_json)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'caches the relation in memory' do
|
40
|
+
allow(LHS::Record).to receive(:for_url).and_return(User)
|
41
|
+
user_object_id = transaction.user.object_id
|
42
|
+
expect(transaction.user.object_id).to eql(user_object_id)
|
43
|
+
transaction2 = Transaction.find(2)
|
44
|
+
expect(transaction2.user.object_id).not_to eql(user_object_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'recalculates cache for relation when it was modified' do
|
48
|
+
allow(LHS::Record).to receive(:for_url).and_return(Comment)
|
49
|
+
expect(user.comments).to be_blank
|
50
|
+
comments_object_id = user.comments.object_id
|
51
|
+
user.comments = [Comment.new]
|
52
|
+
expect(user.comments.object_id).not_to eql(comments_object_id)
|
53
|
+
expect(user.comments).not_to be_blank
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'clear cache' do
|
58
|
+
before do
|
59
|
+
class Place < LHS::Record
|
60
|
+
endpoint 'https://datastore/places/{id}', followlocation: true, headers: { 'Prefer' => 'redirect-strategy=redirect-over-not-found' }
|
61
|
+
has_many :available_assets
|
62
|
+
end
|
63
|
+
|
64
|
+
class AvailableAsset < LHS::Record
|
65
|
+
end
|
66
|
+
|
67
|
+
stub_request(:get, "http://datastore/places/#{place_id}/available-assets?limit=100")
|
68
|
+
.to_return(body: {
|
69
|
+
total: available_assets.size,
|
70
|
+
items: available_assets
|
71
|
+
}.to_json)
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:place_id) { SecureRandom.urlsafe_base64 }
|
75
|
+
|
76
|
+
let(:place_hash) do
|
77
|
+
{
|
78
|
+
href: "https://datastore/places/#{place_id}",
|
79
|
+
id: place_id,
|
80
|
+
available_assets: { href: "http://datastore/places/#{place_id}/available-assets?offset=0&limit=10" }
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:available_asset_hash) do
|
85
|
+
{ asset_code: 'OPENING_HOURS' }
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:available_assets) { [available_asset_hash] }
|
89
|
+
|
90
|
+
it 'clears the cache when using find' do
|
91
|
+
stub_request(:get, place_hash[:href])
|
92
|
+
.to_return(body: place_hash.to_json)
|
93
|
+
place = Place
|
94
|
+
.options(auth: { bearer: 'XYZ' })
|
95
|
+
.includes_all(:available_assets)
|
96
|
+
.find(place_id)
|
97
|
+
expect(place.available_assets.first).to be_a(AvailableAsset)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'clears the cache when using where' do
|
101
|
+
stub_request(:get, place_hash[:href])
|
102
|
+
.to_return(body: place_hash.to_json)
|
103
|
+
place = Place
|
104
|
+
.options(auth: { bearer: 'XYZ' })
|
105
|
+
.includes_all(:available_assets)
|
106
|
+
.where(id: place_id)
|
107
|
+
expect(place.available_assets.first).to be_a(AvailableAsset)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'clears the cache when using find_by' do
|
111
|
+
stub_request(:get, "https://datastore/places/#{place_id}?limit=1")
|
112
|
+
.to_return(body: place_hash.to_json)
|
113
|
+
place = Place
|
114
|
+
.options(auth: { bearer: 'XYZ' })
|
115
|
+
.includes_all(:available_assets)
|
116
|
+
.find_by(id: place_id)
|
117
|
+
expect(place.available_assets.first).to be_a(AvailableAsset)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
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: 18.0.
|
4
|
+
version: 18.0.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: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -427,6 +427,7 @@ files:
|
|
427
427
|
- spec/record/pagination_spec.rb
|
428
428
|
- spec/record/persisted_spec.rb
|
429
429
|
- spec/record/references_spec.rb
|
430
|
+
- spec/record/relation_caching_spec.rb
|
430
431
|
- spec/record/reload_by_id_spec.rb
|
431
432
|
- spec/record/reload_spec.rb
|
432
433
|
- spec/record/request_spec.rb
|
@@ -626,6 +627,7 @@ test_files:
|
|
626
627
|
- spec/record/pagination_spec.rb
|
627
628
|
- spec/record/persisted_spec.rb
|
628
629
|
- spec/record/references_spec.rb
|
630
|
+
- spec/record/relation_caching_spec.rb
|
629
631
|
- spec/record/reload_by_id_spec.rb
|
630
632
|
- spec/record/reload_spec.rb
|
631
633
|
- spec/record/request_spec.rb
|