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

Make the create object work with custom serializer

This commit is contained in:
Bradley Priest 2013-01-10 18:48:06 +08:00
parent 714d7e13b5
commit 42022be8ec
2 changed files with 8 additions and 2 deletions

View file

@ -189,7 +189,7 @@ module PaperTrail
} }
if changed_notably? and version_class.column_names.include?('object_changes') 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 end
send(self.class.versions_association_name).create merge_metadata(data) send(self.class.versions_association_name).create merge_metadata(data)

View file

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