solidus_frontend 2.10.2 → 2.11.0

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.

Potentially problematic release.


This version of solidus_frontend might be problematic. Click here for more details.

Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/frontend/checkout/address.js +1 -1
  3. data/app/assets/javascripts/spree/frontend/checkout/coupon-code.js +1 -1
  4. data/app/controllers/spree/checkout_controller.rb +9 -5
  5. data/app/controllers/spree/orders_controller.rb +9 -9
  6. data/app/controllers/spree/products_controller.rb +1 -1
  7. data/app/views/spree/address/_form.html.erb +15 -8
  8. data/app/views/spree/address/_form_hidden.html.erb +6 -2
  9. data/app/views/spree/checkout/payment/_gateway.html.erb +1 -1
  10. data/app/views/spree/orders/_form.html.erb +1 -1
  11. data/app/views/spree/shared/_address.html.erb +1 -1
  12. data/app/views/spree/shared/_image.html.erb +3 -2
  13. data/solidus_frontend.gemspec +5 -5
  14. metadata +12 -55
  15. data/script/rails +0 -10
  16. data/spec/controllers/controller_helpers_spec.rb +0 -29
  17. data/spec/controllers/locale_controller_spec.rb +0 -57
  18. data/spec/controllers/spree/checkout_controller_spec.rb +0 -610
  19. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +0 -37
  20. data/spec/controllers/spree/content_controller_spec.rb +0 -9
  21. data/spec/controllers/spree/current_order_tracking_spec.rb +0 -47
  22. data/spec/controllers/spree/home_controller_spec.rb +0 -29
  23. data/spec/controllers/spree/orders_controller_ability_spec.rb +0 -90
  24. data/spec/controllers/spree/orders_controller_spec.rb +0 -254
  25. data/spec/controllers/spree/orders_controller_transitions_spec.rb +0 -33
  26. data/spec/controllers/spree/products_controller_spec.rb +0 -38
  27. data/spec/controllers/spree/taxons_controller_spec.rb +0 -14
  28. data/spec/features/address_spec.rb +0 -78
  29. data/spec/features/automatic_promotion_adjustments_spec.rb +0 -49
  30. data/spec/features/caching/products_spec.rb +0 -48
  31. data/spec/features/caching/taxons_spec.rb +0 -21
  32. data/spec/features/cart_spec.rb +0 -85
  33. data/spec/features/checkout_confirm_insufficient_stock_spec.rb +0 -71
  34. data/spec/features/checkout_spec.rb +0 -758
  35. data/spec/features/checkout_unshippable_spec.rb +0 -37
  36. data/spec/features/coupon_code_spec.rb +0 -266
  37. data/spec/features/currency_spec.rb +0 -20
  38. data/spec/features/first_order_promotion_spec.rb +0 -59
  39. data/spec/features/free_shipping_promotions_spec.rb +0 -60
  40. data/spec/features/locale_spec.rb +0 -26
  41. data/spec/features/order_spec.rb +0 -73
  42. data/spec/features/products_spec.rb +0 -291
  43. data/spec/features/promotion_code_invalidation_spec.rb +0 -54
  44. data/spec/features/quantity_promotions_spec.rb +0 -130
  45. data/spec/features/taxons_spec.rb +0 -158
  46. data/spec/features/template_rendering_spec.rb +0 -20
  47. data/spec/fixtures/thinking-cat.jpg +0 -0
  48. data/spec/generators/solidus/views/override_generator_spec.rb +0 -50
  49. data/spec/helpers/base_helper_spec.rb +0 -13
  50. data/spec/helpers/order_helper_spec.rb +0 -14
  51. data/spec/helpers/taxon_filters_helper_spec.rb +0 -12
  52. data/spec/spec_helper.rb +0 -106
  53. data/spec/support/shared_contexts/checkout_setup.rb +0 -12
  54. data/spec/support/shared_contexts/custom_products.rb +0 -28
  55. data/spec/support/shared_contexts/locales.rb +0 -16
  56. data/spec/views/spree/checkout/_summary_spec.rb +0 -11
@@ -1,610 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Spree::CheckoutController, type: :controller do
6
- let(:token) { 'some_token' }
7
- let(:user) { create(:user) }
8
- let(:order) { FactoryBot.create(:order_with_totals) }
9
-
10
- let(:address_params) do
11
- address = FactoryBot.build(:address)
12
- address.attributes.except("created_at", "updated_at")
13
- end
14
-
15
- before do
16
- allow(controller).to receive_messages try_spree_current_user: user
17
- allow(controller).to receive_messages current_order: order
18
- end
19
-
20
- context "#edit" do
21
- it 'should check if the user is authorized for :edit' do
22
- expect(controller).to receive(:authorize!).with(:edit, order, token)
23
- request.cookie_jar.signed[:guest_token] = token
24
- get :edit, params: { state: 'address' }
25
- end
26
-
27
- it "should redirect to the cart path unless checkout_allowed?" do
28
- allow(order).to receive_messages checkout_allowed?: false
29
- get :edit, params: { state: "delivery" }
30
- expect(response).to redirect_to(spree.cart_path)
31
- end
32
-
33
- it "should redirect to the cart path if current_order is nil" do
34
- allow(controller).to receive(:current_order).and_return(nil)
35
- get :edit, params: { state: "delivery" }
36
- expect(response).to redirect_to(spree.cart_path)
37
- end
38
-
39
- it "should redirect to cart if order is completed" do
40
- allow(order).to receive_messages(completed?: true)
41
- get :edit, params: { state: "address" }
42
- expect(response).to redirect_to(spree.cart_path)
43
- end
44
-
45
- # Regression test for https://github.com/spree/spree/issues/2280
46
- it "should redirect to current step trying to access a future step" do
47
- order.update_column(:state, "address")
48
- get :edit, params: { state: "delivery" }
49
- expect(response).to redirect_to spree.checkout_state_path("address")
50
- end
51
-
52
- context "when entering the checkout" do
53
- before do
54
- # The first step for checkout controller is address
55
- # Transitioning into this state first is required
56
- order.update_column(:state, "address")
57
- end
58
-
59
- it "should associate the order with a user" do
60
- order.update_column :user_id, nil
61
- expect(order).to receive(:associate_user!).with(user)
62
- get :edit
63
- end
64
- end
65
- end
66
-
67
- context "#update" do
68
- it 'should check if the user is authorized for :edit' do
69
- expect(controller).to receive(:authorize!).with(:edit, order, token)
70
- request.cookie_jar.signed[:guest_token] = token
71
- post :update, params: { state: 'address', order: { bill_address_attributes: address_params } }
72
- end
73
-
74
- context "save successful" do
75
- def post_address
76
- post :update, params: {
77
- state: "address",
78
- order: {
79
- bill_address_attributes: address_params,
80
- use_billing: true
81
- }
82
- }
83
- end
84
-
85
- let!(:payment_method) { create(:payment_method) }
86
- before do
87
- # Must have *a* shipping method and a payment method so updating from address works
88
- allow(order).to receive_messages ensure_available_shipping_rates: true
89
- order.line_items << FactoryBot.create(:line_item)
90
- end
91
-
92
- context "with the order in the cart state", partial_double_verification: false do
93
- before do
94
- order.update! user: user
95
- order.update_column(:state, "cart")
96
- end
97
-
98
- it "should assign order" do
99
- post :update, params: { state: "address", order: { bill_address_attributes: address_params } }
100
- expect(assigns[:order]).not_to be_nil
101
- end
102
-
103
- it "should advance the state" do
104
- post_address
105
- expect(order.reload.state).to eq("delivery")
106
- end
107
-
108
- it "should redirect the next state" do
109
- post_address
110
- expect(response).to redirect_to spree.checkout_state_path("delivery")
111
- end
112
-
113
- context "current_user respond to save address method" do
114
- it "calls persist order address on user" do
115
- expect(user).to receive(:persist_order_address)
116
- post :update, params: {
117
- state: "address",
118
- order: {
119
- bill_address_attributes: address_params,
120
- use_billing: true
121
- },
122
- save_user_address: "1"
123
- }
124
- end
125
- end
126
-
127
- context "current_user doesnt respond to persist_order_address" do
128
- it "doesnt raise any error" do
129
- post :update, params: {
130
- state: "address",
131
- order: {
132
- bill_address_attributes: address_params,
133
- use_billing: true
134
- },
135
- save_user_address: "1"
136
- }
137
- end
138
- end
139
- end
140
-
141
- context "with the order in the address state", partial_double_verification: false do
142
- before do
143
- order.update! user: user
144
- order.update_columns(ship_address_id: create(:address).id, state: "address")
145
- end
146
-
147
- context 'landing to address page' do
148
- it "tries to associate user addresses to order" do
149
- expect(order).to receive(:assign_default_user_addresses)
150
- get :edit
151
- end
152
- end
153
-
154
- context "with a billing and shipping address", partial_double_verification: false do
155
- subject do
156
- post :update, params: {
157
- state: "address",
158
- order: {
159
- bill_address_attributes: order.bill_address.attributes.except("created_at", "updated_at").compact,
160
- ship_address_attributes: order.ship_address.attributes.except("created_at", "updated_at").compact,
161
- use_billing: false
162
- }
163
- }
164
- end
165
-
166
- it "doesn't change bill address" do
167
- expect {
168
- subject
169
- }.not_to change { order.reload.ship_address.id }
170
- end
171
-
172
- it "doesn't change ship address" do
173
- expect {
174
- subject
175
- }.not_to change { order.reload.bill_address.id }
176
- end
177
- end
178
- end
179
-
180
- # This is the only time that we need the 'set_payment_parameters_amount'
181
- # controller code, because otherwise the transition to 'confirm' will
182
- # trigger the 'add_store_credit_payments' transition code which will do
183
- # the same thing here.
184
- # Perhaps we can just remove 'set_payment_parameters_amount' entirely at
185
- # some point?
186
- context "when there is a checkout step between payment and confirm", partial_double_verification: false do
187
- before do
188
- @old_checkout_flow = Spree::Order.checkout_flow
189
- Spree::Order.class_eval do
190
- insert_checkout_step :new_step, after: :payment
191
- end
192
- end
193
-
194
- after do
195
- Spree::Order.checkout_flow(&@old_checkout_flow)
196
- end
197
-
198
- let(:order) { create(:order_with_line_items) }
199
- let(:payment_method) { create(:credit_card_payment_method) }
200
-
201
- let(:params) do
202
- {
203
- state: 'payment',
204
- order: {
205
- payments_attributes: [
206
- {
207
- payment_method_id: payment_method.id.to_s,
208
- source_attributes: attributes_for(:credit_card)
209
- }
210
- ]
211
- }
212
- }
213
- end
214
-
215
- before do
216
- order.update! user: user
217
- 3.times { order.next! } # should put us in the payment state
218
- end
219
-
220
- it 'sets the payment amount' do
221
- post :update, params: params
222
- order.reload
223
- expect(order.state).to eq('new_step')
224
- expect(order.payments.size).to eq(1)
225
- expect(order.payments.first.amount).to eq(order.total)
226
- end
227
- end
228
-
229
- context "when in the payment state", partial_double_verification: false do
230
- let(:order) { create(:order_with_line_items) }
231
- let(:payment_method) { create(:credit_card_payment_method) }
232
-
233
- let(:params) do
234
- {
235
- state: 'payment',
236
- order: {
237
- payments_attributes: [
238
- {
239
- payment_method_id: payment_method.id.to_s,
240
- source_attributes: attributes_for(:credit_card)
241
- }
242
- ]
243
- }
244
- }
245
- end
246
-
247
- before do
248
- order.update! user: user
249
- 3.times { order.next! } # should put us in the payment state
250
- end
251
-
252
- context 'with a permitted payment method' do
253
- it 'sets the payment amount' do
254
- post :update, params: params
255
- order.reload
256
- expect(order.state).to eq('confirm')
257
- expect(order.payments.size).to eq(1)
258
- expect(order.payments.first.amount).to eq(order.total)
259
- end
260
- end
261
-
262
- context 'with an unpermitted payment method' do
263
- before { payment_method.update!(available_to_users: false) }
264
-
265
- it 'sets the payment amount' do
266
- expect {
267
- post :update, params: params
268
- }.to raise_error(ActiveRecord::RecordNotFound)
269
-
270
- expect(order.state).to eq('payment')
271
- expect(order.payments).to be_empty
272
- end
273
- end
274
-
275
- context 'trying to change the address' do
276
- let(:params) do
277
- {
278
- state: 'payment',
279
- order: {
280
- payments_attributes: [
281
- {
282
- payment_method_id: payment_method.id.to_s,
283
- source_attributes: attributes_for(:credit_card)
284
- }
285
- ],
286
- ship_address_attributes: {
287
- zipcode: 'TEST'
288
- }
289
- }
290
- }
291
- end
292
-
293
- it 'does not change the address' do
294
- expect do
295
- post :update, params: params
296
- end.not_to change { order.reload.ship_address.zipcode }
297
- end
298
- end
299
- end
300
-
301
- context "when in the confirm state" do
302
- before do
303
- order.update! user: user
304
- order.update_column(:state, "confirm")
305
- # An order requires a payment to reach the complete state
306
- # This is because payment_required? is true on the order
307
- create(:payment, amount: order.total, order: order)
308
- order.create_proposed_shipments
309
- order.payments.reload
310
- end
311
-
312
- # This inadvertently is a regression test for https://github.com/spree/spree/issues/2694
313
- it "should redirect to the order view" do
314
- post :update, params: { state: "confirm" }
315
- expect(response).to redirect_to spree.order_path(order)
316
- end
317
-
318
- it "should populate the flash message" do
319
- post :update, params: { state: "confirm" }
320
- expect(flash.notice).to eq(I18n.t('spree.order_processed_successfully'))
321
- end
322
-
323
- it "should remove completed order from current_order" do
324
- post :update, params: { state: "confirm" }
325
- expect(assigns(:current_order)).to be_nil
326
- expect(assigns(:order)).to eql controller.current_order
327
- end
328
- end
329
- end
330
-
331
- context "save unsuccessful" do
332
- before do
333
- order.update! user: user
334
- allow(order).to receive_messages valid?: false
335
- end
336
-
337
- it "should not assign order" do
338
- post :update, params: { state: "address", order: { email: ''} }
339
- expect(assigns[:order]).not_to be_nil
340
- end
341
-
342
- it "should not change the order state" do
343
- expect do
344
- post :update, params: { state: 'address', order: { bill_address_attributes: address_params } }
345
- end.not_to change { order.reload.state }
346
- end
347
-
348
- it "should render the edit template" do
349
- post :update, params: { state: 'address', order: { bill_address_attributes: address_params } }
350
- expect(response).to render_template :edit
351
- end
352
- end
353
-
354
- context "when current_order is nil" do
355
- before { allow(controller).to receive_messages current_order: nil }
356
-
357
- it "should not change the state if order is completed" do
358
- expect(order).not_to receive(:update_attribute)
359
- post :update, params: { state: "confirm" }
360
- end
361
-
362
- it "should redirect to the cart_path" do
363
- post :update, params: { state: "confirm" }
364
- expect(response).to redirect_to spree.cart_path
365
- end
366
- end
367
-
368
- context "Spree::Core::GatewayError" do
369
- before do
370
- order.update! user: user
371
- allow(order).to receive(:next).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
372
- post :update, params: { state: "address", order: { bill_address_attributes: address_params } }
373
- end
374
-
375
- it "should render the edit template and display exception message" do
376
- expect(response).to render_template :edit
377
- expect(flash.now[:error]).to eq(I18n.t('spree.spree_gateway_error_flash_for_checkout'))
378
- expect(assigns(:order).errors[:base]).to include("Invalid something or other.")
379
- end
380
- end
381
-
382
- context "fails to transition from address" do
383
- let(:order) do
384
- FactoryBot.create(:order_with_line_items).tap do |order|
385
- order.next!
386
- expect(order.state).to eq('address')
387
- end
388
- end
389
-
390
- before do
391
- allow(controller).to receive_messages current_order: order
392
- allow(controller).to receive_messages check_authorization: true
393
- end
394
-
395
- context "when the order is invalid" do
396
- before do
397
- allow(order).to receive_messages valid?: true, next: nil
398
- order.errors.add :base, 'Base error'
399
- order.errors.add :adjustments, 'error'
400
- end
401
-
402
- it "due to the order having errors" do
403
- put :update, params: { state: order.state, order: { bill_address_attributes: address_params } }
404
- expect(flash[:error]).to eq("Base error\nAdjustments error")
405
- expect(response).to redirect_to(spree.checkout_state_path('address'))
406
- end
407
- end
408
-
409
- context "when the country is not a shippable country" do
410
- let(:foreign_address) { create(:address, country_iso_code: "CA") }
411
-
412
- before do
413
- order.update(shipping_address: foreign_address)
414
- end
415
-
416
- it "due to no available shipping rates for any of the shipments" do
417
- put :update, params: { state: "address", order: { bill_address_attributes: address_params } }
418
- expect(flash[:error]).to eq(I18n.t('spree.items_cannot_be_shipped'))
419
- expect(response).to redirect_to(spree.checkout_state_path('address'))
420
- end
421
- end
422
- end
423
-
424
- context "when GatewayError is raised" do
425
- let(:order) do
426
- FactoryBot.create(:order_with_line_items).tap do |order|
427
- until order.state == 'payment'
428
- order.next!
429
- end
430
- # So that the confirmation step is skipped and we get straight to the action.
431
- payment_method = FactoryBot.create(:simple_credit_card_payment_method)
432
- payment = FactoryBot.create(:payment, payment_method: payment_method, amount: order.total)
433
- order.payments << payment
434
- order.next!
435
- end
436
- end
437
-
438
- before do
439
- allow(controller).to receive_messages current_order: order
440
- allow(controller).to receive_messages check_authorization: true
441
- end
442
-
443
- it "fails to transition from payment to complete" do
444
- allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(I18n.t('spree.payment_processing_failed')))
445
- put :update, params: { state: order.state, order: {} }
446
- expect(flash[:error]).to eq(I18n.t('spree.payment_processing_failed'))
447
- end
448
- end
449
-
450
- context "when InsufficientStock error is raised" do
451
- before do
452
- allow(controller).to receive_messages current_order: order
453
- allow(controller).to receive_messages check_authorization: true
454
- allow(controller).to receive_messages ensure_sufficient_stock_lines: true
455
- end
456
-
457
- context "when the order has no shipments" do
458
- let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:address) }
459
-
460
- before do
461
- allow(order).to receive_messages shipments: []
462
- # Order#next is the tipical failure point here:
463
- allow(order).to receive(:next).and_raise(Spree::Order::InsufficientStock)
464
- end
465
-
466
- it "redirects the customer to the cart page with an error message" do
467
- put :update, params: { state: order.state, order: { bill_address_attributes: address_params } }
468
- expect(flash[:error]).to eq(I18n.t('spree.insufficient_stock_for_order'))
469
- expect(response).to redirect_to(spree.cart_path)
470
- end
471
- end
472
-
473
- context "when the order has shipments" do
474
- let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
475
-
476
- context "when items become somehow not available anymore" do
477
- before { Spree::StockItem.update_all backorderable: false }
478
-
479
- it "redirects the customer to the address checkout page with an error message" do
480
- put :update, params: { state: order.state, order: {} }
481
- error = I18n.t('spree.inventory_error_flash_for_insufficient_shipment_quantity', unavailable_items: order.products.first.name)
482
- expect(flash[:error]).to eq(error)
483
- expect(response).to redirect_to(spree.checkout_state_path(state: :address))
484
- end
485
- end
486
- end
487
- end
488
- end
489
-
490
- context "When last inventory item has been purchased" do
491
- let(:product) { mock_model(Spree::Product, name: "Amazing Object") }
492
- let(:variant) { mock_model(Spree::Variant) }
493
- let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true, amount: 0, name: "Amazing Item" }
494
- let(:order) { create(:order) }
495
-
496
- before do
497
- allow(order).to receive_messages(line_items: [line_item], state: "payment")
498
-
499
- stub_spree_preferences(track_inventory_levels: true)
500
- end
501
-
502
- context "and back orders are not allowed" do
503
- before do
504
- post :update, params: { state: "payment" }
505
- end
506
-
507
- it "should redirect to cart" do
508
- expect(response).to redirect_to spree.cart_path
509
- end
510
-
511
- it "should set flash message for no inventory" do
512
- expect(flash[:error]).to eq("Amazing Item became unavailable.")
513
- end
514
- end
515
- end
516
-
517
- context "order doesn't have a delivery step" do
518
- before do
519
- allow(order).to receive_messages(checkout_steps: ["cart", "address", "payment"])
520
- allow(order).to receive_messages state: "address"
521
- allow(controller).to receive_messages check_authorization: true
522
- end
523
-
524
- # This does not test whether the shipping address is set via params.
525
- # It only tests whether it is set in the before action.
526
- it "doesn't set a default shipping address on the order" do
527
- expect(order).to_not receive(:ship_address=)
528
- post :update, params: { state: order.state, order: { bill_address_attributes: address_params } }
529
- end
530
-
531
- it "doesn't remove unshippable items before payment" do
532
- expect {
533
- post :update, params: { state: "payment" }
534
- }.to_not change { order.line_items }
535
- end
536
- end
537
-
538
- it "does remove unshippable items before payment" do
539
- allow(order).to receive_messages payment_required?: true
540
- allow(controller).to receive_messages check_authorization: true
541
-
542
- expect {
543
- post :update, params: { state: "payment", order: { email: "johndoe@example.com"} }
544
- }.to change { order.line_items.to_a.size }.from(1).to(0)
545
- end
546
-
547
- context 'trying to apply a coupon code' do
548
- let(:order) { create(:order_with_line_items, state: 'payment', guest_token: 'a token') }
549
- let(:coupon_code) { "coupon_code" }
550
-
551
- before { cookies.signed[:guest_token] = order.guest_token }
552
-
553
- context "when coupon code is empty" do
554
- let(:coupon_code) { "" }
555
-
556
- it 'does not try to apply coupon code' do
557
- expect(Spree::PromotionHandler::Coupon).not_to receive :new
558
-
559
- put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
560
-
561
- expect(response).to redirect_to(spree.checkout_state_path('confirm'))
562
- end
563
- end
564
-
565
- context "when coupon code is applied" do
566
- let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') }
567
-
568
- it "continues checkout flow normally" do
569
- expect(Spree::Deprecation).to receive(:warn)
570
-
571
- expect(Spree::PromotionHandler::Coupon)
572
- .to receive_message_chain(:new, :apply)
573
- .and_return(promotion_handler)
574
-
575
- put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
576
-
577
- expect(response).to render_template :edit
578
- expect(flash.now[:success]).to eq('Coupon Applied!')
579
- end
580
-
581
- context "when coupon code is not applied" do
582
- let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) }
583
-
584
- it "setups the current step correctly before rendering" do
585
- expect(Spree::Deprecation).to receive(:warn)
586
-
587
- expect(Spree::PromotionHandler::Coupon)
588
- .to receive_message_chain(:new, :apply)
589
- .and_return(promotion_handler)
590
- expect(controller).to receive(:setup_for_current_state)
591
-
592
- put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
593
- end
594
-
595
- it "render cart with coupon error" do
596
- expect(Spree::Deprecation).to receive(:warn)
597
-
598
- expect(Spree::PromotionHandler::Coupon)
599
- .to receive_message_chain(:new, :apply)
600
- .and_return(promotion_handler)
601
-
602
- put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
603
-
604
- expect(response).to render_template :edit
605
- expect(flash.now[:error]).to eq('Some error')
606
- end
607
- end
608
- end
609
- end
610
- end