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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8034dc47aeea3eeca0970dae7bec53a8e99de285
4
- data.tar.gz: 26a50c7cd327edfdebc0706edf1cb6a861b76411
3
+ metadata.gz: 7f6ad6fe3fb7afb2054c68fe8625cc99ea85c327
4
+ data.tar.gz: 2196c42e206c184669e3429323b4d77774db068e
5
5
  SHA512:
6
- metadata.gz: d439b688a52f03174b5f18020e226522518069da36e9b96b41953aec8266f8f81c533ae6299f5b4c496ffc9830512c7c62bb86b26075fe110627b135bfcd7119
7
- data.tar.gz: a1a4189f19fdc39e248c40e3b4d60dc734dd4340082caeeb72289281df287aca115e84460714fce002ce49dea3195ff7c312caa5439693e5efb2663614a74bda
6
+ metadata.gz: 757def8ab9f5e5fa8846b95a6aec91d7f12c2181c51c01680e4fb683cfe61debfe5f71f45e0560da93f43a88c87e2d01d24b1e0c5c338bda469628287bdbe97a
7
+ data.tar.gz: 9c0c6e845e61607d91e0513d6ce8cf6226b577b416e3aee6fdba89e3be4cde58c7bb1c52a4186313d85623f6db07a96df4716a8c81f619bcf72908a4a44b6fe9
@@ -69,9 +69,10 @@ module Tantot
69
69
 
70
70
  Tantot.collector.register_watch(context, block)
71
71
 
72
- callback_options = {
73
- if: Observe.condition_proc(context)
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
@@ -1,3 +1,3 @@
1
1
  module Tantot
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tantot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - François-Pierre Bouchard