Skip to content

Commit

Permalink
Make the create object work with custom serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleypriest committed Jan 10, 2013
1 parent 714d7e1 commit 42022be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def record_create
}

if changed_notably? and version_class.column_names.include?('object_changes')
data[:object_changes] = changes_for_paper_trail.to_yaml
data[:object_changes] = PaperTrail.serializer.dump(changes_for_paper_trail)
end

send(self.class.versions_association_name).create merge_metadata(data)
Expand Down
8 changes: 7 additions & 1 deletion test/unit/serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SerializerTest < ActiveSupport::TestCase
PaperTrail.config.serializer = PaperTrail::Serializers::Yaml
end

should 'work with custom serializer' do
should 'reify with custom serializer' do
# Normal behaviour
assert_equal 2, @fluxor.versions.length
assert_nil @fluxor.versions[0].reify
Expand All @@ -64,7 +64,13 @@ class SerializerTest < ActiveSupport::TestCase
hash = {"widget_id" => nil,"name" =>"Some text.","id" =>1}
assert_equal JSON.dump(hash), @fluxor.versions[1].object
assert_equal hash, JSON.parse(@fluxor.versions[1].object)
end

should 'store object_changes' do
initial_changeset = {"name" => [nil, "Some text."], "id" => [nil, 1]}
second_changeset = {"name"=>["Some text.", "Some more text."]}
assert_equal initial_changeset, @fluxor.versions[0].changeset
assert_equal second_changeset, @fluxor.versions[1].changeset
end
end

Expand Down

0 comments on commit 42022be

Please sign in to comment.