Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/models/solidus_stripe/address_from_params_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def country
end

def state
@state ||= country.states.find_by_abbr(address_params[:region])
@state ||= begin
region = address_params[:region]
country.states.find_by(abbr: region) || country.states.find_by(name: region)
end
end

def default_attributes
Expand Down
4 changes: 3 additions & 1 deletion spec/features/stripe_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@
def within_3d_secure_modal
within_frame "__privateStripeFrame11" do
within_frame "__stripeJSChallengeFrame" do
yield
within_frame "acsFrame" do
yield
end
end
end
end
Expand Down
24 changes: 19 additions & 5 deletions spec/models/solidus_stripe/address_from_params_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
recipient: 'Clark Kent',
city: 'Metropolis',
postalCode: '12345',
addressLine: [ '12, Lincoln Rd']
addressLine: [ '12, Lincoln Rd'],
phone: '555-555-0199'
}
end

Expand All @@ -39,7 +40,8 @@
firstname: 'Clark',
lastname: 'Kent',
address1: params[:addressLine].first,
address2: nil
address2: nil,
phone: '555-555-0199'
)
end

Expand All @@ -50,11 +52,23 @@

context "when no user's address is compatible with the params" do
before do
user.addresses << create(:address)
user.addresses << create(:address, state: state)
end

it "returns a non-persisted address model" do
expect(subject).to be_new_record
it "returns a non-persisted valid address" do
aggregate_failures do
expect(subject).to be_new_record
expect(subject).to be_valid
expect(subject.state).to eq state
end
end

context "when the region is the state name" do
before { params[:region] = state.name }

it "still can set the address state attribute" do
expect(subject.state).to eq state
end
end
end
end
Expand Down