mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Add :on option to has_paper_trail method
This commit is contained in:
parent
64e5fa2946
commit
7ed698ed0e
3 changed files with 11 additions and 5 deletions
|
@ -50,9 +50,9 @@ module PaperTrail
|
|||
:as => :item,
|
||||
:order => "created_at ASC, #{self.primary_key} ASC"
|
||||
|
||||
after_create :record_create
|
||||
before_update :record_update
|
||||
after_destroy :record_destroy
|
||||
after_create :record_create if !options[:on] || (options[:on] && options[:on].include?(:create))
|
||||
before_update :record_update if !options[:on] || (options[:on] && options[:on].include?(:update))
|
||||
after_destroy :record_destroy if !options[:on] || (options[:on] && options[:on].include?(:destroy))
|
||||
end
|
||||
|
||||
# Switches PaperTrail off for this class.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
class Document < ActiveRecord::Base
|
||||
has_paper_trail :versions => :paper_trail_versions
|
||||
has_paper_trail :versions => :paper_trail_versions,
|
||||
:on => [:create, :update]
|
||||
end
|
||||
|
|
|
@ -812,7 +812,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context 'A model with a custom association' do
|
||||
context 'A model with a custom association and "on" option' do
|
||||
setup do
|
||||
@doc = Document.create
|
||||
@doc.update_attributes :name => 'Doc 1'
|
||||
|
@ -831,6 +831,11 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
assert_equal 3, @doc.paper_trail_versions.length
|
||||
assert_equal 'Doc 1', @doc.previous_version.name
|
||||
end
|
||||
|
||||
should 'not create new version after destroy' do
|
||||
@doc.destroy
|
||||
assert_equal 2, @doc.paper_trail_versions.length
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue