tantot 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tantot/observe.rb +4 -3
- data/lib/tantot/version.rb +1 -1
- data/spec/tantot_spec.rb +78 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f6ad6fe3fb7afb2054c68fe8625cc99ea85c327
|
4
|
+
data.tar.gz: 2196c42e206c184669e3429323b4d77774db068e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757def8ab9f5e5fa8846b95a6aec91d7f12c2181c51c01680e4fb683cfe61debfe5f71f45e0560da93f43a88c87e2d01d24b1e0c5c338bda469628287bdbe97a
|
7
|
+
data.tar.gz: 9c0c6e845e61607d91e0513d6ce8cf6226b577b416e3aee6fdba89e3be4cde58c7bb1c52a4186313d85623f6db07a96df4716a8c81f619bcf72908a4a44b6fe9
|
data/lib/tantot/observe.rb
CHANGED
@@ -69,9 +69,10 @@ module Tantot
|
|
69
69
|
|
70
70
|
Tantot.collector.register_watch(context, block)
|
71
71
|
|
72
|
-
callback_options = {
|
73
|
-
if
|
74
|
-
|
72
|
+
callback_options = {}.tap do |opts|
|
73
|
+
opts[:if] = Observe.condition_proc(context) if context[:attributes].any? || options.key?(:if)
|
74
|
+
opts[:on] = options[:on] if options.key?(:on)
|
75
|
+
end
|
75
76
|
update_proc = Observe.update_proc(context)
|
76
77
|
|
77
78
|
if Tantot.config.use_after_commit_callbacks
|
data/lib/tantot/version.rb
CHANGED
data/spec/tantot_spec.rb
CHANGED
@@ -295,5 +295,83 @@ describe Tantot do
|
|
295
295
|
expect(changes[:obj]).to eq(Tantot::Changes::ById.new({1=>{"id"=>[nil, 1]}, 2=>{"id"=>[nil, 2]}, 3=>{"id"=>[nil, 3]}}))
|
296
296
|
end
|
297
297
|
end
|
298
|
+
|
299
|
+
context 'on:' do
|
300
|
+
|
301
|
+
context ':create' do
|
302
|
+
before do
|
303
|
+
stub_model(:city) do
|
304
|
+
watch TestWatcher, on: :create
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should only watch creation" do
|
309
|
+
city = nil
|
310
|
+
Tantot.collector.run do
|
311
|
+
city = City.create!
|
312
|
+
expect(watcher_instance).to receive(:perform).once.with(Tantot::Changes::ByModel.new({City => {city.id => {"id" => [nil, city.id]}}}))
|
313
|
+
end
|
314
|
+
Tantot.collector.run do
|
315
|
+
city = City.find(city)
|
316
|
+
city.name = 'foo'
|
317
|
+
city.save
|
318
|
+
end
|
319
|
+
Tantot.collector.run do
|
320
|
+
city = City.find(city)
|
321
|
+
city.destroy
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context ':update' do
|
327
|
+
before do
|
328
|
+
stub_model(:city) do
|
329
|
+
watch TestWatcher, on: :update
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should only watch update" do
|
334
|
+
city = nil
|
335
|
+
Tantot.collector.run do
|
336
|
+
city = City.create!
|
337
|
+
expect(watcher_instance).to receive(:perform).once.with(Tantot::Changes::ByModel.new({City => {city.id => {"name" => [nil, 'foo']}}}))
|
338
|
+
end
|
339
|
+
Tantot.collector.run do
|
340
|
+
city = City.find(city)
|
341
|
+
city.name = 'foo'
|
342
|
+
city.save
|
343
|
+
end
|
344
|
+
Tantot.collector.run do
|
345
|
+
city = City.find(city)
|
346
|
+
city.destroy
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context ':destroy' do
|
352
|
+
before do
|
353
|
+
stub_model(:city) do
|
354
|
+
watch TestWatcher, on: :destroy
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should only watch destruction" do
|
359
|
+
city = nil
|
360
|
+
Tantot.collector.run do
|
361
|
+
city = City.create!
|
362
|
+
expect(watcher_instance).to receive(:perform).once.with(Tantot::Changes::ByModel.new({City => {city.id => {}}}))
|
363
|
+
end
|
364
|
+
Tantot.collector.run do
|
365
|
+
city = City.find(city)
|
366
|
+
city.name = 'foo'
|
367
|
+
city.save
|
368
|
+
end
|
369
|
+
Tantot.collector.run do
|
370
|
+
city = City.find(city)
|
371
|
+
city.destroy
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
298
376
|
end # describe '.watch'
|
299
377
|
end
|