thermos 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thermos/beverage.rb +7 -1
- data/lib/thermos/refill_job.rb +2 -4
- data/lib/thermos/version.rb +1 -1
- data/test/dummy/app/models/category.rb +4 -0
- data/test/fixtures/stores.yml +2 -0
- data/test/thermos_test.rb +83 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d08a67a8ad98400b2b0eda1e63af9b22cb127e82d72117c6dbb8fecb71a808
|
4
|
+
data.tar.gz: 8a8369af0507aae7ef1c81ddf0bc7833adea0bd5941708c183c8c011b3e7db22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9f06c52aa92a34a3beacd1384b8f4de92318484a536d657a1a8c3b5a5017ec09d42f6b99b95966b8e3572fdaf57d8c01dd2a0c8ec6b9eb99490ac413e1ca88
|
7
|
+
data.tar.gz: 3215b079c3890c74045ff902bcf259dc83d1d40e4ff5ee0c69be0833a959aa4e25dd7e92fbe9738fd18352223a6c050810d2065a9ab4bf25d45e0d87003d2889
|
data/lib/thermos/beverage.rb
CHANGED
@@ -19,9 +19,15 @@ module Thermos
|
|
19
19
|
@deps.select do |dep|
|
20
20
|
dep.klass == dep_model.class
|
21
21
|
end.flat_map do |dep|
|
22
|
+
lookup_keys = []
|
23
|
+
|
22
24
|
@model.joins(dep.path)
|
23
25
|
.where(dep.table => { id: dep_model.id })
|
24
|
-
.
|
26
|
+
.find_each do |model|
|
27
|
+
lookup_keys << model.send(@lookup_key) if should_fill?(model)
|
28
|
+
end
|
29
|
+
|
30
|
+
lookup_keys
|
25
31
|
end.uniq
|
26
32
|
end
|
27
33
|
|
data/lib/thermos/refill_job.rb
CHANGED
@@ -17,10 +17,8 @@ module Thermos
|
|
17
17
|
|
18
18
|
def refill_dependency_caches(model)
|
19
19
|
BeverageStorage.instance.beverages.each do |beverage|
|
20
|
-
|
21
|
-
|
22
|
-
Thermos::RebuildCacheJob.perform_later(beverage.key, lookup_key)
|
23
|
-
end
|
20
|
+
beverage.lookup_keys_for_dep_model(model).each do |lookup_key|
|
21
|
+
Thermos::RebuildCacheJob.perform_later(beverage.key, lookup_key)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
data/lib/thermos/version.rb
CHANGED
data/test/fixtures/stores.yml
CHANGED
data/test/thermos_test.rb
CHANGED
@@ -161,6 +161,28 @@ class ThermosTest < ActiveSupport::TestCase
|
|
161
161
|
assert_raises(MockExpectationError) { mock.verify }
|
162
162
|
end
|
163
163
|
|
164
|
+
test "allows filtering based on the beverage when multiple beverages are configured and only one of them has a filter" do
|
165
|
+
mock = Minitest::Mock.new
|
166
|
+
store = stores(:supermarket)
|
167
|
+
category = categories(:baseball)
|
168
|
+
# filter method specific to one model
|
169
|
+
# store.ball? doesn't exist
|
170
|
+
filter = ->(model) { model.ball? }
|
171
|
+
|
172
|
+
Thermos.fill(key: "key", model: Category, lookup_key: "name", filter: filter) do |name|
|
173
|
+
mock.call(name)
|
174
|
+
end
|
175
|
+
|
176
|
+
Thermos.fill(key: "key_2", model: Store, lookup_key: "name") do |name|
|
177
|
+
mock.call(name)
|
178
|
+
end
|
179
|
+
|
180
|
+
mock.expect(:call, 1, ["groceries"])
|
181
|
+
store.update!(name: "groceries")
|
182
|
+
assert_equal 1, Thermos.drink(key: "key_2", id: "groceries")
|
183
|
+
mock.verify
|
184
|
+
end
|
185
|
+
|
164
186
|
# has_many model changes
|
165
187
|
test "rebuilds the cache on has_many model change" do
|
166
188
|
mock = Minitest::Mock.new
|
@@ -223,6 +245,26 @@ class ThermosTest < ActiveSupport::TestCase
|
|
223
245
|
assert_raises(MockExpectationError) { mock.verify }
|
224
246
|
end
|
225
247
|
|
248
|
+
test "re-builds the cache for has_many record changes when filter condition is met" do
|
249
|
+
mock = Minitest::Mock.new
|
250
|
+
category = categories(:baseball)
|
251
|
+
filter = ->(model) { model.ball? }
|
252
|
+
|
253
|
+
Thermos.fill(key: "key", model: Category, deps: [:category_items], filter: filter) do |id|
|
254
|
+
mock.call(id)
|
255
|
+
end
|
256
|
+
|
257
|
+
mock.expect(:call, 1, [category.id])
|
258
|
+
CategoryItem.create!(category: category)
|
259
|
+
mock.verify
|
260
|
+
|
261
|
+
category.update!(name: "hockey")
|
262
|
+
|
263
|
+
mock.expect(:call, 1, [category.id])
|
264
|
+
CategoryItem.create!(category: category)
|
265
|
+
assert_raises(MockExpectationError) { mock.verify }
|
266
|
+
end
|
267
|
+
|
226
268
|
# belongs_to model changes
|
227
269
|
test "rebuilds the cache on belongs_to model change" do
|
228
270
|
mock = Minitest::Mock.new
|
@@ -286,6 +328,27 @@ class ThermosTest < ActiveSupport::TestCase
|
|
286
328
|
assert_raises(MockExpectationError) { mock.verify }
|
287
329
|
end
|
288
330
|
|
331
|
+
test "re-builds the cache for belongs_to record changes when filter condition is met" do
|
332
|
+
mock = Minitest::Mock.new
|
333
|
+
category = categories(:baseball)
|
334
|
+
filter = ->(model) { model.ball? }
|
335
|
+
|
336
|
+
Thermos.fill(key: "key", model: Category, deps: [:store], filter: filter) do |id|
|
337
|
+
mock.call(id)
|
338
|
+
end
|
339
|
+
|
340
|
+
mock.expect(:call, 1, [category.id])
|
341
|
+
mock.expect(:call, 1, [category.id])
|
342
|
+
Store.create!(name: "foo", categories: [category])
|
343
|
+
mock.verify
|
344
|
+
|
345
|
+
category.update!(name: "hockey")
|
346
|
+
|
347
|
+
mock.expect(:call, 2, [category.id])
|
348
|
+
Store.create!(name: "bar", categories: [category])
|
349
|
+
assert_raises(MockExpectationError) { mock.verify }
|
350
|
+
end
|
351
|
+
|
289
352
|
# has_many through model changes
|
290
353
|
test "rebuilds the cache on has_many through model change" do
|
291
354
|
mock = Minitest::Mock.new
|
@@ -348,6 +411,26 @@ class ThermosTest < ActiveSupport::TestCase
|
|
348
411
|
assert_raises(MockExpectationError) { mock.verify }
|
349
412
|
end
|
350
413
|
|
414
|
+
test "re-builds the cache for has_many through record changes when filter condition is met" do
|
415
|
+
mock = Minitest::Mock.new
|
416
|
+
category = categories(:baseball)
|
417
|
+
filter = ->(model) { model.ball? }
|
418
|
+
|
419
|
+
Thermos.fill(key: "key", model: Category, deps: [:products], filter: filter) do |id|
|
420
|
+
mock.call(id)
|
421
|
+
end
|
422
|
+
|
423
|
+
mock.expect(:call, 1, [category.id])
|
424
|
+
Product.create!(categories: [category])
|
425
|
+
mock.verify
|
426
|
+
|
427
|
+
category.update!(name: "hockey")
|
428
|
+
|
429
|
+
mock.expect(:call, 2, [category.id])
|
430
|
+
Product.create!(categories: [category])
|
431
|
+
assert_raises(MockExpectationError) { mock.verify }
|
432
|
+
end
|
433
|
+
|
351
434
|
test "handles indirect associations" do
|
352
435
|
mock = Minitest::Mock.new
|
353
436
|
category = categories(:baseball)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thermos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Thal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|