From 3e7f5a4ea99f6dd876715ffb7d8a25a889582f6c Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 30 Jun 2020 10:38:08 +0200 Subject: [PATCH] Update user address tests I considered deleting these tests, as they're not very good and are testing Rails functionality. I decided to leave them in case something explodes in a future upgrade. For reference: there are issues in Rails 4 when using `object.clone.attributes`, and with assigning a hash containing `created_at` and `updated_at` values with `object.update(attributes_hash)`. --- spec/models/spree/user_spec.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index 0e48621452..ba5b4cd488 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -9,23 +9,25 @@ describe Spree.user_class do describe "addresses" do let(:user) { create(:user, bill_address: create(:address)) } - it 'updates billing address with new address' do - old_bill_address = user.bill_address - new_bill_address = create(:address, firstname: 'abc') + context "updating addresses via nested attributes" do + it 'updates billing address with new address' do + old_bill_address = user.bill_address + new_bill_address = create(:address, firstname: 'abc') - user.update(bill_address_attributes: new_bill_address.clone.attributes.merge('id' => old_bill_address.id)) + user.update(bill_address_attributes: new_bill_address.dup.attributes.merge('id' => old_bill_address.id).except!('created_at', 'updated_at')) - expect(user.bill_address.id).to eq old_bill_address.id - expect(user.bill_address.firstname).to eq new_bill_address.firstname - end + expect(user.bill_address.id).to eq old_bill_address.id + expect(user.bill_address.firstname).to eq new_bill_address.firstname + end - it 'creates new shipping address' do - new_ship_address = create(:address, firstname: 'abc') + it 'creates new shipping address' do + new_ship_address = create(:address, firstname: 'abc') - user.update(ship_address_attributes: new_ship_address.clone.attributes) + user.update(ship_address_attributes: new_ship_address.dup.attributes.except!('created_at', 'updated_at')) - expect(user.ship_address.id).not_to eq new_ship_address.id - expect(user.ship_address.firstname).to eq new_ship_address.firstname + expect(user.ship_address.id).not_to eq new_ship_address.id + expect(user.ship_address.firstname).to eq new_ship_address.firstname + end end end