From 05e21cc106b8a5c523909c37a8423c3a0d74e068 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sat, 10 Oct 2015 00:13:45 -0400 Subject: [PATCH] Minor changes to docs, tests, for PR 614 --- CHANGELOG.md | 5 ++-- README.md | 18 +++++------- spec/models/callback_modifier_spec.rb | 1 - spec/support/callback_modifier.rb | 28 ------------------ test/dummy/app/models/callback_modifier.rb | 29 +++++++++++++++++++ .../20110208155312_set_up_test_tables.rb | 1 - 6 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 spec/support/callback_modifier.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6bc49b..562cf712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,9 +28,8 @@ None ### Added -- Added callback-methods `paper_trail_update` `paper_trail_create` `paper_trail_destroy` - instead of has_paper_trail - [#593](https://github.com/airblade/paper_trail/pull/607) +- A way to control the order of AR callbacks. + [#614](https://github.com/airblade/paper_trail/pull/614) - Added `unversioned_attributes` option to `reify`. [#579](https://github.com/airblade/paper_trail/pull/579) diff --git a/README.md b/README.md index 6f9f8aa5..502d4322 100644 --- a/README.md +++ b/README.md @@ -332,24 +332,20 @@ a.versions.last.event # 'update' ### Controlling the Order of AR Callbacks -You can also use the corresponding callback-methods seperately instead of using -the :on option. If you choose to use the callback-methods, PaperTrail will only -track the according events - so `paper_trail_on_create` is basically the same as -`has_paper_trail :on => :create`. +The `has_paper_trail` method installs AR callbacks. If you need to control +their order, use the `paper_trail_on_*` methods. ```ruby class Article < ActiveRecord::Base - has_paper_trail :on => [] - paper_trail_on_destroy - paper_trail_on_update + has_paper_trail :on => [] # don't install callbacks yet + paper_trail_on_destroy # install destroy + paper_trail_on_update # etc. paper_trail_on_create end ``` -The `paper_trail_on_destroy` method can be configured to be called `:before` or `:after` the -destroy event. This can be usefull if you are using a third party tool that alters the -destroy method (for example paranoia). If you do not pass an argument, it will default -to after_destroy. +The `paper_trail_on_destroy` method can be further configured to happen +`:before` or `:after` the destroy event. By default, it will happen after. ## Choosing When To Save New Versions diff --git a/spec/models/callback_modifier_spec.rb b/spec/models/callback_modifier_spec.rb index 13b8c421..55d9c5f4 100644 --- a/spec/models/callback_modifier_spec.rb +++ b/spec/models/callback_modifier_spec.rb @@ -1,5 +1,4 @@ require 'rails_helper' -require 'support/callback_modifier' describe CallbackModifier, :type => :model do with_versioning do diff --git a/spec/support/callback_modifier.rb b/spec/support/callback_modifier.rb deleted file mode 100644 index 51368291..00000000 --- a/spec/support/callback_modifier.rb +++ /dev/null @@ -1,28 +0,0 @@ -class BeforeDestroyModifier < CallbackModifier - has_paper_trail :on => [] - paper_trail_on_destroy :before -end - -class AfterDestroyModifier < CallbackModifier - has_paper_trail :on => [] - paper_trail_on_destroy :after -end - -class NoArgDestroyModifier < CallbackModifier - has_paper_trail :on => [] - paper_trail_on_destroy -end - -class UpdateModifier < CallbackModifier - has_paper_trail :on => [] - paper_trail_on_update -end - -class CreateModifier < CallbackModifier - has_paper_trail :on => [] - paper_trail_on_create -end - -class DefaultModifier < CallbackModifier - has_paper_trail -end diff --git a/test/dummy/app/models/callback_modifier.rb b/test/dummy/app/models/callback_modifier.rb index 0233899c..e584f5cf 100644 --- a/test/dummy/app/models/callback_modifier.rb +++ b/test/dummy/app/models/callback_modifier.rb @@ -14,3 +14,32 @@ class CallbackModifier < ActiveRecord::Base deleted? end end + +class BeforeDestroyModifier < CallbackModifier + has_paper_trail :on => [] + paper_trail_on_destroy :before +end + +class AfterDestroyModifier < CallbackModifier + has_paper_trail :on => [] + paper_trail_on_destroy :after +end + +class NoArgDestroyModifier < CallbackModifier + has_paper_trail :on => [] + paper_trail_on_destroy +end + +class UpdateModifier < CallbackModifier + has_paper_trail :on => [] + paper_trail_on_update +end + +class CreateModifier < CallbackModifier + has_paper_trail :on => [] + paper_trail_on_create +end + +class DefaultModifier < CallbackModifier + has_paper_trail +end diff --git a/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb b/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb index a71b4051..f0199dc2 100644 --- a/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +++ b/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb @@ -282,7 +282,6 @@ class SetUpTestTables < ActiveRecord::Migration remove_index :version_associations, :column => [:version_id] remove_index :version_associations, :name => 'index_version_associations_on_foreign_key' drop_table :version_associations - drop_table :filter_modifier drop_table :callback_modifiers end end