diff --git a/backend/spec/controllers/spree/admin/payments_controller_spec.rb b/backend/spec/controllers/spree/admin/payments_controller_spec.rb index cd73336c7e2..fabae0d7374 100644 --- a/backend/spec/controllers/spree/admin/payments_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/payments_controller_spec.rb @@ -55,7 +55,7 @@ module Admin let(:address_attributes) do { - 'firstname' => address.firstname, + 'name' => address.name, 'address1' => address.address1, 'city' => address.city, 'country_id' => address.country_id, @@ -68,7 +68,7 @@ module Admin it 'associates the address' do expect(order.payments.count).to eq(1) credit_card = order.payments.last.source - expect(credit_card.address.attributes).to include(address_attributes) + expect(credit_card.address.as_json).to include(address_attributes) end end end diff --git a/backend/spec/controllers/spree/admin/search_controller_spec.rb b/backend/spec/controllers/spree/admin/search_controller_spec.rb index adab87f5e28..0b022b6aa05 100644 --- a/backend/spec/controllers/spree/admin/search_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/search_controller_spec.rb @@ -25,23 +25,27 @@ end context 'when searching by user attributes' do - let(:params) { { q: user_attribute } } + let(:params) { { q: search_query } } + + def starting_letters(string) + string.first(3) + end context 'when searching by email' do it_should_behave_like 'user found by search' do - let(:user_attribute) { user.email } + let(:search_query) { starting_letters(user.email) } end end context 'when searching by ship addresss name' do it_should_behave_like 'user found by search' do - let(:user_attribute) { user.ship_address.name } + let(:search_query) { starting_letters(user.ship_address.name) } end end context 'when searching by bill address name' do it_should_behave_like 'user found by search' do - let(:user_attribute) { user.bill_address.name } + let(:search_query) { starting_letters(user.bill_address.name) } end end end diff --git a/core/app/models/spree/address.rb b/core/app/models/spree/address.rb index 0aa2a66139e..aa271685cbb 100644 --- a/core/app/models/spree/address.rb +++ b/core/app/models/spree/address.rb @@ -180,7 +180,10 @@ def country_iso # @return [String] the full name on this address def name - Spree::Address::Name.new(firstname, lastname).value + Spree::Address::Name.new( + read_attribute(:firstname), + read_attribute(:lastname) + ).value end def name=(value) @@ -204,7 +207,7 @@ def as_json(options = {}) private def validate_name - return if firstname.present? + return if name.present? name_attribute = if Spree::Config.use_combined_first_and_last_name_in_address :name diff --git a/core/lib/spree/testing_support/factories/address_factory.rb b/core/lib/spree/testing_support/factories/address_factory.rb index 72568e6f41a..9f0a51407db 100644 --- a/core/lib/spree/testing_support/factories/address_factory.rb +++ b/core/lib/spree/testing_support/factories/address_factory.rb @@ -11,8 +11,7 @@ state_code { 'AL' } end - firstname { 'John' } - lastname { nil } + name { 'John Von Doe' } company { 'Company' } address1 { '10 Lovely Street' } address2 { 'Northwest' } diff --git a/core/spec/models/spree/address_spec.rb b/core/spec/models/spree/address_spec.rb index 3ff91ba1b7d..0588f8dee30 100644 --- a/core/spec/models/spree/address_spec.rb +++ b/core/spec/models/spree/address_spec.rb @@ -159,19 +159,19 @@ end it 'accepts other attributes' do - address = Spree::Address.build_default(first_name: 'Ryan') + address = Spree::Address.build_default(name: 'Ryan') expect(address.country).to eq default_country - expect(address.first_name).to eq 'Ryan' + expect(address.name).to eq 'Ryan' end it 'accepts a block' do address = Spree::Address.build_default do |record| - record.first_name = 'Ryan' + record.name = 'Ryan' end expect(address.country).to eq default_country - expect(address.first_name).to eq 'Ryan' + expect(address.name).to eq 'Ryan' end it 'can override the country' do @@ -213,7 +213,7 @@ end end - let(:new_address_attributes) { attributes_for(:address) } + let(:new_address_attributes) { build(:address).attributes } subject { Spree::Address.immutable_merge(existing_address, new_address_attributes) } context "no existing address supplied" do @@ -227,7 +227,7 @@ context 'and there is a matching address in the database' do let(:new_address_attributes) { Spree::Address.value_attributes(matching_address.attributes) } - let!(:matching_address) { create(:address, firstname: 'Jordan') } + let!(:matching_address) { create(:address, name: 'Jordan') } it "returns the matching address" do expect(subject.attributes).to be_address_equivalent_attributes(new_address_attributes) @@ -256,7 +256,7 @@ context 'and changed address matches an existing address' do let(:new_address_attributes) { Spree::Address.value_attributes(matching_address.attributes) } - let!(:matching_address) { create(:address, firstname: 'Jordan') } + let!(:matching_address) { create(:address, name: 'Jordan') } it 'returns the matching address' do expect(subject.attributes).to be_address_equivalent_attributes(new_address_attributes) @@ -319,10 +319,10 @@ describe '.taxation_attributes' do context 'both taxation and non-taxation attributes are present ' do - let(:address) { Spree::Address.new firstname: 'Michael', lastname: 'Jackson', state_id: 1, country_id: 2, zipcode: '12345' } + let(:address) { Spree::Address.new name: 'Michael Jackson', state_id: 1, country_id: 2, zipcode: '12345' } it 'removes the non-taxation attributes' do - expect(address.taxation_attributes).not_to eq('firstname' => 'Michael', 'lastname' => 'Jackson') + expect(address.taxation_attributes).not_to eq('name' => 'Michael Jackson') end it 'returns only the taxation attributes' do @@ -331,7 +331,7 @@ end context 'taxation attributes are blank' do - let(:address) { Spree::Address.new firstname: 'Michael', lastname: 'Jackson' } + let(:address) { Spree::Address.new name: 'Michael Jackson' } it 'returns a subset of the attributes with the correct keys and nil values' do expect(address.taxation_attributes).to eq('state_id' => nil, 'country_id' => nil, 'zipcode' => nil) diff --git a/core/spec/models/spree/concerns/user_address_book_spec.rb b/core/spec/models/spree/concerns/user_address_book_spec.rb index 07f989d8648..5a1cb231101 100644 --- a/core/spec/models/spree/concerns/user_address_book_spec.rb +++ b/core/spec/models/spree/concerns/user_address_book_spec.rb @@ -77,16 +77,16 @@ module Spree end context "and changing another address field at the same time" do - let(:updated_address_attributes) { address.attributes.tap { |value| value[:first_name] = "Newbie" } } + let(:updated_address_attributes) { address.attributes.tap { |value| value[:city] = "Dallas" } } subject { user.save_in_address_book(updated_address_attributes, true) } - it "changes first name" do - expect(subject.first_name).to eq updated_address_attributes[:first_name] + it "changes city" do + expect(subject.city).to eq updated_address_attributes[:city] end - it "preserves last name" do - expect(subject.last_name).to eq address.last_name + it "preserves name" do + expect(subject.name).to eq address.name end it "is a new immutable address instance" do