Minor changes to docs, tests, for PR 614

This commit is contained in:
Jared Beck 2015-10-10 00:13:45 -04:00
parent de528439a3
commit 05e21cc106
6 changed files with 38 additions and 44 deletions

View File

@ -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)

View File

@ -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

View File

@ -1,5 +1,4 @@
require 'rails_helper'
require 'support/callback_modifier'
describe CallbackModifier, :type => :model do
with_versioning do

View File

@ -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

View File

@ -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

View File

@ -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