Skip to content

Commit

Permalink
Change deletion behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
John Crepezzi committed Jan 11, 2011
1 parent 1c00376 commit 127022c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/track_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ def record_historical_changes(action)
# go through each and build the hashes
attributes = {}
historical_fields.each do |field, field_options|
next if !send(:"#{field}_changed?")
attributes.merge! field_options[:before] => send(:"#{field}_was"), field_options[:after] => send(field.to_sym)
next if !send(:"#{field}_changed?") && action == 'update'
after_value = action == 'destroy' ? nil : send(field.to_sym) # special tracking on deletions
attributes.merge! field_options[:before] => send(:"#{field}_was"), field_options[:after] => after_value
end
return if attributes.empty? && action == 'update' # nothing changed - skip out
# then go through each track
Expand Down
3 changes: 3 additions & 0 deletions spec/examples/basic_enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class BasicUser < ActiveRecord::Base
history = BasicUserHistory.first
history.basic_user_id.should == user.id # make sure the reference is maintained
history.action.should == 'destroy'
history.name_before.should == 'john'
history.name_after.should == nil # we do this for convenience
history.modifications.should == ['name']
end

end

0 comments on commit 127022c

Please sign in to comment.