lib/paper_trail/version.rb in paper_trail-2.7.0 vs lib/paper_trail/version.rb in paper_trail-2.7.1
- old
+ new
@@ -77,14 +77,14 @@
class_name = attrs[inheritance_column_name].blank? ? item_type : attrs[inheritance_column_name]
klass = class_name.constantize
model = klass.new
end
- model.class.unserialize_attributes attrs
+ model.class.unserialize_attributes_for_paper_trail attrs
attrs.each do |k, v|
if model.respond_to?("#{k}=")
- model.send :write_attribute, k.to_sym, v
+ model[k.to_sym] = v
else
logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
end
end
@@ -100,18 +100,16 @@
end
# Returns what changed in this version of the item. Cf. `ActiveModel::Dirty#changes`.
# Returns nil if your `versions` table does not have an `object_changes` text column.
def changeset
- if self.class.column_names.include? 'object_changes'
- if changes = object_changes
- HashWithIndifferentAccess[PaperTrail.serializer.load(changes)].tap do |changes|
- item_type.constantize.unserialize_attribute_changes(changes)
- end
- else
- {}
- end
+ return nil unless self.class.column_names.include? 'object_changes'
+
+ HashWithIndifferentAccess.new(PaperTrail.serializer.load(object_changes)).tap do |changes|
+ item_type.constantize.unserialize_attribute_changes(changes)
end
+ rescue
+ {}
end
# Returns who put the item into the state stored in this version.
def originator
previous.try :whodunnit