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)`.
This commit is contained in:
Matt-Yorkley
2020-06-30 10:38:08 +02:00
parent 87cd936c94
commit 3e7f5a4ea9

View File

@@ -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