Use #dup when copying attributes hash

In Rails 4, #clone behaves differently. The attributes hash of the cloned object is shared with the original, it's not a separate object! https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/core.rb#L217-L220
This commit is contained in:
Matt-Yorkley
2020-06-29 19:54:28 +02:00
parent abe96c6f32
commit ce8908f53b

View File

@@ -9,7 +9,7 @@ class UserDefaultAddressSetter
# Sets the order bill address as the user default bill address
def set_default_bill_address
new_bill_address = @order.bill_address.clone.attributes
new_bill_address = @order.bill_address.dup.attributes
set_bill_address_attributes(@current_user, new_bill_address)
set_bill_address_attributes(@order.customer, new_bill_address)
@@ -17,7 +17,7 @@ class UserDefaultAddressSetter
# Sets the order ship address as the user default ship address
def set_default_ship_address
new_ship_address = @order.ship_address.clone.attributes
new_ship_address = @order.ship_address.dup.attributes
set_ship_address_attributes(@current_user, new_ship_address)
set_ship_address_attributes(@order.customer, new_ship_address)