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 +5 -0
- data/README.md +3 -1
- data/lib/skip_activerecord_callbacks/model_helpers.rb +23 -0
- data/lib/skip_activerecord_callbacks/version.rb +1 -1
- data/test/dummy/log/test.log +340 -0
- data/test/skip_activerecord_callbacks_test.rb +27 -0
- data/test/test_helper.rb +1 -0
- metadata +28 -15
- data/lib/tasks/skip_activerecord_callbacks_tasks.rake +0 -4
data/CHANGELOG.md
CHANGED
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
|
|
data/test/dummy/log/test.log
CHANGED
@@ -184,3 +184,343 @@
|
|
184
184
|
[1m[35m (0.0ms)[0m begin transaction
|
185
185
|
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
186
186
|
[1m[35m (0.0ms)[0m commit transaction
|
187
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
188
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
189
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
190
|
+
[1m[35m (0.0ms)[0m begin transaction
|
191
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
192
|
+
[1m[35m (0.0ms)[0m commit transaction
|
193
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
194
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
|
195
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
196
|
+
[1m[35m (0.0ms)[0m begin transaction
|
197
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
198
|
+
[1m[35m (0.0ms)[0m commit transaction
|
199
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
200
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
201
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
202
|
+
[1m[35m (0.0ms)[0m begin transaction
|
203
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
204
|
+
[1m[35m (0.0ms)[0m commit transaction
|
205
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
206
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
207
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
208
|
+
[1m[35m (0.0ms)[0m begin transaction
|
209
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
210
|
+
[1m[35m (0.0ms)[0m commit transaction
|
211
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
212
|
+
[1m[35m (0.1ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
|
213
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
214
|
+
[1m[35m (0.0ms)[0m begin transaction
|
215
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
216
|
+
[1m[35m (0.0ms)[0m commit transaction
|
217
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
218
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
219
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
220
|
+
[1m[35m (0.0ms)[0m begin transaction
|
221
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
222
|
+
[1m[35m (0.0ms)[0m commit transaction
|
223
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
224
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
225
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
226
|
+
[1m[35m (0.0ms)[0m begin transaction
|
227
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
228
|
+
[1m[35m (0.0ms)[0m commit transaction
|
229
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
230
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
|
231
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
232
|
+
[1m[35m (0.0ms)[0m begin transaction
|
233
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
234
|
+
[1m[35m (0.0ms)[0m commit transaction
|
235
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
236
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
237
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
238
|
+
[1m[35m (0.0ms)[0m begin transaction
|
239
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
240
|
+
[1m[35m (0.0ms)[0m begin transaction
|
241
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
242
|
+
[1m[35m (0.0ms)[0m commit transaction
|
243
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
244
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
245
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
246
|
+
[1m[35m (0.0ms)[0m begin transaction
|
247
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
248
|
+
[1m[35m (0.0ms)[0m commit transaction
|
249
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
250
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
|
251
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
252
|
+
[1m[35m (0.0ms)[0m begin transaction
|
253
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
254
|
+
[1m[35m (0.0ms)[0m commit transaction
|
255
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
256
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
257
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
258
|
+
[1m[35m (0.0ms)[0m begin transaction
|
259
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
260
|
+
[1m[35m (0.0ms)[0m commit transaction
|
261
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
262
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
263
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
264
|
+
[1m[35m (0.0ms)[0m begin transaction
|
265
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 1[0m
|
266
|
+
[1m[35m (0.0ms)[0m commit transaction
|
267
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
268
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
269
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
270
|
+
[1m[35m (0.0ms)[0m begin transaction
|
271
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 2[0m
|
272
|
+
[1m[35m (0.0ms)[0m commit transaction
|
273
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
274
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
275
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
276
|
+
[1m[35m (0.0ms)[0m begin transaction
|
277
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
278
|
+
[1m[35m (0.0ms)[0m commit transaction
|
279
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
280
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
281
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
282
|
+
[1m[35m (0.0ms)[0m begin transaction
|
283
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
284
|
+
[1m[35m (0.0ms)[0m commit transaction
|
285
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
286
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2
|
287
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
288
|
+
[1m[35m (0.0ms)[0m begin transaction
|
289
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
290
|
+
[1m[35m (0.0ms)[0m commit transaction
|
291
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
292
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
293
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
294
|
+
[1m[35m (0.0ms)[0m begin transaction
|
295
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
296
|
+
[1m[35m (0.0ms)[0m begin transaction
|
297
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
298
|
+
[1m[35m (0.0ms)[0m commit transaction
|
299
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
300
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
301
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
302
|
+
[1m[35m (0.0ms)[0m begin transaction
|
303
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
304
|
+
[1m[35m (0.0ms)[0m commit transaction
|
305
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
306
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
307
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
308
|
+
[1m[35m (0.0ms)[0m begin transaction
|
309
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3[0m
|
310
|
+
[1m[35m (0.0ms)[0m commit transaction
|
311
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
312
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
313
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
314
|
+
[1m[35m (0.0ms)[0m begin transaction
|
315
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 4[0m
|
316
|
+
[1m[35m (0.0ms)[0m commit transaction
|
317
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
318
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
319
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
320
|
+
[1m[35m (0.0ms)[0m begin transaction
|
321
|
+
[1m[36mSQL (2.0ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 5]]
|
322
|
+
[1m[35m (0.0ms)[0m commit transaction
|
323
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
324
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
325
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
326
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
327
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
328
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
329
|
+
[1m[35m (0.0ms)[0m begin transaction
|
330
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
331
|
+
[1m[35m (0.0ms)[0m commit transaction
|
332
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
333
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
334
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
335
|
+
[1m[35m (0.0ms)[0m begin transaction
|
336
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3[0m
|
337
|
+
[1m[35m (0.0ms)[0m commit transaction
|
338
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
339
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
340
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
341
|
+
[1m[35m (0.0ms)[0m begin transaction
|
342
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4[0m
|
343
|
+
[1m[35m (0.0ms)[0m commit transaction
|
344
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
345
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
346
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
347
|
+
[1m[35m (0.0ms)[0m begin transaction
|
348
|
+
[1m[36mSQL (1.8ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 5]]
|
349
|
+
[1m[35m (0.0ms)[0m commit transaction
|
350
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
351
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
352
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
353
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
354
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
355
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
356
|
+
[1m[35m (0.0ms)[0m begin transaction
|
357
|
+
[1m[36mSQL (1.5ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
358
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
359
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
360
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
361
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
362
|
+
[1m[35m (0.0ms)[0m begin transaction
|
363
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
364
|
+
[1m[35m (0.0ms)[0m commit transaction
|
365
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
366
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 3
|
367
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
368
|
+
[1m[35m (0.0ms)[0m begin transaction
|
369
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
370
|
+
[1m[35m (0.0ms)[0m commit transaction
|
371
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
372
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 4
|
373
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
374
|
+
[1m[35m (0.0ms)[0m begin transaction
|
375
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
376
|
+
[1m[35m (0.0ms)[0m commit transaction
|
377
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
378
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
|
379
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
380
|
+
[1m[35m (0.0ms)[0m begin transaction
|
381
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
382
|
+
[1m[35m (0.0ms)[0m commit transaction
|
383
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
384
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
385
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
386
|
+
[1m[35m (0.0ms)[0m begin transaction
|
387
|
+
[1m[36mSQL (1.5ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
388
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
389
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
390
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
391
|
+
undefined local variable or method `action' for #<Product id: nil, name: "foo">
|
392
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
393
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
394
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
395
|
+
[1m[35m (0.0ms)[0m begin transaction
|
396
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
397
|
+
undefined local variable or method `action' for #<Product id: 2, name: "foo">
|
398
|
+
[1m[35m (0.0ms)[0m begin transaction
|
399
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
400
|
+
undefined local variable or method `action' for #<Product id: nil, name: "foo">
|
401
|
+
[1m[35m (0.0ms)[0m begin transaction
|
402
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
403
|
+
[1m[35m (0.0ms)[0m commit transaction
|
404
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
405
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 3]]
|
406
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
407
|
+
[1m[35m (0.0ms)[0m begin transaction
|
408
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
409
|
+
[1m[35m (0.0ms)[0m commit transaction
|
410
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
411
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
412
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
413
|
+
[1m[35m (0.0ms)[0m begin transaction
|
414
|
+
[1m[36mSQL (1.7ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
415
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
416
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
417
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
418
|
+
undefined local variable or method `action' for #<Product id: nil, name: "foo">
|
419
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
420
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
421
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
422
|
+
[1m[35m (0.0ms)[0m begin transaction
|
423
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
424
|
+
undefined local variable or method `action' for #<Product id: 2, name: "foo">
|
425
|
+
[1m[35m (0.0ms)[0m begin transaction
|
426
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
427
|
+
undefined local variable or method `action' for #<Product id: nil, name: "foo">
|
428
|
+
[1m[35m (0.0ms)[0m begin transaction
|
429
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
430
|
+
[1m[35m (0.0ms)[0m commit transaction
|
431
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
432
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 3]]
|
433
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
434
|
+
[1m[35m (0.0ms)[0m begin transaction
|
435
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
436
|
+
[1m[35m (0.0ms)[0m commit transaction
|
437
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
438
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
439
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
440
|
+
[1m[35m (0.0ms)[0m begin transaction
|
441
|
+
[1m[36mSQL (2.0ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
442
|
+
[1m[35m (0.0ms)[0m commit transaction
|
443
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
444
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
445
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
446
|
+
[1m[35m (0.0ms)[0m begin transaction
|
447
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
448
|
+
[1m[35m (0.0ms)[0m commit transaction
|
449
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
450
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3
|
451
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
452
|
+
[1m[35m (0.0ms)[0m begin transaction
|
453
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
454
|
+
[1m[35m (0.0ms)[0m commit transaction
|
455
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
456
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
|
457
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
458
|
+
[1m[35m (0.0ms)[0m begin transaction
|
459
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
460
|
+
[1m[35m (0.0ms)[0m commit transaction
|
461
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
462
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
|
463
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
464
|
+
[1m[35m (0.0ms)[0m begin transaction
|
465
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
466
|
+
[1m[35m (0.0ms)[0m commit transaction
|
467
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
468
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
469
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
470
|
+
[1m[35m (0.0ms)[0m begin transaction
|
471
|
+
[1m[36mSQL (1.9ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
472
|
+
[1m[35m (0.0ms)[0m commit transaction
|
473
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
474
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
475
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
476
|
+
[1m[35m (0.0ms)[0m begin transaction
|
477
|
+
[1m[36m (0.0ms)[0m [1mUPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 2[0m
|
478
|
+
[1m[35m (0.0ms)[0m commit transaction
|
479
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
480
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
481
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
482
|
+
[1m[35m (0.0ms)[0m begin transaction
|
483
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
484
|
+
[1m[35m (0.0ms)[0m commit transaction
|
485
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
486
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
|
487
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
488
|
+
[1m[35m (0.0ms)[0m begin transaction
|
489
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
490
|
+
[1m[35m (0.0ms)[0m commit transaction
|
491
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
492
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
|
493
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
494
|
+
[1m[35m (0.0ms)[0m begin transaction
|
495
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
496
|
+
[1m[35m (0.0ms)[0m commit transaction
|
497
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
498
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "bar"]]
|
499
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
500
|
+
[1m[35m (0.0ms)[0m begin transaction
|
501
|
+
[1m[36mSQL (1.5ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = ?[0m [["id", 1]]
|
502
|
+
[1m[35m (0.0ms)[0m commit transaction
|
503
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
504
|
+
[1m[35mSQL (0.0ms)[0m INSERT INTO "products" ("name") VALUES (?) [["name", "foo"]]
|
505
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
506
|
+
[1m[35m (0.0ms)[0m begin transaction
|
507
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
508
|
+
[1m[35m (0.0ms)[0m commit transaction
|
509
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
510
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'foo' WHERE "products"."id" = 3
|
511
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
512
|
+
[1m[35m (0.0ms)[0m begin transaction
|
513
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "foo"]]
|
514
|
+
[1m[35m (0.0ms)[0m commit transaction
|
515
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
516
|
+
[1m[35m (0.0ms)[0m UPDATE "products" SET "name" = 'bar' WHERE "products"."id" = 4
|
517
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
518
|
+
[1m[35m (0.0ms)[0m begin transaction
|
519
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
520
|
+
[1m[35m (0.0ms)[0m commit transaction
|
521
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
522
|
+
[1m[35mSQL (0.0ms)[0m DELETE FROM "products" WHERE "products"."id" = ? [["id", 5]]
|
523
|
+
[1m[36m (0.0ms)[0m [1mcommit transaction[0m
|
524
|
+
[1m[35m (0.0ms)[0m begin transaction
|
525
|
+
[1m[36mSQL (0.0ms)[0m [1mINSERT INTO "products" ("name") VALUES (?)[0m [["name", "bar"]]
|
526
|
+
[1m[35m (0.0ms)[0m 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
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
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-
|
18
|
+
date: 2012-04-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
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
|
-
|
33
|
-
prerelease: false
|
34
|
-
requirement: *id001
|
34
|
+
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
|
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:
|
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:
|
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.
|
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
|