Skip to content

Commit 1389785

Browse files
authored
Merge pull request #186 from nebulab/kennyadsl/feature-specs-fill-address
Fill address names combined when needed
2 parents 9a1e7fa + 3d92726 commit 1389785

2 files changed

Lines changed: 36 additions & 32 deletions

File tree

spec/features/checkout_spec.rb

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,9 @@
6060
expect(page).to have_text(/Billing Address/i)
6161
expect(page).to have_text(/Shipping Address/i)
6262

63-
str_addr = 'bill_address'
64-
select 'United States', from: "order_#{str_addr}_attributes_country_id"
65-
%w(firstname lastname address1 city zipcode phone).each do |field|
66-
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
67-
end
68-
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
69-
check 'order_use_billing'
70-
63+
fill_addresses_fields_with(address)
7164
click_button 'Save and Continue'
65+
7266
click_button 'Save and Continue'
7367
click_button 'Save and Continue'
7468
click_button 'Place Order'
@@ -92,15 +86,9 @@
9286

9387
click_button 'Checkout'
9488

95-
str_addr = 'bill_address'
96-
select 'United States', from: "order_#{str_addr}_attributes_country_id"
97-
%w(firstname lastname address1 city zipcode phone).each do |field|
98-
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
99-
end
100-
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
101-
check 'order_use_billing'
102-
89+
fill_addresses_fields_with(address)
10390
click_button 'Save and Continue'
91+
10492
click_button 'Save and Continue'
10593
click_button 'Save and Continue'
10694
click_button 'Place Order'
@@ -134,14 +122,7 @@
134122
click_link 'Cart'
135123
click_button 'Checkout'
136124

137-
str_addr = 'bill_address'
138-
select 'United States', from: "order_#{str_addr}_attributes_country_id"
139-
%w(firstname lastname address1 city zipcode phone).each do |field|
140-
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
141-
end
142-
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
143-
check 'order_use_billing'
144-
125+
fill_addresses_fields_with(address)
145126
click_button 'Save and Continue'
146127

147128
expect(page).not_to have_text 'Email is invalid'
@@ -163,15 +144,9 @@
163144

164145
expect(page).to have_text 'You have signed up successfully.'
165146

166-
str_addr = 'bill_address'
167-
select 'United States', from: "order_#{str_addr}_attributes_country_id"
168-
%w(firstname lastname address1 city zipcode phone).each do |field|
169-
fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
170-
end
171-
select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
172-
check 'order_use_billing'
173-
147+
fill_addresses_fields_with(address)
174148
click_button 'Save and Continue'
149+
175150
click_button 'Save and Continue'
176151
click_button 'Save and Continue'
177152
click_button 'Place Order'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module FillAddressFields
4+
def fill_addresses_fields_with(address)
5+
fields = %w[
6+
address1
7+
city
8+
zipcode
9+
phone
10+
]
11+
fields += if Spree::Config.has_preference?(:use_combined_first_and_last_name_in_address) && Spree::Config.use_combined_first_and_last_name_in_address
12+
%w[name]
13+
else
14+
%w[firstname lastname]
15+
end
16+
17+
fields.each do |field|
18+
fill_in "order_bill_address_attributes_#{field}", with: address.send(field).to_s
19+
end
20+
select 'United States', from: "order_bill_address_attributes_country_id"
21+
select address.state.name.to_s, from: "order_bill_address_attributes_state_id"
22+
23+
check 'order_use_billing'
24+
end
25+
end
26+
27+
RSpec.configure do |config|
28+
config.include FillAddressFields, type: :feature
29+
end

0 commit comments

Comments
 (0)