thermos 0.0.5 → 0.0.6

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.
data/test/thermos_test.rb CHANGED
@@ -43,6 +43,7 @@ class ThermosTest < ActiveSupport::TestCase
43
43
  assert_raises(MockExpectationError) { mock.verify }
44
44
  end
45
45
 
46
+ # primary model changes
46
47
  test "rebuilds the cache on primary model change" do
47
48
  mock = Minitest::Mock.new
48
49
  category = categories(:baseball)
@@ -64,6 +65,45 @@ class ThermosTest < ActiveSupport::TestCase
64
65
  assert_raises(MockExpectationError) { mock.verify }
65
66
  end
66
67
 
68
+ test "does not rebuild the cache for an unrelated primary model change" do
69
+ mock = Minitest::Mock.new
70
+ category = categories(:baseball)
71
+ other_category = Category.create!(name: "bar")
72
+
73
+ Thermos.fill(key: "key", model: Category) do |id|
74
+ mock.call(id)
75
+ end
76
+
77
+ mock.expect(:call, 2, [other_category.id])
78
+ assert_equal 2, Thermos.drink(key: "key", id: other_category.id)
79
+ mock.verify
80
+
81
+ mock.expect(:call, 1, [category.id])
82
+ category.update!(name: "foo")
83
+ mock.verify
84
+
85
+ mock.expect(:call, 3, [other_category.id])
86
+ assert_equal 2, Thermos.drink(key: "key", id: other_category.id)
87
+ assert_raises(MockExpectationError) { mock.verify }
88
+ end
89
+
90
+ test "pre-builds cache for new primary model records" do
91
+ mock = Minitest::Mock.new
92
+
93
+ Thermos.fill(key: "key", model: Category, lookup_key: "name") do |name|
94
+ mock.call(name)
95
+ end
96
+
97
+ mock.expect(:call, 1, ["foo"])
98
+ Category.create!(name: "foo")
99
+ mock.verify
100
+
101
+ mock.expect(:call, 2, ["foo"])
102
+ assert_equal 1, Thermos.drink(key: "key", id: "foo")
103
+ assert_raises(MockExpectationError) { mock.verify }
104
+ end
105
+
106
+ # has_many model changes
67
107
  test "rebuilds the cache on has_many model change" do
68
108
  mock = Minitest::Mock.new
69
109
  category = categories(:baseball)
@@ -86,6 +126,46 @@ class ThermosTest < ActiveSupport::TestCase
86
126
  assert_raises(MockExpectationError) { mock.verify }
87
127
  end
88
128
 
129
+ test "does not rebuild the cache for an unrelated has_many model change" do
130
+ mock = Minitest::Mock.new
131
+ category = categories(:baseball)
132
+ category_item = CategoryItem.create(category: nil)
133
+
134
+ Thermos.fill(key: "key", model: Category, deps: [:category_items]) do |id|
135
+ mock.call(id)
136
+ end
137
+
138
+ mock.expect(:call, 1, [category.id])
139
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
140
+ mock.verify
141
+
142
+ mock.expect(:call, 2, [category.id])
143
+ category_item.update!(name: "foo")
144
+ assert_raises(MockExpectationError) { mock.verify }
145
+
146
+ mock.expect(:call, 3, [category.id])
147
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
148
+ assert_raises(MockExpectationError) { mock.verify }
149
+ end
150
+
151
+ test "re-builds the cache for new has_many records" do
152
+ mock = Minitest::Mock.new
153
+ category = categories(:baseball)
154
+
155
+ Thermos.fill(key: "key", model: Category, deps: [:category_items]) do |id|
156
+ mock.call(id)
157
+ end
158
+
159
+ mock.expect(:call, 1, [category.id])
160
+ CategoryItem.create!(category: category)
161
+ mock.verify
162
+
163
+ mock.expect(:call, 2, [category.id])
164
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
165
+ assert_raises(MockExpectationError) { mock.verify }
166
+ end
167
+
168
+ # belongs_to model changes
89
169
  test "rebuilds the cache on belongs_to model change" do
90
170
  mock = Minitest::Mock.new
91
171
  category = categories(:baseball)
@@ -108,6 +188,47 @@ class ThermosTest < ActiveSupport::TestCase
108
188
  assert_raises(MockExpectationError) { mock.verify }
109
189
  end
110
190
 
191
+ test "does not rebuild the cache for an unrelated belongs_to model change" do
192
+ mock = Minitest::Mock.new
193
+ category = categories(:baseball)
194
+ store = Store.create!
195
+
196
+ Thermos.fill(key: "key", model: Category, deps: [:store]) do |id|
197
+ mock.call(id)
198
+ end
199
+
200
+ mock.expect(:call, 1, [category.id])
201
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
202
+ mock.verify
203
+
204
+ mock.expect(:call, 2, [category.id])
205
+ store.update!(name: "foo")
206
+ assert_raises(MockExpectationError) { mock.verify }
207
+
208
+ mock.expect(:call, 3, [category.id])
209
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
210
+ assert_raises(MockExpectationError) { mock.verify }
211
+ end
212
+
213
+ test "re-builds the cache for new belongs_to records" do
214
+ mock = Minitest::Mock.new
215
+ category = categories(:baseball)
216
+
217
+ Thermos.fill(key: "key", model: Category, deps: [:store]) do |id|
218
+ mock.call(id)
219
+ end
220
+
221
+ mock.expect(:call, 1, [category.id])
222
+ mock.expect(:call, 1, [category.id])
223
+ Store.create!(name: "foo", categories: [category])
224
+ mock.verify
225
+
226
+ mock.expect(:call, 2, [category.id])
227
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
228
+ assert_raises(MockExpectationError) { mock.verify }
229
+ end
230
+
231
+ # has_many through model changes
111
232
  test "rebuilds the cache on has_many through model change" do
112
233
  mock = Minitest::Mock.new
113
234
  category = categories(:baseball)
@@ -130,6 +251,45 @@ class ThermosTest < ActiveSupport::TestCase
130
251
  assert_raises(MockExpectationError) { mock.verify }
131
252
  end
132
253
 
254
+ test "does not rebuild the cache for an unrelated has_many through model change" do
255
+ mock = Minitest::Mock.new
256
+ category = categories(:baseball)
257
+ product = Product.create!
258
+
259
+ Thermos.fill(key: "key", model: Category, deps: [:products]) do |id|
260
+ mock.call(id)
261
+ end
262
+
263
+ mock.expect(:call, 1, [category.id])
264
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
265
+ mock.verify
266
+
267
+ mock.expect(:call, 2, [category.id])
268
+ product.update!(name: "foo")
269
+ assert_raises(MockExpectationError) { mock.verify }
270
+
271
+ mock.expect(:call, 3, [category.id])
272
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
273
+ assert_raises(MockExpectationError) { mock.verify }
274
+ end
275
+
276
+ test "re-builds the cache for new has_many through records" do
277
+ mock = Minitest::Mock.new
278
+ category = categories(:baseball)
279
+
280
+ Thermos.fill(key: "key", model: Category, deps: [:products]) do |id|
281
+ mock.call(id)
282
+ end
283
+
284
+ mock.expect(:call, 1, [category.id])
285
+ Product.create!(categories: [category])
286
+ mock.verify
287
+
288
+ mock.expect(:call, 2, [category.id])
289
+ assert_equal 1, Thermos.drink(key: "key", id: category.id)
290
+ assert_raises(MockExpectationError) { mock.verify }
291
+ end
292
+
133
293
  test "only rebuilds cache for stated dependencies, even if another cache has an associated model of the primary" do
134
294
  category_mock = Minitest::Mock.new
135
295
  product_mock = Minitest::Mock.new
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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Thal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-28 00:00:00.000000000 Z
11
+ date: 2016-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails