Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow symbols to be passed to the 'on' option for single events #264

Merged
merged 1 commit into from
Aug 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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