diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e688427b..850e31c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 2.7.1 (Unreleased) + - [#197](https://github.com/airblade/paper_trail/issues/197) - PaperTrail now falls back on using YAML for serialization of + serialized model attributes for storage in the `object` and `object_changes` columns in the `Version` table. This fixes + compatibility for `Rails 3.0.x` for projects that employ the `serialize` declaration on a model. - [#194](https://github.com/airblade/paper_trail/issues/194) - A JSON serializer is now included in the gem. - [#192](https://github.com/airblade/paper_trail/pull/192) - `object_changes` should store serialized representation of serialized attributes for `create` actions (in addition to `update` actions, which had already been patched by @@ -14,7 +17,7 @@ - [#183](https://github.com/airblade/paper_trail/pull/183) - Fully qualify the `Version` class to help prevent namespace resolution errors within other gems / plugins. - [#180](https://github.com/airblade/paper_trail/pull/180) - Store serialized representation of serialized attributes - on the `object` and `object_changes` column in the `Version` table. + on the `object` and `object_changes` columns in the `Version` table. - [#164](https://github.com/airblade/paper_trail/pull/164) - Allow usage of custom serializer for storage of object attributes. ## 2.6.4 diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index fa56a204b..061f4c532 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -84,13 +84,19 @@ def paper_trail_on # Used for Version#object attribute def serialize_attributes_for_paper_trail(attributes) serialized_attributes.each do |key, coder| - attributes[key] = coder.dump(attributes[key]) if attributes.key?(key) + if attributes.key?(key) + coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) # Rails 3.0.x's default serializers don't have a `dump` method + attributes[key] = coder.dump(attributes[key]) + end end end def unserialize_attributes_for_paper_trail(attributes) serialized_attributes.each do |key, coder| - attributes[key] = coder.load(attributes[key]) if attributes.key?(key) + if attributes.key?(key) + coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) + attributes[key] = coder.load(attributes[key]) + end end end @@ -98,6 +104,7 @@ def unserialize_attributes_for_paper_trail(attributes) def serialize_attribute_changes(changes) serialized_attributes.each do |key, coder| if changes.key?(key) + coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) # Rails 3.0.x's default serializers don't have a `dump` method old_value, new_value = changes[key] changes[key] = [coder.dump(old_value), coder.dump(new_value)] @@ -108,6 +115,7 @@ def serialize_attribute_changes(changes) def unserialize_attribute_changes(changes) serialized_attributes.each do |key, coder| if changes.key?(key) + coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) old_value, new_value = changes[key] changes[key] = [coder.load(old_value), coder.load(new_value)]