mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Handle :on => [] correctly.
This commit is contained in:
parent
6b039a2607
commit
81d266f23a
2 changed files with 20 additions and 4 deletions
|
@ -70,14 +70,14 @@ module PaperTrail
|
|||
:order => self.paper_trail_version_class.timestamp_sort_order
|
||||
end
|
||||
|
||||
options_on = Array(options[:on]) # so that a single symbol can be passed in without wrapping it in an `Array`
|
||||
after_create :record_create, :if => :save_version? if options_on.empty? || options_on.include?(:create)
|
||||
if options_on.empty? || options_on.include?(:update)
|
||||
options_on = Array(options[:on]) unless options[:on].nil? # so that a single symbol can be passed in without wrapping it in an `Array`
|
||||
after_create :record_create, :if => :save_version? if options_on.nil? || options_on.include?(:create)
|
||||
if options_on.nil? || options_on.include?(:update)
|
||||
before_save :reset_timestamp_attrs_for_update_if_needed!, :on => :update
|
||||
after_update :record_update, :if => :save_version?
|
||||
after_update :clear_version_instance!
|
||||
end
|
||||
after_destroy :record_destroy, :if => :save_version? if options_on.empty? || options_on.include?(:destroy)
|
||||
after_destroy :record_destroy, :if => :save_version? if options_on.nil? || options_on.include?(:destroy)
|
||||
|
||||
# Reset the transaction id when the transaction is closed
|
||||
after_commit :reset_transaction_id
|
||||
|
|
|
@ -1203,6 +1203,22 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
assert_equal 'destroy', @fluxor.versions.last.event
|
||||
end
|
||||
end
|
||||
context 'on []' do
|
||||
setup do
|
||||
Fluxor.reset_callbacks :create
|
||||
Fluxor.reset_callbacks :update
|
||||
Fluxor.reset_callbacks :destroy
|
||||
Fluxor.instance_eval <<-END
|
||||
has_paper_trail :on => []
|
||||
END
|
||||
@fluxor = Fluxor.create
|
||||
@fluxor.update_attributes :name => 'blah'
|
||||
@fluxor.destroy
|
||||
end
|
||||
should 'not have any versions' do
|
||||
assert_equal 0, @fluxor.versions.length
|
||||
end
|
||||
end
|
||||
context 'allows a symbol to be passed' do
|
||||
setup do
|
||||
Fluxor.reset_callbacks :create
|
||||
|
|
Loading…
Reference in a new issue