Minor changes to docs, tests, for PR 614
This commit is contained in:
parent
de528439a3
commit
05e21cc106
|
@ -28,9 +28,8 @@ None
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added callback-methods `paper_trail_update` `paper_trail_create` `paper_trail_destroy`
|
- A way to control the order of AR callbacks.
|
||||||
instead of has_paper_trail
|
[#614](https://github.com/airblade/paper_trail/pull/614)
|
||||||
[#593](https://github.com/airblade/paper_trail/pull/607)
|
|
||||||
- Added `unversioned_attributes` option to `reify`.
|
- Added `unversioned_attributes` option to `reify`.
|
||||||
[#579](https://github.com/airblade/paper_trail/pull/579)
|
[#579](https://github.com/airblade/paper_trail/pull/579)
|
||||||
|
|
||||||
|
|
18
README.md
18
README.md
|
@ -332,24 +332,20 @@ a.versions.last.event # 'update'
|
||||||
|
|
||||||
### Controlling the Order of AR Callbacks
|
### Controlling the Order of AR Callbacks
|
||||||
|
|
||||||
You can also use the corresponding callback-methods seperately instead of using
|
The `has_paper_trail` method installs AR callbacks. If you need to control
|
||||||
the :on option. If you choose to use the callback-methods, PaperTrail will only
|
their order, use the `paper_trail_on_*` methods.
|
||||||
track the according events - so `paper_trail_on_create` is basically the same as
|
|
||||||
`has_paper_trail :on => :create`.
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Article < ActiveRecord::Base
|
class Article < ActiveRecord::Base
|
||||||
has_paper_trail :on => []
|
has_paper_trail :on => [] # don't install callbacks yet
|
||||||
paper_trail_on_destroy
|
paper_trail_on_destroy # install destroy
|
||||||
paper_trail_on_update
|
paper_trail_on_update # etc.
|
||||||
paper_trail_on_create
|
paper_trail_on_create
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
The `paper_trail_on_destroy` method can be configured to be called `:before` or `:after` the
|
The `paper_trail_on_destroy` method can be further configured to happen
|
||||||
destroy event. This can be usefull if you are using a third party tool that alters the
|
`:before` or `:after` the destroy event. By default, it will happen after.
|
||||||
destroy method (for example paranoia). If you do not pass an argument, it will default
|
|
||||||
to after_destroy.
|
|
||||||
|
|
||||||
## Choosing When To Save New Versions
|
## Choosing When To Save New Versions
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require 'support/callback_modifier'
|
|
||||||
|
|
||||||
describe CallbackModifier, :type => :model do
|
describe CallbackModifier, :type => :model do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
|
|
|
@ -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
|
|
|
@ -14,3 +14,32 @@ class CallbackModifier < ActiveRecord::Base
|
||||||
deleted?
|
deleted?
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
|
@ -282,7 +282,6 @@ class SetUpTestTables < ActiveRecord::Migration
|
||||||
remove_index :version_associations, :column => [:version_id]
|
remove_index :version_associations, :column => [:version_id]
|
||||||
remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
|
remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
|
||||||
drop_table :version_associations
|
drop_table :version_associations
|
||||||
drop_table :filter_modifier
|
|
||||||
drop_table :callback_modifiers
|
drop_table :callback_modifiers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue