Skip to content

Commit

Permalink
Remove any remaining reference to Address deprecated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
filippoliverani committed Apr 17, 2020
1 parent ab8bebc commit 12bdceb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions backend/spec/controllers/spree/admin/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions core/app/models/spree/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions core/lib/spree/testing_support/factories/address_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
state_code { 'AL' }
end

firstname { 'John' }
lastname { nil }
name { 'John Von Doe' }
company { 'Company' }
address1 { '10 Lovely Street' }
address2 { 'Northwest' }
Expand Down
20 changes: 10 additions & 10 deletions core/spec/models/spree/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions core/spec/models/spree/concerns/user_address_book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12bdceb

Please sign in to comment.