skip_activerecord_callbacks 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ v0.1.1
2
+
3
+ * Adds destroy_without_callbacks
4
+ * Removes Gemfile.lock
5
+
1
6
  v0.1.0
2
7
 
3
8
  * Initial release
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Skip ActiveRecord Callbacks
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/dball/skip_activerecord_callbacks.png)](http://travis-ci.org/dball/skip_activerecord_callbacks)
4
+
3
5
  Do you miss update_without_callbacks from Rails 2? You shouldn't,
4
6
  because ActiveRecord callbacks are not a particularly good way to
5
7
  implement system behavior. If you have to skip them routinely in the
@@ -24,7 +26,7 @@ model.
24
26
 
25
27
  ## Seriously?
26
28
 
27
- Yeah. But it seems to work just fine. The undecoration is the first
29
+ Yeah, I know. But it seems to work just fine. The undecoration is the first
28
30
  thing that happens when running the `:save` callbacks, so it would seem
29
31
  the only way this could not work is if ActiveRecord failed to call the
30
32
  `run_callbacks` method on save, or if ActiveSupport needed to call the
@@ -4,8 +4,14 @@ module SkipActiveRecordCallbacks
4
4
  ModelDecorator.override_run_callbacks_to_skip_save_once(self)
5
5
  save
6
6
  end
7
+
8
+ def destroy_without_callbacks
9
+ ModelDecorator.override_run_callbacks_to_skip_destroy_once(self)
10
+ destroy
11
+ end
7
12
  end
8
13
 
14
+ # TODO: The cut and paste is sad
9
15
  class ModelDecorator
10
16
  def self.override_run_callbacks_to_skip_save_once(model)
11
17
  class << model
@@ -23,6 +29,23 @@ module SkipActiveRecordCallbacks
23
29
  end
24
30
  end
25
31
  end
32
+
33
+ def self.override_run_callbacks_to_skip_destroy_once(model)
34
+ class << model
35
+ alias :run_callbacks_orig :run_callbacks
36
+ def run_callbacks(name, &block)
37
+ if name == :destroy
38
+ class << self
39
+ undef :run_callbacks
40
+ alias :run_callbacks :run_callbacks_orig
41
+ end
42
+ yield
43
+ else
44
+ run_callbacks_orig(name, &block)
45
+ end
46
+ end
47
+ end
48
+ end
26
49
  end
27
50
  end
28
51
 
@@ -1,3 +1,3 @@
1
1
  module SkipActiverecordCallbacks
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -184,3 +184,343 @@
184
184
   (0.0ms) begin transaction
185
185
  SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
186
186
   (0.0ms) commit transaction
187
+  (0.0ms) begin transaction
188
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
189
+  (0.0ms) commit transaction
190
+  (0.0ms) begin transaction
191
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
192
+  (0.0ms) commit transaction
193
+  (0.0ms) begin transaction
194
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
195
+  (0.0ms) commit transaction
196
+  (0.0ms) begin transaction
197
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
198
+  (0.0ms) commit transaction
199
+  (0.0ms) begin transaction
200
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
201
+  (0.0ms) commit transaction
202
+  (0.0ms) begin transaction
203
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
204
+  (0.0ms) commit transaction
205
+  (0.0ms) begin transaction
206
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
207
+  (0.0ms) commit transaction
208
+  (0.0ms) begin transaction
209
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
210
+  (0.0ms) commit transaction
211
+  (0.0ms) begin transaction
212
+  (0.1ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
213
+  (0.0ms) commit transaction
214
+  (0.0ms) begin transaction
215
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
216
+  (0.0ms) commit transaction
217
+  (0.0ms) begin transaction
218
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
219
+  (0.0ms) commit transaction
220
+  (0.0ms) begin transaction
221
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
222
+  (0.0ms) commit transaction
223
+  (0.0ms) begin transaction
224
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
225
+  (0.0ms) commit transaction
226
+  (0.0ms) begin transaction
227
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
228
+  (0.0ms) commit transaction
229
+  (0.0ms) begin transaction
230
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
231
+  (0.0ms) commit transaction
232
+  (0.0ms) begin transaction
233
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
234
+  (0.0ms) commit transaction
235
+  (0.0ms) begin transaction
236
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
237
+  (0.0ms) commit transaction
238
+  (0.0ms) begin transaction
239
+  (0.0ms) commit transaction
240
+  (0.0ms) begin transaction
241
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
242
+  (0.0ms) commit transaction
243
+  (0.0ms) begin transaction
244
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
245
+  (0.0ms) commit transaction
246
+  (0.0ms) begin transaction
247
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
248
+  (0.0ms) commit transaction
249
+  (0.0ms) begin transaction
250
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
251
+  (0.0ms) commit transaction
252
+  (0.0ms) begin transaction
253
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
254
+  (0.0ms) commit transaction
255
+  (0.0ms) begin transaction
256
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
257
+  (0.0ms) commit transaction
258
+  (0.0ms) begin transaction
259
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
260
+  (0.0ms) commit transaction
261
+  (0.0ms) begin transaction
262
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
263
+  (0.0ms) commit transaction
264
+  (0.0ms) begin transaction
265
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 1
266
+  (0.0ms) commit transaction
267
+  (0.0ms) begin transaction
268
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
269
+  (0.0ms) commit transaction
270
+  (0.0ms) begin transaction
271
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 2
272
+  (0.0ms) commit transaction
273
+  (0.0ms) begin transaction
274
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
275
+  (0.0ms) commit transaction
276
+  (0.0ms) begin transaction
277
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
278
+  (0.0ms) commit transaction
279
+  (0.0ms) begin transaction
280
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
281
+  (0.0ms) commit transaction
282
+  (0.0ms) begin transaction
283
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
284
+  (0.0ms) commit transaction
285
+  (0.0ms) begin transaction
286
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
287
+  (0.0ms) commit transaction
288
+  (0.0ms) begin transaction
289
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
290
+  (0.0ms) commit transaction
291
+  (0.0ms) begin transaction
292
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
293
+  (0.0ms) commit transaction
294
+  (0.0ms) begin transaction
295
+  (0.0ms) commit transaction
296
+  (0.0ms) begin transaction
297
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
298
+  (0.0ms) commit transaction
299
+  (0.0ms) begin transaction
300
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
301
+  (0.0ms) commit transaction
302
+  (0.0ms) begin transaction
303
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
304
+  (0.0ms) commit transaction
305
+  (0.0ms) begin transaction
306
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
307
+  (0.0ms) commit transaction
308
+  (0.0ms) begin transaction
309
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
310
+  (0.0ms) commit transaction
311
+  (0.0ms) begin transaction
312
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
313
+  (0.0ms) commit transaction
314
+  (0.0ms) begin transaction
315
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 4
316
+  (0.0ms) commit transaction
317
+  (0.0ms) begin transaction
318
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
319
+  (0.0ms) commit transaction
320
+  (0.0ms) begin transaction
321
+ SQL (2.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
322
+  (0.0ms) commit transaction
323
+  (0.0ms) begin transaction
324
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
325
+  (0.0ms) commit transaction
326
+  (0.0ms) begin transaction
327
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
328
+  (0.0ms) commit transaction
329
+  (0.0ms) begin transaction
330
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
331
+  (0.0ms) commit transaction
332
+  (0.0ms) begin transaction
333
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
334
+  (0.0ms) commit transaction
335
+  (0.0ms) begin transaction
336
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3
337
+  (0.0ms) commit transaction
338
+  (0.0ms) begin transaction
339
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
340
+  (0.0ms) commit transaction
341
+  (0.0ms) begin transaction
342
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
343
+  (0.0ms) commit transaction
344
+  (0.0ms) begin transaction
345
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
346
+  (0.0ms) commit transaction
347
+  (0.0ms) begin transaction
348
+ SQL (1.8ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
349
+  (0.0ms) commit transaction
350
+  (0.0ms) begin transaction
351
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
352
+  (0.0ms) commit transaction
353
+  (0.0ms) begin transaction
354
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
355
+  (0.0ms) commit transaction
356
+  (0.0ms) begin transaction
357
+ SQL (1.5ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
358
+  (0.0ms) rollback transaction
359
+  (0.0ms) begin transaction
360
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
361
+  (0.0ms) commit transaction
362
+  (0.0ms) begin transaction
363
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
364
+  (0.0ms) commit transaction
365
+  (0.0ms) begin transaction
366
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
367
+  (0.0ms) commit transaction
368
+  (0.0ms) begin transaction
369
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
370
+  (0.0ms) commit transaction
371
+  (0.0ms) begin transaction
372
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 4
373
+  (0.0ms) commit transaction
374
+  (0.0ms) begin transaction
375
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
376
+  (0.0ms) commit transaction
377
+  (0.0ms) begin transaction
378
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
379
+  (0.0ms) commit transaction
380
+  (0.0ms) begin transaction
381
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
382
+  (0.0ms) commit transaction
383
+  (0.0ms) begin transaction
384
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
385
+  (0.0ms) commit transaction
386
+  (0.0ms) begin transaction
387
+ SQL (1.5ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
388
+  (0.0ms) rollback transaction
389
+  (0.0ms) begin transaction
390
+  (0.0ms) rollback transaction
391
+ undefined local variable or method `action' for #<Product id: nil, name: "foo">
392
+  (0.0ms) begin transaction
393
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
394
+  (0.0ms) commit transaction
395
+  (0.0ms) begin transaction
396
+  (0.0ms) rollback transaction
397
+ undefined local variable or method `action' for #<Product id: 2, name: "foo">
398
+  (0.0ms) begin transaction
399
+  (0.0ms) rollback transaction
400
+ undefined local variable or method `action' for #<Product id: nil, name: "foo">
401
+  (0.0ms) begin transaction
402
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
403
+  (0.0ms) commit transaction
404
+  (0.0ms) begin transaction
405
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 3]]
406
+  (0.0ms) commit transaction
407
+  (0.0ms) begin transaction
408
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
409
+  (0.0ms) commit transaction
410
+  (0.0ms) begin transaction
411
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
412
+  (0.0ms) commit transaction
413
+  (0.0ms) begin transaction
414
+ SQL (1.7ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
415
+  (0.0ms) rollback transaction
416
+  (0.0ms) begin transaction
417
+  (0.0ms) rollback transaction
418
+ undefined local variable or method `action' for #<Product id: nil, name: "foo">
419
+  (0.0ms) begin transaction
420
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
421
+  (0.0ms) commit transaction
422
+  (0.0ms) begin transaction
423
+  (0.0ms) rollback transaction
424
+ undefined local variable or method `action' for #<Product id: 2, name: "foo">
425
+  (0.0ms) begin transaction
426
+  (0.0ms) rollback transaction
427
+ undefined local variable or method `action' for #<Product id: nil, name: "foo">
428
+  (0.0ms) begin transaction
429
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
430
+  (0.0ms) commit transaction
431
+  (0.0ms) begin transaction
432
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 3]]
433
+  (0.0ms) commit transaction
434
+  (0.0ms) begin transaction
435
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
436
+  (0.0ms) commit transaction
437
+  (0.0ms) begin transaction
438
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
439
+  (0.0ms) commit transaction
440
+  (0.0ms) begin transaction
441
+ SQL (2.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
442
+  (0.0ms) commit transaction
443
+  (0.0ms) begin transaction
444
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
445
+  (0.0ms) commit transaction
446
+  (0.0ms) begin transaction
447
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
448
+  (0.0ms) commit transaction
449
+  (0.0ms) begin transaction
450
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3
451
+  (0.0ms) commit transaction
452
+  (0.0ms) begin transaction
453
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
454
+  (0.0ms) commit transaction
455
+  (0.0ms) begin transaction
456
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
457
+  (0.0ms) commit transaction
458
+  (0.0ms) begin transaction
459
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
460
+  (0.0ms) commit transaction
461
+  (0.0ms) begin transaction
462
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
463
+  (0.0ms) commit transaction
464
+  (0.0ms) begin transaction
465
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
466
+  (0.0ms) commit transaction
467
+  (0.0ms) begin transaction
468
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
469
+  (0.0ms) commit transaction
470
+  (0.0ms) begin transaction
471
+ SQL (1.9ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
472
+  (0.0ms) commit transaction
473
+  (0.0ms) begin transaction
474
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
475
+  (0.0ms) commit transaction
476
+  (0.0ms) begin transaction
477
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
478
+  (0.0ms) commit transaction
479
+  (0.0ms) begin transaction
480
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
481
+  (0.0ms) commit transaction
482
+  (0.0ms) begin transaction
483
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
484
+  (0.0ms) commit transaction
485
+  (0.0ms) begin transaction
486
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
487
+  (0.0ms) commit transaction
488
+  (0.0ms) begin transaction
489
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
490
+  (0.0ms) commit transaction
491
+  (0.0ms) begin transaction
492
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
493
+  (0.0ms) commit transaction
494
+  (0.0ms) begin transaction
495
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
496
+  (0.0ms) commit transaction
497
+  (0.0ms) begin transaction
498
+ SQL (0.1ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
499
+  (0.0ms) commit transaction
500
+  (0.0ms) begin transaction
501
+ SQL (1.5ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
502
+  (0.0ms) commit transaction
503
+  (0.0ms) begin transaction
504
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
505
+  (0.0ms) commit transaction
506
+  (0.0ms) begin transaction
507
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
508
+  (0.0ms) commit transaction
509
+  (0.0ms) begin transaction
510
+  (0.0ms) UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3
511
+  (0.0ms) commit transaction
512
+  (0.0ms) begin transaction
513
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
514
+  (0.0ms) commit transaction
515
+  (0.0ms) begin transaction
516
+  (0.0ms) UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
517
+  (0.0ms) commit transaction
518
+  (0.0ms) begin transaction
519
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
520
+  (0.0ms) commit transaction
521
+  (0.0ms) begin transaction
522
+ SQL (0.0ms) DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
523
+  (0.0ms) commit transaction
524
+  (0.0ms) begin transaction
525
+ SQL (0.0ms) INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
526
+  (0.0ms) commit transaction
@@ -1,5 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
+ class DestructionNotifier
4
+ def self.product_was_destroyed(product)
5
+ end
6
+ end
7
+
3
8
  class Product < ActiveRecord::Base
4
9
  attr_accessible :name
5
10
 
@@ -10,6 +15,10 @@ class Product < ActiveRecord::Base
10
15
  after_save do |product|
11
16
  product.name = product.name.titleize
12
17
  end
18
+
19
+ after_destroy do |product|
20
+ DestructionNotifier.product_was_destroyed(product)
21
+ end
13
22
  end
14
23
 
15
24
  describe SkipActiverecordCallbacks do
@@ -44,4 +53,22 @@ describe SkipActiverecordCallbacks do
44
53
  product.name.must_equal 'Bar'
45
54
  end
46
55
  end
56
+
57
+ describe "normal destroy" do
58
+ it "destroys the model and runs the callbacks" do
59
+ product.save
60
+ DestructionNotifier.expects(:product_was_destroyed).with(product)
61
+ product.destroy
62
+ assert product.destroyed?
63
+ end
64
+ end
65
+
66
+ describe "#destroy_without_callbacks" do
67
+ it "destroys a record without running the callbacks" do
68
+ product.save
69
+ DestructionNotifier.expects(:product_was_destroyed).never
70
+ product.destroy_without_callbacks
71
+ assert product.destroyed?
72
+ end
73
+ end
47
74
  end
data/test/test_helper.rb CHANGED
@@ -4,6 +4,7 @@ ENV["RAILS_ENV"] = "test"
4
4
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
5
  require "rails/test_help"
6
6
  require 'minitest/autorun'
7
+ require 'mocha/integration/mini_test'
7
8
 
8
9
  Rails.backtrace_cleaner.remove_silencers!
9
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skip_activerecord_callbacks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Donald Ball
@@ -15,10 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-13 00:00:00 Z
18
+ date: 2012-04-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ type: :runtime
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
22
24
  none: false
23
25
  requirements:
24
26
  - - ~>
@@ -29,11 +31,11 @@ dependencies:
29
31
  - 2
30
32
  version: "3.2"
31
33
  name: rails
32
- type: :runtime
33
- prerelease: false
34
- requirement: *id001
34
+ version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ type: :development
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
37
39
  none: false
38
40
  requirements:
39
41
  - - ">="
@@ -43,11 +45,11 @@ dependencies:
43
45
  - 0
44
46
  version: "0"
45
47
  name: sqlite3
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
46
50
  type: :development
47
51
  prerelease: false
48
- requirement: *id002
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
51
53
  none: false
52
54
  requirements:
53
55
  - - ">="
@@ -57,9 +59,21 @@ dependencies:
57
59
  - 0
58
60
  version: "0"
59
61
  name: minitest
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
60
64
  type: :development
61
65
  prerelease: false
62
- requirement: *id003
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ name: mocha
76
+ version_requirements: *id004
63
77
  description: Provides support for the deprecated update_without_callbacks method from rails 2
64
78
  email:
65
79
  - donald.ball@gmail.com
@@ -74,7 +88,6 @@ files:
74
88
  - lib/skip_activerecord_callbacks/railtie.rb
75
89
  - lib/skip_activerecord_callbacks/version.rb
76
90
  - lib/skip_activerecord_callbacks.rb
77
- - lib/tasks/skip_activerecord_callbacks_tasks.rake
78
91
  - MIT-LICENSE
79
92
  - Rakefile
80
93
  - README.md
@@ -140,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
153
  requirements: []
141
154
 
142
155
  rubyforge_project:
143
- rubygems_version: 1.8.21
156
+ rubygems_version: 1.8.17
144
157
  signing_key:
145
158
  specification_version: 3
146
159
  summary: Lets you save activerecord models without callbacks
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :skip_activerecord_callbacks do
3
- # # Task goes here
4
- # end