Stop invoking #dup on model in PaperTrail::Model::InstanceMethods#item_before_change

This commit is contained in:
Ben Atkins 2015-01-29 17:32:20 -05:00
parent b465bbb9cb
commit 5e77b16202
2 changed files with 7 additions and 14 deletions

View File

@ -419,16 +419,9 @@ module PaperTrail
end
def item_before_change
previous = self.dup
# `dup` clears timestamps so we add them back.
all_timestamp_attributes.each do |column|
if self.class.column_names.include?(column.to_s) and not send("#{column}_was").nil?
previous[column] = send("#{column}_was")
end
end
enums = previous.respond_to?(:defined_enums) ? previous.defined_enums : {}
previous = attributes.merge(changed_attributes)
enums = self.respond_to?(:defined_enums) ? self.defined_enums : {}
previous.tap do |prev|
prev.id = id # `dup` clears the `id` so we add that back
changed_attributes.select { |k,v| self.class.column_names.include?(k) }.each do |attr, before|
before = enums[attr][before] if enums[attr]
prev[attr] = before
@ -438,8 +431,8 @@ module PaperTrail
# returns hash of attributes (with appropriate attributes serialized),
# ommitting attributes to be skipped
def object_attrs_for_paper_trail(object)
attrs = object.attributes.except(*self.paper_trail_options[:skip])
def object_attrs_for_paper_trail(attributes_hash)
attrs = attributes_hash.except(*self.paper_trail_options[:skip])
if PaperTrail.serialized_attributes?
self.class.serialize_attributes_for_paper_trail(attrs)
end

View File

@ -10,7 +10,7 @@ class SerializerTest < ActiveSupport::TestCase
END
@fluxor = Fluxor.create :name => 'Some text.'
@original_fluxor_attributes = @fluxor.send(:item_before_change).attributes # this is exactly what PaperTrail serializes
@original_fluxor_attributes = @fluxor.send(:item_before_change) # this is exactly what PaperTrail serializes
@fluxor.update_attributes :name => 'Some more text.'
end
@ -41,7 +41,7 @@ class SerializerTest < ActiveSupport::TestCase
END
@fluxor = Fluxor.create :name => 'Some text.'
@original_fluxor_attributes = @fluxor.send(:item_before_change).attributes # this is exactly what PaperTrail serializes
@original_fluxor_attributes = @fluxor.send(:item_before_change) # this is exactly what PaperTrail serializes
@fluxor.update_attributes :name => 'Some more text.'
end
@ -83,7 +83,7 @@ class SerializerTest < ActiveSupport::TestCase
END
@fluxor = Fluxor.create
@original_fluxor_attributes = @fluxor.send(:item_before_change).attributes.reject { |k,v| v.nil? } # this is exactly what PaperTrail serializes
@original_fluxor_attributes = @fluxor.send(:item_before_change).reject { |k,v| v.nil? } # this is exactly what PaperTrail serializes
@fluxor.update_attributes :name => 'Some more text.'
end