spree_frontend 3.0.10 → 3.1.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/spree/frontend.js +3 -0
  4. data/app/assets/javascripts/spree/frontend/checkout.js.coffee +12 -7
  5. data/app/assets/javascripts/spree/frontend/checkout/payment.js.coffee +5 -3
  6. data/app/assets/javascripts/spree/frontend/product.js.coffee +11 -4
  7. data/app/assets/stylesheets/spree/frontend.css +0 -1
  8. data/app/assets/stylesheets/spree/frontend/frontend_bootstrap.css.scss +2 -2
  9. data/app/controllers/spree/checkout_controller.rb +17 -1
  10. data/app/controllers/spree/home_controller.rb +1 -1
  11. data/app/controllers/spree/orders_controller.rb +4 -2
  12. data/app/controllers/spree/products_controller.rb +7 -4
  13. data/app/controllers/spree/store_controller.rb +23 -18
  14. data/app/controllers/spree/taxons_controller.rb +1 -6
  15. data/app/helpers/spree/frontend_helper.rb +3 -2
  16. data/app/helpers/spree/taxons_helper.rb +3 -2
  17. data/app/views/spree/address/_form.html.erb +28 -15
  18. data/app/views/spree/checkout/_payment.html.erb +3 -2
  19. data/app/views/spree/checkout/_summary.html.erb +7 -0
  20. data/app/views/spree/checkout/edit.html.erb +3 -1
  21. data/app/views/spree/checkout/payment/_gateway.html.erb +13 -5
  22. data/app/views/spree/checkout/payment/_storecredit.html.erb +16 -0
  23. data/app/views/spree/payments/_payment.html.erb +2 -0
  24. data/app/views/spree/products/_cart_form.html.erb +24 -15
  25. data/app/views/spree/products/_taxons.html.erb +7 -11
  26. data/app/views/spree/products/show.html.erb +8 -6
  27. data/app/views/spree/shared/_filters.html.erb +1 -1
  28. data/app/views/spree/shared/_header.html.erb +1 -1
  29. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  30. data/app/views/spree/shared/_order_details.html.erb +6 -6
  31. data/app/views/spree/shared/_products.html.erb +12 -14
  32. data/app/views/spree/shared/forbidden.html.erb +0 -0
  33. data/config/routes.rb +15 -19
  34. data/spec/controllers/controller_helpers_spec.rb +102 -6
  35. data/spec/controllers/spree/checkout_controller_spec.rb +7 -0
  36. data/spec/features/checkout_spec.rb +223 -165
  37. data/spec/features/checkout_unshippable_spec.rb +1 -1
  38. data/spec/features/microdata_spec.rb +0 -0
  39. data/spec/features/products_spec.rb +79 -7
  40. data/spec/helpers/frontend_helper_spec.rb +16 -0
  41. data/spec/spec_helper.rb +1 -0
  42. metadata +13 -10
  43. data/CHANGELOG.md +0 -1
@@ -271,6 +271,13 @@ describe Spree::CheckoutController, type: :controller do
271
271
  spree_post :update, state: 'address'
272
272
  expect(response).to render_template :edit
273
273
  end
274
+
275
+ it "should render order in payment state when payment fails" do
276
+ order.update_column(:state, 'confirm')
277
+ allow(controller).to receive(:insufficient_payment?).and_return(true)
278
+ spree_post :update, state: 'confirm'
279
+ expect(order.state).to eq('payment')
280
+ end
274
281
  end
275
282
 
276
283
  context "when current_order is nil" do
@@ -1,95 +1,97 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Checkout", type: :feature, inaccessible: true, js: true do
4
-
3
+ describe 'Checkout', type: :feature, inaccessible: true, js: true do
5
4
  include_context 'checkout setup'
6
5
 
6
+ let(:country) { create(:country, name: 'United States of America', iso_name: 'UNITED STATES') }
7
+ let(:state) { create(:state, name: 'Alabama', abbr: 'AL', country: country) }
8
+
7
9
  context "visitor makes checkout as guest without registration" do
8
10
  before(:each) do
9
11
  stock_location.stock_items.update_all(count_on_hand: 1)
10
12
  end
11
13
 
12
- context "defaults to use billing address" do
14
+ context 'defaults to use billing address' do
13
15
  before do
14
16
  add_mug_to_cart
15
- Spree::Order.last.update_column(:email, "test@example.com")
16
- click_button "Checkout"
17
+ Spree::Order.last.update_column(:email, 'test@example.com')
18
+ click_button 'Checkout'
17
19
  end
18
20
 
19
- it "should default checkbox to checked" do
21
+ it 'should default checkbox to checked' do
20
22
  expect(find('input#order_use_billing')).to be_checked
21
23
  end
22
24
 
23
- it "should remain checked when used and visitor steps back to address step" do
25
+ it 'should remain checked when used and visitor steps back to address step' do
24
26
  fill_in_address
25
27
  expect(find('input#order_use_billing')).to be_checked
26
28
  end
27
29
  end
28
30
 
29
31
  # Regression test for #4079
30
- context "persists state when on address page" do
32
+ context 'persists state when on address page' do
31
33
  before do
32
34
  add_mug_to_cart
33
- click_button "Checkout"
35
+ click_button 'Checkout'
34
36
  end
35
37
 
36
38
  specify do
37
39
  expect(Spree::Order.count).to eq 1
38
- expect(Spree::Order.last.state).to eq "address"
40
+ expect(Spree::Order.last.state).to eq 'address'
39
41
  end
40
42
  end
41
43
 
42
44
  # Regression test for #1596
43
- context "full checkout" do
45
+ context 'full checkout' do
44
46
  before do
45
47
  shipping_method.calculator.update!(preferred_amount: 10)
46
48
  mug.shipping_category = shipping_method.shipping_categories.first
47
49
  mug.save!
48
50
  end
49
51
 
50
- it "does not break the per-item shipping method calculator", :js => true do
52
+ it 'does not break the per-item shipping method calculator', js: true do
51
53
  add_mug_to_cart
52
- click_button "Checkout"
54
+ click_button 'Checkout'
53
55
 
54
- fill_in "order_email", :with => "test@example.com"
56
+ fill_in 'order_email', with: 'test@example.com'
55
57
  click_on 'Continue'
56
58
  fill_in_address
57
59
 
58
- click_button "Save and Continue"
60
+ click_button 'Save and Continue'
59
61
  expect(page).to_not have_content("undefined method `promotion'")
60
- click_button "Save and Continue"
61
- expect(page).to have_content("Shipping total: $10.00")
62
+ click_button 'Save and Continue'
63
+ expect(page).to have_content('Shipping total: $10.00')
62
64
  end
63
65
  end
64
66
 
65
67
  # Regression test for #4306
66
- context "free shipping" do
68
+ context 'free shipping' do
67
69
  before do
68
70
  add_mug_to_cart
69
- click_button "Checkout"
70
- fill_in "order_email", :with => "test@example.com"
71
+ click_button 'Checkout'
72
+ fill_in 'order_email', with: 'test@example.com'
71
73
  click_on 'Continue'
72
74
  end
73
75
 
74
76
  it "should not show 'Free Shipping' when there are no shipments" do
75
- within("#checkout-summary") do
77
+ within('#checkout-summary') do
76
78
  expect(page).to_not have_content('Free Shipping')
77
79
  end
78
80
  end
79
81
  end
80
82
 
81
83
  # Regression test for #4190
82
- it "updates state_lock_version on form submission", js: true do
84
+ it 'updates state_lock_version on form submission', js: true do
83
85
  add_mug_to_cart
84
86
  click_button "Checkout"
85
87
 
86
- expect(find('input#order_state_lock_version', visible: false).value).to eq "0"
88
+ expect(find('input#order_state_lock_version', visible: false).value).to eq '0'
87
89
 
88
- fill_in "order_email", with: "test@example.com"
90
+ fill_in 'order_email', with: 'test@example.com'
89
91
  fill_in_address
90
- click_button "Save and Continue"
92
+ click_button 'Save and Continue'
91
93
 
92
- expect(find('input#order_state_lock_version', visible: false).value).to eq "1"
94
+ expect(find('input#order_state_lock_version', visible: false).value).to eq '1'
93
95
  end
94
96
  end
95
97
 
@@ -98,54 +100,54 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
98
100
  before(:each) do
99
101
  order = OrderWalkthrough.up_to(:payment)
100
102
  allow(order).to receive_messages confirmation_required?: true
101
- allow(order).to receive_messages(:available_payment_methods => [ create(:credit_card_payment_method) ])
103
+ allow(order).to receive_messages(available_payment_methods: [create(:credit_card_payment_method)])
102
104
 
103
105
  user = create(:user)
104
106
  order.user = user
105
- order.update!
107
+ order.update_with_updater!
106
108
 
107
109
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
108
110
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
109
111
  end
110
112
 
111
- it "redirects to payment page", inaccessible: true, js: true do
113
+ it 'redirects to payment page', inaccessible: true, js: true do
112
114
  visit spree.checkout_state_path(:payment)
113
- click_button "Save and Continue"
114
- choose "Credit Card"
115
- fill_in "Card Number", with: '123'
116
- fill_in "card_expiry", with: '04 / 20'
117
- fill_in "Card Code", with: '123'
118
- click_button "Save and Continue"
119
- click_button "Place Order"
120
- expect(page).to have_content("Bogus Gateway: Forced failure")
121
- expect(page.current_url).to include("/checkout/payment")
115
+ click_button 'Save and Continue'
116
+ choose 'Credit Card'
117
+ fill_in 'Card Number', with: '123'
118
+ fill_in 'card_expiry', with: '04 / 20'
119
+ fill_in 'Card Code', with: '123'
120
+ click_button 'Save and Continue'
121
+ click_button 'Place Order'
122
+ expect(page).to have_content('Bogus Gateway: Forced failure')
123
+ expect(page.current_url).to include('/checkout/payment')
122
124
  end
123
125
  end
124
126
 
125
- #regression test for #3945
126
- context "when Spree::Config[:always_include_confirm_step] is true" do
127
+ # regression test for #3945
128
+ context 'when Spree::Config[:always_include_confirm_step] is true' do
127
129
  before do
128
130
  Spree::Config[:always_include_confirm_step] = true
129
131
  end
130
132
 
131
- it "displays confirmation step", js: true do
133
+ it 'displays confirmation step', js: true do
132
134
  add_mug_to_cart
133
- click_button "Checkout"
135
+ click_button 'Checkout'
134
136
 
135
- fill_in "order_email", with: "test@example.com"
137
+ fill_in 'order_email', with: 'test@example.com'
136
138
  click_on 'Continue'
137
139
  fill_in_address
138
140
 
139
- click_button "Save and Continue"
140
- click_button "Save and Continue"
141
- click_button "Save and Continue"
141
+ click_button 'Save and Continue'
142
+ click_button 'Save and Continue'
143
+ click_button 'Save and Continue'
142
144
 
143
- continue_button = find("#checkout .btn-success")
144
- expect(continue_button.value).to eq "Place Order"
145
+ continue_button = find('#checkout .btn-success')
146
+ expect(continue_button.value).to eq 'Place Order'
145
147
  end
146
148
  end
147
149
 
148
- context "and likes to double click buttons" do
150
+ context 'and likes to double click buttons' do
149
151
  let!(:user) { create(:user) }
150
152
 
151
153
  let!(:order) do
@@ -154,7 +156,7 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
154
156
 
155
157
  order.reload
156
158
  order.user = user
157
- order.update!
159
+ order.update_with_updater!
158
160
  order
159
161
  end
160
162
 
@@ -164,33 +166,33 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
164
166
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(skip_state_validation?: true)
165
167
  end
166
168
 
167
- it "prevents double clicking the payment button on checkout", js: true do
169
+ it 'prevents double clicking the payment button on checkout', js: true do
168
170
  visit spree.checkout_state_path(:payment)
169
171
 
170
172
  # prevent form submit to verify button is disabled
171
173
  page.execute_script("$('#checkout_form_payment').submit(function(){return false;})")
172
174
 
173
- expect(page).to_not have_selector('input.btn[disabled]')
174
- click_button "Save and Continue"
175
- expect(page).to have_selector('input.btn[disabled]')
175
+ expect(page).to_not have_selector('input.btn.disabled')
176
+ click_button 'Save and Continue'
177
+ expect(page).to have_selector('input.btn.disabled')
176
178
  end
177
179
 
178
- it "prevents double clicking the confirm button on checkout", :js => true do
180
+ it 'prevents double clicking the confirm button on checkout', js: true do
179
181
  order.payments << create(:payment, amount: order.amount)
180
182
  visit spree.checkout_state_path(:confirm)
181
183
 
182
184
  # prevent form submit to verify button is disabled
183
185
  page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
184
186
 
185
- expect(page).to_not have_selector('input.btn[disabled]')
186
- click_button "Place Order"
187
- expect(page).to have_selector('input.btn[disabled]')
187
+ expect(page).to_not have_selector('input.btn.disabled')
188
+ click_button 'Place Order'
189
+ expect(page).to have_selector('input.btn.disabled')
188
190
  end
189
191
  end
190
192
 
191
- context "when several payment methods are available", js: true do
192
- let(:credit_cart_payment) {create(:credit_card_payment_method) }
193
- let(:check_payment) {create(:check_payment_method) }
193
+ context 'when several payment methods are available', js: true do
194
+ let(:credit_cart_payment) { create(:credit_card_payment_method) }
195
+ let(:check_payment) { create(:check_payment_method) }
194
196
 
195
197
  after do
196
198
  Capybara.ignore_hidden_elements = true
@@ -199,9 +201,9 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
199
201
  before do
200
202
  Capybara.ignore_hidden_elements = false
201
203
  order = OrderWalkthrough.up_to(:payment)
202
- allow(order).to receive_messages(available_payment_methods: [check_payment,credit_cart_payment])
204
+ allow(order).to receive_messages(available_payment_methods: [check_payment, credit_cart_payment])
203
205
  order.user = create(:user)
204
- order.update!
206
+ order.update_with_updater!
205
207
 
206
208
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
207
209
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: order.user)
@@ -209,25 +211,25 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
209
211
  visit spree.checkout_state_path(:payment)
210
212
  end
211
213
 
212
- it "the first payment method should be selected" do
213
- payment_method_css = "#order_payments_attributes__payment_method_id_"
214
+ it 'the first payment method should be selected' do
215
+ payment_method_css = '#order_payments_attributes__payment_method_id_'
214
216
  expect(find("#{payment_method_css}#{check_payment.id}")).to be_checked
215
217
  expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_checked
216
218
  end
217
219
 
218
- it "the fields for the other payment methods should be hidden" do
219
- payment_method_css = "#payment_method_"
220
+ it 'the fields for the other payment methods should be hidden' do
221
+ payment_method_css = '#payment_method_'
220
222
  expect(find("#{payment_method_css}#{check_payment.id}")).to be_visible
221
223
  expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_visible
222
224
  end
223
225
  end
224
226
 
225
- context "user has payment sources", js: true do
227
+ context 'user has payment sources', js: true do
226
228
  let(:bogus) { create(:credit_card_payment_method) }
227
229
  let(:user) { create(:user) }
228
230
 
229
231
  let!(:credit_card) do
230
- create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: "BGS-WEFWF")
232
+ create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: 'BGS-WEFWF')
231
233
  end
232
234
 
233
235
  before do
@@ -241,153 +243,149 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
241
243
  visit spree.checkout_state_path(:payment)
242
244
  end
243
245
 
244
- it "selects first source available and customer moves on" do
245
- expect(find "#use_existing_card_yes").to be_checked
246
+ it 'selects first source available and customer moves on' do
247
+ expect(find('#use_existing_card_yes')).to be_checked
246
248
 
247
- expect {
248
- click_on "Save and Continue"
249
- }.not_to change { Spree::CreditCard.count }
249
+ expect { click_on 'Save and Continue' }.not_to change { Spree::CreditCard.count }
250
250
 
251
- click_on "Place Order"
251
+ click_on 'Place Order'
252
252
  expect(current_path).to match(spree.order_path(Spree::Order.last))
253
253
  end
254
254
 
255
- it "allows user to enter a new source" do
256
- choose "use_existing_card_no"
255
+ it 'allows user to enter a new source' do
256
+ choose 'use_existing_card_no'
257
257
 
258
- fill_in "Name on card", with: 'Spree Commerce'
259
- fill_in "Card Number", with: '4111111111111111'
260
- fill_in "card_expiry", with: '04 / 20'
261
- fill_in "Card Code", with: '123'
258
+ fill_in 'Name on card', with: 'Spree Commerce'
259
+ fill_in 'Card Number', with: '4111111111111111'
260
+ fill_in 'card_expiry', with: '04 / 20'
261
+ fill_in 'Card Code', with: '123'
262
262
 
263
- expect {
264
- click_on "Save and Continue"
265
- }.to change { Spree::CreditCard.count }.by 1
263
+ expect { click_on 'Save and Continue' }.to change { Spree::CreditCard.count }.by 1
266
264
 
267
- click_on "Place Order"
265
+ click_on 'Place Order'
268
266
  expect(current_path).to match(spree.order_path(Spree::Order.last))
269
267
  end
270
268
  end
271
269
 
272
270
  # regression for #2921
273
- context "goes back from payment to add another item", js: true do
274
- let!(:bag) { create(:product, name: "RoR Bag") }
271
+ context 'goes back from payment to add another item', js: true do
272
+ let!(:bag) { create(:product, name: 'RoR Bag') }
275
273
 
276
- it "transit nicely through checkout steps again" do
274
+ it 'transit nicely through checkout steps again' do
277
275
  add_mug_to_cart
278
- click_on "Checkout"
279
- fill_in "order_email", with: "test@example.com"
276
+ click_on 'Checkout'
277
+ fill_in 'order_email', with: 'test@example.com'
280
278
  click_on 'Continue'
281
279
  fill_in_address
282
- click_on "Save and Continue"
283
- click_on "Save and Continue"
284
- expect(current_path).to eql(spree.checkout_state_path("payment"))
280
+ click_on 'Save and Continue'
281
+ click_on 'Save and Continue'
282
+ expect(current_path).to eql(spree.checkout_state_path('payment'))
285
283
 
286
284
  visit spree.root_path
287
285
  click_link bag.name
288
- click_button "add-to-cart-button"
286
+ click_button 'add-to-cart-button'
289
287
 
290
- click_on "Checkout"
291
- click_on "Save and Continue"
292
- click_on "Save and Continue"
293
- click_on "Save and Continue"
288
+ click_on 'Checkout'
289
+ click_on 'Save and Continue'
290
+ click_on 'Save and Continue'
291
+ click_on 'Save and Continue'
294
292
 
295
293
  expect(current_path).to match(spree.order_path(Spree::Order.last))
296
294
  end
297
295
  end
298
296
 
299
- context "from payment step customer goes back to cart", js: true do
297
+ context 'from payment step customer goes back to cart', js: true do
300
298
  before do
301
299
  add_mug_to_cart
302
- click_on "Checkout"
303
- fill_in "order_email", with: "test@example.com"
300
+ click_on 'Checkout'
301
+ fill_in 'order_email', with: 'test@example.com'
304
302
  click_on 'Continue'
305
303
  fill_in_address
306
- click_on "Save and Continue"
307
- click_on "Save and Continue"
308
- expect(current_path).to eql(spree.checkout_state_path("payment"))
304
+ click_on 'Save and Continue'
305
+ click_on 'Save and Continue'
306
+ expect(current_path).to eql(spree.checkout_state_path('payment'))
309
307
  end
310
308
 
311
- context "and updates line item quantity and try to reach payment page" do
309
+ context 'and updates line item quantity and try to reach payment page' do
312
310
  before do
313
311
  visit spree.cart_path
314
- within ".cart-item-quantity" do
315
- fill_in first("input")["name"], with: 3
312
+ within '.cart-item-quantity' do
313
+ fill_in first('input')['name'], with: 3
316
314
  end
317
315
 
318
- click_on "Update"
316
+ click_on 'Update'
319
317
  end
320
318
 
321
- it "redirects user back to address step" do
322
- visit spree.checkout_state_path("payment")
323
- expect(current_path).to eql(spree.checkout_state_path("address"))
319
+ it 'redirects user back to address step' do
320
+ visit spree.checkout_state_path('payment')
321
+ expect(current_path).to eql(spree.checkout_state_path('address'))
324
322
  end
325
323
 
326
- it "updates shipments properly through step address -> delivery transitions" do
327
- visit spree.checkout_state_path("payment")
328
- click_on "Save and Continue"
329
- click_on "Save and Continue"
324
+ it 'updates shipments properly through step address -> delivery transitions' do
325
+ visit spree.checkout_state_path('payment')
326
+ click_on 'Save and Continue'
327
+ click_on 'Save and Continue'
330
328
 
331
329
  expect(Spree::InventoryUnit.count).to eq 3
332
330
  end
333
331
  end
334
332
 
335
- context "and adds new product to cart and try to reach payment page" do
336
- let!(:bag) { create(:product, name: "RoR Bag") }
333
+ context 'and adds new product to cart and try to reach payment page' do
334
+ let!(:bag) { create(:product, name: 'RoR Bag') }
337
335
 
338
336
  before do
339
337
  visit spree.root_path
340
338
  click_link bag.name
341
- click_button "add-to-cart-button"
339
+ click_button 'add-to-cart-button'
342
340
  end
343
341
 
344
- it "redirects user back to address step" do
345
- visit spree.checkout_state_path("payment")
346
- expect(current_path).to eql(spree.checkout_state_path("address"))
342
+ it 'redirects user back to address step' do
343
+ visit spree.checkout_state_path('payment')
344
+ expect(current_path).to eql(spree.checkout_state_path('address'))
347
345
  end
348
346
 
349
- it "updates shipments properly through step address -> delivery transitions" do
347
+ it 'updates shipments properly through step address -> delivery transitions' do
350
348
  visit spree.checkout_state_path("payment")
351
- click_on "Save and Continue"
352
- click_on "Save and Continue"
349
+ click_on 'Save and Continue'
350
+ click_on 'Save and Continue'
353
351
 
354
352
  expect(Spree::InventoryUnit.count).to eq 2
355
353
  end
356
354
  end
357
355
  end
358
356
 
359
- context "if coupon promotion, submits coupon along with payment", js: true do
360
- let!(:promotion) { Spree::Promotion.create(name: "Huhuhu", code: "huhu") }
361
- let!(:calculator) { Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10") }
357
+ context 'if coupon promotion, submits coupon along with payment', js: true do
358
+ let!(:promotion) { Spree::Promotion.create(name: 'Huhuhu', code: 'huhu') }
359
+ let!(:calculator) { Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: '10') }
362
360
  let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator) }
363
361
 
364
362
  before do
365
363
  promotion.actions << action
366
364
 
367
365
  add_mug_to_cart
368
- click_on "Checkout"
366
+ click_on 'Checkout'
369
367
 
370
- fill_in "order_email", with: "test@example.com"
368
+ fill_in 'order_email', with: 'test@example.com'
371
369
  click_on 'Continue'
372
370
  fill_in_address
373
- click_on "Save and Continue"
371
+ click_on 'Save and Continue'
374
372
 
375
- click_on "Save and Continue"
376
- expect(current_path).to eql(spree.checkout_state_path("payment"))
373
+ click_on 'Save and Continue'
374
+ expect(current_path).to eql(spree.checkout_state_path('payment'))
377
375
  end
378
376
 
379
- it "makes sure payment reflects order total with discounts" do
380
- fill_in "Coupon Code", with: promotion.code
381
- click_on "Save and Continue"
377
+ it 'makes sure payment reflects order total with discounts' do
378
+ fill_in 'Coupon Code', with: promotion.code
379
+ click_on 'Save and Continue'
382
380
 
383
381
  expect(page).to have_content(promotion.name)
384
382
  expect(Spree::Payment.first.amount.to_f).to eq Spree::Order.last.total.to_f
385
383
  end
386
384
 
387
- context "invalid coupon" do
388
- it "doesnt create a payment record" do
389
- fill_in "Coupon Code", with: 'invalid'
390
- click_on "Save and Continue"
385
+ context 'invalid coupon' do
386
+ it 'doesnt create a payment record' do
387
+ fill_in 'Coupon Code', with: 'invalid'
388
+ click_on 'Save and Continue'
391
389
 
392
390
  expect(Spree::Payment.count).to eq 0
393
391
  expect(page).to have_content(Spree.t(:coupon_code_not_found))
@@ -395,14 +393,14 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
395
393
  end
396
394
 
397
395
  context "doesn't fill in coupon code input" do
398
- it "advances just fine" do
399
- click_on "Save and Continue"
396
+ it 'advances just fine' do
397
+ click_on 'Save and Continue'
400
398
  expect(current_path).to match(spree.order_path(Spree::Order.last))
401
399
  end
402
400
  end
403
401
  end
404
402
 
405
- context "order has only payment step" do
403
+ context 'order has only payment step' do
406
404
  before do
407
405
  create(:credit_card_payment_method)
408
406
  @old_checkout_flow = Spree::Order.checkout_flow
@@ -413,33 +411,32 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
413
411
  end
414
412
  end
415
413
 
416
- allow_any_instance_of(Spree::Order).to receive_messages email: "spree@commerce.com"
414
+ allow_any_instance_of(Spree::Order).to receive_messages email: 'spree@commerce.com'
417
415
 
418
416
  add_mug_to_cart
419
- click_on "Checkout"
417
+ click_on 'Checkout'
420
418
  end
421
419
 
422
420
  after do
423
421
  Spree::Order.checkout_flow(&@old_checkout_flow)
424
422
  end
425
423
 
426
- it "goes right payment step and place order just fine" do
424
+ it 'goes right payment step and place order just fine' do
427
425
  expect(current_path).to eq spree.checkout_state_path('payment')
428
426
 
429
- choose "Credit Card"
430
- fill_in "Name on card", with: 'Spree Commerce'
431
- fill_in "Card Number", with: '4111111111111111'
432
- fill_in "card_expiry", with: '04 / 20'
433
- fill_in "Card Code", with: '123'
434
- click_button "Save and Continue"
427
+ choose 'Credit Card'
428
+ fill_in 'Name on card', with: 'Spree Commerce'
429
+ fill_in 'Card Number', with: '4111111111111111'
430
+ fill_in 'card_expiry', with: '04 / 20'
431
+ fill_in 'Card Code', with: '123'
432
+ click_button 'Save and Continue'
435
433
 
436
434
  expect(current_path).to eq spree.checkout_state_path('confirm')
437
- click_button "Place Order"
435
+ click_button 'Place Order'
438
436
  end
439
437
  end
440
438
 
441
-
442
- context "save my address" do
439
+ context 'save my address' do
443
440
  before do
444
441
  stock_location.stock_items.update_all(count_on_hand: 1)
445
442
  add_mug_to_cart
@@ -447,12 +444,12 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
447
444
 
448
445
  context 'as a guest' do
449
446
  before do
450
- Spree::Order.last.update_column(:email, "test@example.com")
451
- click_button "Checkout"
447
+ Spree::Order.last.update_column(:email, 'test@example.com')
448
+ click_button 'Checkout'
452
449
  end
453
450
 
454
451
  it 'should not be displayed' do
455
- expect(page).to_not have_css("[data-hook=save_user_address]")
452
+ expect(page).to_not have_css('[data-hook=save_user_address]')
456
453
  end
457
454
  end
458
455
 
@@ -462,16 +459,16 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
462
459
  Spree::Order.last.update_column :user_id, user.id
463
460
  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
464
461
  allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
465
- click_button "Checkout"
462
+ click_button 'Checkout'
466
463
  end
467
464
 
468
465
  it 'should be displayed' do
469
- expect(page).to have_css("[data-hook=save_user_address]")
466
+ expect(page).to have_css('[data-hook=save_user_address]')
470
467
  end
471
468
  end
472
469
  end
473
470
 
474
- context "when order is completed" do
471
+ context 'when order is completed' do
475
472
  let!(:user) { create(:user) }
476
473
  let!(:order) { OrderWalkthrough.up_to(:payment) }
477
474
 
@@ -481,27 +478,88 @@ describe "Checkout", type: :feature, inaccessible: true, js: true do
481
478
  allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
482
479
 
483
480
  visit spree.checkout_state_path(:payment)
484
- click_button "Save and Continue"
481
+ click_button 'Save and Continue'
485
482
  end
486
483
 
487
- it "displays a thank you message" do
484
+ it 'displays a thank you message' do
488
485
  expect(page).to have_content(Spree.t(:thank_you_for_your_order))
489
486
  end
490
487
 
491
- it "does not display a thank you message on that order future visits" do
488
+ it 'does not display a thank you message on that order future visits' do
492
489
  visit spree.order_path(order)
493
490
  expect(page).to_not have_content(Spree.t(:thank_you_for_your_order))
494
491
  end
495
492
  end
496
493
 
494
+ context 'user has store credits', js: true do
495
+ let(:bogus) { create(:credit_card_payment_method) }
496
+ let(:store_credit_payment_method) { create(:store_credit_payment_method) }
497
+ let(:user) { create(:user) }
498
+ let(:order) { OrderWalkthrough.up_to(:payment) }
499
+
500
+ let(:prepare_checkout!) do
501
+ order.update(user: user)
502
+ allow(order).to receive_messages(available_payment_methods: [bogus, store_credit_payment_method])
503
+
504
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
505
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
506
+ allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
507
+ visit spree.checkout_state_path(:payment)
508
+ end
509
+
510
+ context 'when not all Store Credits are used' do
511
+ let!(:store_credit) { create(:store_credit, user: user) }
512
+ let!(:additional_store_credit) { create(:store_credit, user: user, amount: 13) }
513
+
514
+ before { prepare_checkout! }
515
+
516
+ it 'page has data for (multiple) Store Credits' do
517
+ expect(page).to have_selector('[data-hook="checkout_payment_store_credit_available"]')
518
+ expect(page).to have_selector('button[name="apply_store_credit"]')
519
+
520
+ amount = Spree::Money.new(store_credit.amount_remaining + additional_store_credit.amount_remaining)
521
+ expect(page).to have_content(Spree.t('store_credit.available_amount', amount: amount))
522
+ end
523
+
524
+ it 'apply store credits button should move checkout to next step if amount is sufficient' do
525
+ click_button 'Apply Store Credit'
526
+ expect(current_path).to eq spree.order_path(order)
527
+ expect(page).to have_content(Spree.t('order_processed_successfully'))
528
+ end
529
+
530
+ it 'apply store credits button should wait on payment step for other payment' do
531
+ store_credit.update(amount_used: 145)
532
+ additional_store_credit.update(amount_used: 12)
533
+ click_button 'Apply Store Credit'
534
+
535
+ expect(current_path).to eq spree.checkout_state_path(:payment)
536
+ amount = Spree::Money.new(store_credit.amount_remaining + additional_store_credit.amount_remaining)
537
+ remaining_amount = Spree::Money.new(order.total - amount.money.to_f)
538
+ expect(page).to have_content(Spree.t('store_credit.applicable_amount', amount: amount))
539
+ expect(page).to have_content(Spree.t('store_credit.additional_payment_needed', amount: remaining_amount))
540
+ end
541
+ end
542
+
543
+ context 'when all Store Credits are used' do
544
+ let!(:store_credit) { create(:store_credit, user: user, amount_used: 150) }
545
+
546
+ before { prepare_checkout! }
547
+
548
+ it 'page has no data for Store Credits when all Store Credits are used' do
549
+ expect(page).to_not have_selector('[data-hook="checkout_payment_store_credit_available"]')
550
+ expect(page).to_not have_selector('button[name="apply_store_credit"]')
551
+ end
552
+ end
553
+ end
554
+
497
555
  def fill_in_address
498
556
  address = "order_bill_address_attributes"
499
557
  fill_in "#{address}_firstname", with: "Ryan"
500
558
  fill_in "#{address}_lastname", with: "Bigg"
501
559
  fill_in "#{address}_address1", with: "143 Swan Street"
502
560
  fill_in "#{address}_city", with: "Richmond"
503
- select "United States of America", from: "#{address}_country_id"
504
- select "Alabama", from: "#{address}_state_id"
561
+ select country.name, from: "#{address}_country_id"
562
+ select state.name, from: "#{address}_state_id"
505
563
  fill_in "#{address}_zipcode", with: "12345"
506
564
  fill_in "#{address}_phone", with: "(555) 555-5555"
507
565
  end