lhs 16.1.1 → 16.1.2
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/concerns/proxy/accessors.rb +7 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/record/has_one_spec.rb +20 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07100d466b8e07fda10f73bf8b76c45eee3caf8d187221e919e8ea9fb32a795e
|
4
|
+
data.tar.gz: 92aa74f46a7f46df4d76c18b3ae9c6b57cc1aae8d6c55ae14c793acad5cd086a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f31cbc7ea4f1b72c49aa5953a66857b0d8128ed7b6a521d3b61fe1f7eceb8f11c13e0a31bb69a069ab8db1fc758f6c9d367250bcecb09324c8899e331aed580d
|
7
|
+
data.tar.gz: 15be398c376a80e30ada0f68ad3be7bc1265525eeec7a911046b41c34aaf17f759299492574774f2c393132dae392b4a29b21ce73f81cbadf9aafd98444c21b3
|
@@ -13,6 +13,7 @@ class LHS::Proxy
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def set(name, value)
|
16
|
+
clear_cache!
|
16
17
|
key = name.to_s.gsub(/=$/, '')
|
17
18
|
_data._raw[key.to_sym] = value
|
18
19
|
end
|
@@ -76,10 +77,11 @@ class LHS::Proxy
|
|
76
77
|
data = (value.is_a?(LHS::Data) || value.is_a?(LHS::Record)) ? value : LHS::Data.new(value, _data, _record, _request)
|
77
78
|
data.errors = LHS::Problems::Nested::Errors.new(errors, name) if errors.any?
|
78
79
|
data.warnings = LHS::Problems::Nested::Warnings.new(warnings, name) if warnings.any?
|
79
|
-
return data.becomes(record) if record && !value.is_a?(LHS::Record)
|
80
80
|
if _record && _record._relations[name]
|
81
81
|
klass = _record._relations[name][:record_class_name].constantize
|
82
82
|
return cache.compute_if_absent(klass) { data.becomes(klass) }
|
83
|
+
elsif record && !value.is_a?(LHS::Record)
|
84
|
+
return data.becomes(record)
|
83
85
|
end
|
84
86
|
data
|
85
87
|
end
|
@@ -111,5 +113,9 @@ class LHS::Proxy
|
|
111
113
|
def cache
|
112
114
|
@cache ||= Concurrent::Map.new
|
113
115
|
end
|
116
|
+
|
117
|
+
def clear_cache!
|
118
|
+
@cache = nil
|
119
|
+
end
|
114
120
|
end
|
115
121
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/has_one_spec.rb
CHANGED
@@ -10,7 +10,8 @@ describe LHS::Record do
|
|
10
10
|
stub_request(:get, "http://myservice/transactions/#{id}")
|
11
11
|
.to_return(body: {
|
12
12
|
user: {
|
13
|
-
email_address: 'steve@local.ch'
|
13
|
+
email_address: 'steve@local.ch',
|
14
|
+
comments: []
|
14
15
|
}
|
15
16
|
}.to_json)
|
16
17
|
end
|
@@ -26,11 +27,15 @@ describe LHS::Record do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
class User < LHS::Record
|
30
|
+
has_many :comments
|
29
31
|
|
30
32
|
def email
|
31
33
|
self[:email_address]
|
32
34
|
end
|
33
35
|
end
|
36
|
+
|
37
|
+
class Comment < LHS::Record
|
38
|
+
end
|
34
39
|
end
|
35
40
|
|
36
41
|
it 'casts the relation into the correct type' do
|
@@ -43,11 +48,21 @@ describe LHS::Record do
|
|
43
48
|
expect(user.parent._raw).to eq transaction._raw
|
44
49
|
end
|
45
50
|
|
46
|
-
it 'the relation
|
47
|
-
|
48
|
-
|
51
|
+
it 'caches the relation in memory' do
|
52
|
+
allow(LHS::Record).to receive(:for_url).and_return(User)
|
53
|
+
user_object_id = transaction.user.object_id
|
54
|
+
expect(transaction.user.object_id).to eql(user_object_id)
|
49
55
|
transaction2 = Transaction.find(2)
|
50
|
-
expect(transaction2.user.object_id).not_to eql(
|
56
|
+
expect(transaction2.user.object_id).not_to eql(user_object_id)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'recalculates cache for relation when it was modified' do
|
60
|
+
allow(LHS::Record).to receive(:for_url).and_return(Comment)
|
61
|
+
expect(user.comments).to be_blank
|
62
|
+
comments_object_id = user.comments.object_id
|
63
|
+
user.comments = [Comment.new]
|
64
|
+
expect(user.comments.object_id).not_to eql(comments_object_id)
|
65
|
+
expect(user.comments).not_to be_blank
|
51
66
|
end
|
52
67
|
end
|
53
68
|
|