Skip to content

Commit

Permalink
Allow symbols to be passed to the 'on' option for single events
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrif committed Aug 29, 2013
1 parent 98848bb commit 28d4a42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def has_paper_trail(options = {})
:as => :item,
:order => "#{PaperTrail.timestamp_field} ASC"
end

after_create :record_create, :if => :save_version? if !options[:on] || options[:on].include?(:create)
before_update :record_update, :if => :save_version? if !options[:on] || options[:on].include?(:update)
after_destroy :record_destroy, :if => :save_version? if !options[:on] || options[:on].include?(:destroy)

options_on = Array(options[:on])
after_create :record_create, :if => :save_version? if options_on.empty? || options_on.include?(:create)
before_update :record_update, :if => :save_version? if options_on.empty? || options_on.include?(:update)
after_destroy :record_destroy, :if => :save_version? if options_on.empty? || options_on.include?(:destroy)
end

# Switches PaperTrail off for this class.
Expand Down
12 changes: 12 additions & 0 deletions test/unit/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,18 @@ def without(&block)
assert_equal 'destroy', @fluxor.versions.last.event
end
end
context 'allows a symbol to be passed' do
Fluxor.reset_callbacks :create
Fluxor.reset_callbacks :update
Fluxor.reset_callbacks :destroy
Fluxor.instance_evail <<-END
has_paper_trail :on => :create
END
should 'only have a version for hte create event' do
assert_equal 1, @fluxor.versions.length
assert_equal 'create', @fluxor.versions.last.event
end
end
end

context 'A model with column version and custom version_method' do
Expand Down

0 comments on commit 28d4a42

Please sign in to comment.