lib/superstore/attribute_methods/dirty.rb in superstore-1.2.0 vs lib/superstore/attribute_methods/dirty.rb in superstore-2.0.0

- old
+ new

@@ -25,16 +25,26 @@ result = {} changed_attributes.each_key { |attr| result[attr] = read_attribute(attr) } result end + def old_attribute_value(attr) + if attribute_changed?(attr) + changed_attributes[attr] + else + read_attribute attr + end + end + def write_attribute(name, value) name = name.to_s - old = read_attribute(name) + old = old_attribute_value(name) super - unless attribute_changed?(name) || old == read_attribute(name) + if old == read_attribute(name) + changed_attributes.delete(name) + else changed_attributes[name] = old end end end end