1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Merge branch 'hash' of https://github.com/edtsech/paper_trail into edtsech-hash

* 'hash' of https://github.com/edtsech/paper_trail:
  Changeset method return {} (empty hash) for create and destroy actions if object_changes column defined but return nil if column does not exist
This commit is contained in:
Andy Stewart 2011-07-14 10:26:28 +01:00
commit c0f4e3282c
3 changed files with 9 additions and 3 deletions

View file

@ -458,7 +458,7 @@ There are two scenarios: diffing adjacent versions and diffing non-adjacent vers
The best way to diff adjacent versions is to get PaperTrail to do it for you. If you add an `object_changes` text column to your `versions` table, either at installation time with the `--with-changes` option or manually, PaperTrail will store the `changes` diff (excluding any attributes PaperTrail is ignoring) in each `update` version. You can use the `version.changeset` method to retrieve it. For example:
>> widget = Widget.create :name => 'Bob'
>> widget.versions.last.changeset # nil
>> widget.versions.last.changeset # {}
>> widget.update_attributes :name => 'Robert'
>> widget.versions.last.changeset # {'name' => ['Bob', 'Robert']}

View file

@ -81,7 +81,13 @@ class Version < ActiveRecord::Base
# Returns what changed in this version of the item. Cf. `ActiveModel::Dirty#changes`.
def changeset
YAML::load(object_changes) if Version.method_defined?(:object_changes) && object_changes
if Version.method_defined?(:object_changes)
if changes = object_changes
YAML::load(changes)
else
{}
end
end
end
# Returns who put the item into the state stored in this version.

View file

@ -65,7 +65,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
end
should 'should not have changes' do
assert_nil @widget.versions.last.changeset
assert_equal Hash.new, @widget.versions.last.changeset
end
context 'and then updated without any changes' do