solidus_frontend 1.0.7 → 1.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/frontend/checkout/address.js.coffee +6 -5
  3. data/app/controllers/spree/checkout_controller.rb +5 -3
  4. data/app/controllers/spree/store_controller.rb +2 -1
  5. data/app/views/spree/address/_form.html.erb +15 -15
  6. data/lib/spree/frontend.rb +0 -2
  7. metadata +9 -79
  8. data/CHANGELOG.md +0 -1
  9. data/Gemfile +0 -6
  10. data/Rakefile +0 -15
  11. data/lib/spree/frontend/preference_rescue.rb +0 -25
  12. data/script/rails +0 -9
  13. data/solidus_frontend.gemspec +0 -30
  14. data/spec/controllers/controller_extension_spec.rb +0 -126
  15. data/spec/controllers/controller_helpers_spec.rb +0 -26
  16. data/spec/controllers/spree/checkout_controller_spec.rb +0 -447
  17. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +0 -36
  18. data/spec/controllers/spree/content_controller_spec.rb +0 -7
  19. data/spec/controllers/spree/current_order_tracking_spec.rb +0 -44
  20. data/spec/controllers/spree/home_controller_spec.rb +0 -27
  21. data/spec/controllers/spree/orders_controller_ability_spec.rb +0 -104
  22. data/spec/controllers/spree/orders_controller_spec.rb +0 -134
  23. data/spec/controllers/spree/orders_controller_transitions_spec.rb +0 -31
  24. data/spec/controllers/spree/products_controller_spec.rb +0 -36
  25. data/spec/controllers/spree/taxons_controller_spec.rb +0 -12
  26. data/spec/features/address_spec.rb +0 -76
  27. data/spec/features/automatic_promotion_adjustments_spec.rb +0 -47
  28. data/spec/features/caching/products_spec.rb +0 -55
  29. data/spec/features/caching/taxons_spec.rb +0 -22
  30. data/spec/features/cart_spec.rb +0 -81
  31. data/spec/features/checkout_spec.rb +0 -513
  32. data/spec/features/checkout_unshippable_spec.rb +0 -35
  33. data/spec/features/coupon_code_spec.rb +0 -227
  34. data/spec/features/currency_spec.rb +0 -18
  35. data/spec/features/free_shipping_promotions_spec.rb +0 -59
  36. data/spec/features/locale_spec.rb +0 -60
  37. data/spec/features/order_spec.rb +0 -73
  38. data/spec/features/products_spec.rb +0 -260
  39. data/spec/features/promotion_code_invalidation_spec.rb +0 -51
  40. data/spec/features/quantity_promotions_spec.rb +0 -128
  41. data/spec/features/taxons_spec.rb +0 -135
  42. data/spec/features/template_rendering_spec.rb +0 -19
  43. data/spec/fixtures/thinking-cat.jpg +0 -0
  44. data/spec/helpers/base_helper_spec.rb +0 -11
  45. data/spec/spec_helper.rb +0 -121
  46. data/spec/support/shared_contexts/checkout_setup.rb +0 -9
  47. data/spec/support/shared_contexts/custom_products.rb +0 -25
  48. data/spec/support/shared_contexts/product_prototypes.rb +0 -30
  49. data/spec/views/spree/checkout/_summary_spec.rb +0 -11
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Automatic promotions", :type => :feature, :js => true do
4
- let!(:country) { create(:country, :name => "United States of America", :states_required => true) }
5
- let!(:state) { create(:state, :name => "Alabama", :country => country) }
6
- let!(:zone) { create(:zone) }
7
- let!(:shipping_method) { create(:shipping_method) }
8
- let!(:payment_method) { create(:check_payment_method) }
9
- let!(:product) { create(:product, :name => "RoR Mug", :price => 20) }
10
-
11
- let!(:promotion) do
12
- promotion = Spree::Promotion.create!(:name => "$10 off when you spend more than $100")
13
-
14
- calculator = Spree::Calculator::FlatRate.new
15
- calculator.preferred_amount = 10
16
-
17
- rule = Spree::Promotion::Rules::ItemTotal.create
18
- rule.preferred_amount = 100
19
- rule.save
20
-
21
- promotion.rules << rule
22
-
23
- action = Spree::Promotion::Actions::CreateAdjustment.create
24
- action.calculator = calculator
25
- action.save
26
-
27
- promotion.actions << action
28
- end
29
-
30
- context "on the cart page" do
31
-
32
- before do
33
- visit spree.root_path
34
- click_link product.name
35
- click_button "add-to-cart-button"
36
- end
37
-
38
- it "automatically applies the promotion once the order crosses the threshold" do
39
- fill_in "order_line_items_attributes_0_quantity", :with => 10
40
- click_button "Update"
41
- expect(page).to have_content("Promotion ($10 off when you spend more than $100) -$10.00")
42
- fill_in "order_line_items_attributes_0_quantity", :with => 1
43
- click_button "Update"
44
- expect(page).not_to have_content("Promotion ($10 off when you spend more than $100) -$10.00")
45
- end
46
- end
47
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'products', :type => :feature, :caching => true do
4
- let!(:product) { create(:product) }
5
- let!(:product2) { create(:product) }
6
- let!(:taxonomy) { create(:taxonomy) }
7
- let!(:taxon) { create(:taxon, :taxonomy => taxonomy) }
8
-
9
- before do
10
- product2.update_column(:updated_at, 1.day.ago)
11
- # warm up the cache
12
- visit spree.root_path
13
- assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
14
- assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
15
- assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
16
- assert_written_to_cache("views/en/taxons/#{taxon.updated_at.utc.to_i}")
17
-
18
- clear_cache_events
19
- end
20
-
21
- it "reads from cache upon a second viewing" do
22
- visit spree.root_path
23
- expect(cache_writes.count).to eq(0)
24
- end
25
-
26
- it "busts the cache when a product is updated" do
27
- product.update_column(:updated_at, 1.day.from_now)
28
- visit spree.root_path
29
- assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
30
- assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
31
- expect(cache_writes.count).to eq(2)
32
- end
33
-
34
- it "busts the cache when all products are deleted" do
35
- product.destroy
36
- product2.destroy
37
- visit spree.root_path
38
- assert_written_to_cache("views/en/USD/spree/products/all--#{Date.today.to_s(:number)}-0")
39
- expect(cache_writes.count).to eq(1)
40
- end
41
-
42
- it "busts the cache when the newest product is deleted" do
43
- product.destroy
44
- visit spree.root_path
45
- assert_written_to_cache("views/en/USD/spree/products/all--#{product2.updated_at.utc.to_s(:number)}")
46
- expect(cache_writes.count).to eq(1)
47
- end
48
-
49
- it "busts the cache when an older product is deleted" do
50
- product2.destroy
51
- visit spree.root_path
52
- assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
53
- expect(cache_writes.count).to eq(1)
54
- end
55
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'taxons', :type => :feature, :caching => true do
4
- let!(:taxonomy) { create(:taxonomy) }
5
- let!(:taxon) { create(:taxon, :taxonomy => taxonomy) }
6
-
7
- before do
8
- # warm up the cache
9
- visit spree.root_path
10
- assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
11
- assert_written_to_cache("views/en/taxons/#{taxon.updated_at.utc.to_i}")
12
-
13
- clear_cache_events
14
- end
15
-
16
- it "busts the cache when max_level_in_taxons_menu conf changes" do
17
- Spree::Config[:max_level_in_taxons_menu] = 5
18
- visit spree.root_path
19
- assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
20
- expect(cache_writes.count).to eq(1)
21
- end
22
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Cart", type: :feature, inaccessible: true do
4
- it "shows cart icon on non-cart pages" do
5
- visit spree.root_path
6
- expect(page).to have_selector("li#link-to-cart a", :visible => true)
7
- end
8
-
9
- it "prevents double clicking the remove button on cart", :js => true do
10
- @product = create(:product, :name => "RoR Mug")
11
-
12
- visit spree.root_path
13
- click_link "RoR Mug"
14
- click_button "add-to-cart-button"
15
-
16
- # prevent form submit to verify button is disabled
17
- page.execute_script("$('#update-cart').submit(function(){return false;})")
18
-
19
- expect(page).not_to have_selector('button#update-button[disabled]')
20
- page.find(:css, '.delete img').click
21
- expect(page).to have_selector('button#update-button[disabled]')
22
- end
23
-
24
- # Regression test for #2006
25
- it "does not error out with a 404 when GET'ing to /orders/populate" do
26
- visit '/orders/populate'
27
- within(".error") do
28
- expect(page).to have_content(Spree.t(:populate_get_error))
29
- end
30
- end
31
-
32
- it 'allows you to remove an item from the cart', :js => true do
33
- create(:product, :name => "RoR Mug")
34
- visit spree.root_path
35
- click_link "RoR Mug"
36
- click_button "add-to-cart-button"
37
- find('.cart-item-delete .delete').click
38
- expect(page).not_to have_content("Line items quantity must be an integer")
39
- expect(page).not_to have_content("RoR Mug")
40
- expect(page).to have_content("Your cart is empty")
41
-
42
- within "#link-to-cart" do
43
- expect(page).to have_content("EMPTY")
44
- end
45
- end
46
-
47
- it 'allows you to empty the cart', js: true do
48
- create(:product, :name => "RoR Mug")
49
- visit spree.root_path
50
- click_link "RoR Mug"
51
- click_button "add-to-cart-button"
52
-
53
- expect(page).to have_content("RoR Mug")
54
- click_on "Empty Cart"
55
- expect(page).to have_content("Your cart is empty")
56
-
57
- within "#link-to-cart" do
58
- expect(page).to have_content("EMPTY")
59
- end
60
- end
61
-
62
- # regression for #2276
63
- context "product contains variants but no option values" do
64
- let(:variant) { create(:variant) }
65
- let(:product) { variant.product }
66
-
67
- before { variant.option_values.destroy_all }
68
-
69
- it "still adds product to cart", inaccessible: true do
70
- visit spree.product_path(product)
71
- click_button "add-to-cart-button"
72
-
73
- visit spree.cart_path
74
- expect(page).to have_content(product.name)
75
- end
76
- end
77
- it "should have a surrounding element with data-hook='cart_container'" do
78
- visit spree.cart_path
79
- expect(page).to have_selector("div[data-hook='cart_container']")
80
- end
81
- end
@@ -1,513 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Checkout", type: :feature, inaccessible: true do
4
-
5
- include_context 'checkout setup'
6
-
7
- context "visitor makes checkout as guest without registration" do
8
- before(:each) do
9
- stock_location.stock_items.update_all(count_on_hand: 1)
10
- end
11
-
12
- context "defaults to use billing address" do
13
- before do
14
- add_mug_to_cart
15
- Spree::Order.last.update_column(:email, "test@example.com")
16
- click_button "Checkout"
17
- end
18
-
19
- it "should default checkbox to checked", inaccessible: true do
20
- expect(find('input#order_use_billing')).to be_checked
21
- end
22
-
23
- it "should remain checked when used and visitor steps back to address step", :js => true do
24
- fill_in_address
25
- expect(find('input#order_use_billing')).to be_checked
26
- end
27
- end
28
-
29
- # Regression test for #4079
30
- context "persists state when on address page" do
31
- before do
32
- add_mug_to_cart
33
- click_button "Checkout"
34
- end
35
-
36
- specify do
37
- expect(Spree::Order.count).to eq(1)
38
- expect(Spree::Order.last.state).to eq("address")
39
- end
40
- end
41
-
42
- # Regression test for #1596
43
- context "full checkout" do
44
- before do
45
- shipping_method.calculator.update!(preferred_amount: 10)
46
- mug.shipping_category = shipping_method.shipping_categories.first
47
- mug.save!
48
- end
49
-
50
- it "does not break the per-item shipping method calculator", :js => true do
51
- add_mug_to_cart
52
- click_button "Checkout"
53
-
54
- fill_in "order_email", :with => "test@example.com"
55
- fill_in_address
56
-
57
- click_button "Save and Continue"
58
- expect(page).not_to have_content("undefined method `promotion'")
59
- click_button "Save and Continue"
60
- expect(page).to have_content("Shipping total: $10.00")
61
- end
62
- end
63
-
64
- # Regression test for #4306
65
- context "free shipping" do
66
- before do
67
- add_mug_to_cart
68
- click_button "Checkout"
69
- end
70
-
71
- it "should not show 'Free Shipping' when there are no shipments" do
72
- within("#checkout-summary") do
73
- expect(page).to_not have_content('Free Shipping')
74
- end
75
- end
76
- end
77
- end
78
-
79
- # Regression test for #2694 and #4117
80
- context "doesn't allow bad credit card numbers" do
81
- let!(:payment_method) { create(:credit_card_payment_method) }
82
- before(:each) do
83
- order = OrderWalkthrough.up_to(:delivery)
84
-
85
- user = create(:user)
86
- order.user = user
87
- order.update!
88
-
89
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
90
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
91
- end
92
-
93
- it "redirects to payment page", inaccessible: true do
94
- visit spree.checkout_state_path(:delivery)
95
- click_button "Save and Continue"
96
- choose "Credit Card"
97
- fill_in "Card Number", :with => '123'
98
- fill_in "card_expiry", :with => '04 / 20'
99
- fill_in "Card Code", :with => '123'
100
- click_button "Save and Continue"
101
- click_button "Place Order"
102
- expect(page).to have_content("Bogus Gateway: Forced failure")
103
- expect(page.current_url).to include("/checkout/payment")
104
- end
105
- end
106
-
107
- context "and likes to double click buttons" do
108
- let!(:user) { create(:user) }
109
-
110
- let!(:order) do
111
- order = OrderWalkthrough.up_to(:delivery)
112
- allow(order).to receive_messages :confirmation_required? => true
113
-
114
- order.reload
115
- order.user = user
116
- order.update!
117
- order
118
- end
119
-
120
- before(:each) do
121
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
122
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
123
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:skip_state_validation? => true)
124
- end
125
-
126
- it "prevents double clicking the payment button on checkout", :js => true do
127
- visit spree.checkout_state_path(:payment)
128
-
129
- # prevent form submit to verify button is disabled
130
- page.execute_script("$('#checkout_form_payment').submit(function(){return false;})")
131
-
132
- expect(page).not_to have_selector('input.button[disabled]')
133
- click_button "Save and Continue"
134
- expect(page).to have_selector('input.button[disabled]')
135
- end
136
-
137
- it "prevents double clicking the confirm button on checkout", :js => true do
138
- order.payments << create(:payment)
139
- visit spree.checkout_state_path(:confirm)
140
-
141
- # prevent form submit to verify button is disabled
142
- page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
143
-
144
- expect(page).not_to have_selector('input.button[disabled]')
145
- click_button "Place Order"
146
- expect(page).to have_selector('input.button[disabled]')
147
- end
148
- end
149
-
150
- context "when several payment methods are available" do
151
- let(:credit_cart_payment) {create(:credit_card_payment_method, :environment => 'test') }
152
- let(:check_payment) {create(:check_payment_method, :environment => 'test') }
153
-
154
- after do
155
- Capybara.ignore_hidden_elements = true
156
- end
157
-
158
- before do
159
- Capybara.ignore_hidden_elements = false
160
- order = OrderWalkthrough.up_to(:delivery)
161
- allow(order).to receive_messages(:available_payment_methods => [check_payment,credit_cart_payment])
162
- order.user = create(:user)
163
- order.update!
164
-
165
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
166
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: order.user)
167
-
168
- visit spree.checkout_state_path(:payment)
169
- end
170
-
171
- it "the first payment method should be selected", :js => true do
172
- payment_method_css = "#order_payments_attributes__payment_method_id_"
173
- expect(find("#{payment_method_css}#{check_payment.id}")).to be_checked
174
- expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_checked
175
- end
176
-
177
- it "the fields for the other payment methods should be hidden", :js => true do
178
- payment_method_css = "#payment_method_"
179
- expect(find("#{payment_method_css}#{check_payment.id}")).to be_visible
180
- expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_visible
181
- end
182
- end
183
-
184
- context "user has payment sources", js: true do
185
- before { Spree::PaymentMethod.all.each(&:really_destroy!) }
186
- let!(:bogus) { create(:credit_card_payment_method) }
187
- let(:user) { create(:user) }
188
-
189
- let!(:credit_card) do
190
- create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: "BGS-WEFWF")
191
- end
192
-
193
- before do
194
- order = OrderWalkthrough.up_to(:delivery)
195
-
196
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
197
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
198
- allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
199
-
200
- visit spree.checkout_state_path(:payment)
201
- end
202
-
203
- it "selects first source available and customer moves on" do
204
- expect(find "#use_existing_card_yes").to be_checked
205
-
206
- expect {
207
- click_on "Save and Continue"
208
- }.not_to change { Spree::CreditCard.count }
209
-
210
- click_on "Place Order"
211
- expect(current_path).to eql(spree.order_path(Spree::Order.last))
212
- end
213
-
214
- it "allows user to enter a new source" do
215
- choose "use_existing_card_no"
216
-
217
- fill_in "Name on card", :with => 'Spree Commerce'
218
- fill_in "Card Number", :with => '4111111111111111'
219
- fill_in "card_expiry", :with => '04 / 20'
220
- fill_in "Card Code", :with => '123'
221
-
222
- expect {
223
- click_on "Save and Continue"
224
- }.to change { Spree::CreditCard.count }.by 1
225
-
226
- expect(Spree::CreditCard.last.address).to be_present
227
-
228
- click_on "Place Order"
229
- expect(current_path).to eql(spree.order_path(Spree::Order.last))
230
- end
231
- end
232
-
233
- # regression for #2921
234
- context "goes back from payment to add another item", js: true do
235
- let!(:store) { FactoryGirl.create(:store) }
236
- let!(:bag) { create(:product, :name => "RoR Bag") }
237
-
238
- it "transit nicely through checkout steps again" do
239
- add_mug_to_cart
240
- click_on "Checkout"
241
- fill_in "order_email", :with => "test@example.com"
242
- fill_in_address
243
- click_on "Save and Continue"
244
- click_on "Save and Continue"
245
- expect(current_path).to eql(spree.checkout_state_path("payment"))
246
-
247
- visit spree.root_path
248
- click_link bag.name
249
- click_button "add-to-cart-button"
250
-
251
- click_on "Checkout"
252
- click_on "Save and Continue"
253
- click_on "Save and Continue"
254
- click_on "Save and Continue"
255
- click_on "Place Order"
256
-
257
- expect(current_path).to eql(spree.order_path(Spree::Order.last))
258
- end
259
- end
260
-
261
- context "from payment step customer goes back to cart", js: true do
262
- before do
263
- add_mug_to_cart
264
- click_on "Checkout"
265
- fill_in "order_email", :with => "test@example.com"
266
- fill_in_address
267
- click_on "Save and Continue"
268
- click_on "Save and Continue"
269
- expect(current_path).to eql(spree.checkout_state_path("payment"))
270
- end
271
-
272
- context "and updates line item quantity and try to reach payment page" do
273
- before do
274
- visit spree.cart_path
275
- within ".cart-item-quantity" do
276
- fill_in first("input")["name"], with: 3
277
- end
278
-
279
- click_on "Update"
280
- end
281
-
282
- it "redirects user back to address step" do
283
- visit spree.checkout_state_path("payment")
284
- expect(current_path).to eql(spree.checkout_state_path("address"))
285
- end
286
-
287
- it "updates shipments properly through step address -> delivery transitions" do
288
- visit spree.checkout_state_path("payment")
289
- click_on "Save and Continue"
290
- click_on "Save and Continue"
291
-
292
- expect(Spree::InventoryUnit.count).to eq 3
293
- end
294
- end
295
-
296
- context "and adds new product to cart and try to reach payment page" do
297
- let!(:bag) { create(:product, :name => "RoR Bag") }
298
-
299
- before do
300
- visit spree.root_path
301
- click_link bag.name
302
- click_button "add-to-cart-button"
303
- end
304
-
305
- it "redirects user back to address step" do
306
- visit spree.checkout_state_path("payment")
307
- expect(current_path).to eql(spree.checkout_state_path("address"))
308
- end
309
-
310
- it "updates shipments properly through step address -> delivery transitions" do
311
- visit spree.checkout_state_path("payment")
312
- click_on "Save and Continue"
313
- click_on "Save and Continue"
314
-
315
- expect(Spree::InventoryUnit.count).to eq 2
316
- end
317
- end
318
- end
319
-
320
- context "in coupon promotion, submits coupon along with payment", js: true do
321
- let!(:promotion) { create(:promotion, name: "Huhuhu", code: "huhu") }
322
- let!(:calculator) { Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10") }
323
- let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator) }
324
-
325
- before do
326
- promotion.actions << action
327
-
328
- add_mug_to_cart
329
- click_on "Checkout"
330
-
331
- fill_in "order_email", :with => "test@example.com"
332
- fill_in_address
333
- click_on "Save and Continue"
334
-
335
- click_on "Save and Continue"
336
- expect(current_path).to eql(spree.checkout_state_path("payment"))
337
- end
338
-
339
- it "makes sure payment reflects order total with discounts" do
340
- fill_in "Coupon Code", with: promotion.codes.first.value
341
- click_on "Save and Continue"
342
-
343
- expect(page).to have_content(promotion.name)
344
- expect(Spree::Payment.first.amount.to_f).to eq Spree::Order.last.total.to_f
345
- end
346
-
347
- context "invalid coupon" do
348
- it "doesnt create a payment record" do
349
- fill_in "Coupon Code", with: 'invalid'
350
- click_on "Save and Continue"
351
-
352
- expect(Spree::Payment.count).to eq 0
353
- expect(page).to have_content(Spree.t(:coupon_code_not_found))
354
- end
355
- end
356
-
357
- context "doesn't fill in coupon code input" do
358
- it "advances just fine" do
359
- click_on "Save and Continue"
360
- expect(current_path).to eql(spree.checkout_state_path("confirm"))
361
- end
362
- end
363
- end
364
-
365
- context "order has only payment step" do
366
- before do
367
- create(:credit_card_payment_method)
368
- @old_checkout_flow = Spree::Order.checkout_flow
369
- Spree::Order.class_eval do
370
- checkout_flow do
371
- go_to_state :payment
372
- go_to_state :confirm
373
- end
374
- end
375
-
376
- allow_any_instance_of(Spree::Order).to receive_messages email: "spree@commerce.com"
377
-
378
- add_mug_to_cart
379
- click_on "Checkout"
380
- end
381
-
382
- after do
383
- Spree::Order.checkout_flow(&@old_checkout_flow)
384
- end
385
-
386
- it "goes right payment step and place order just fine" do
387
- expect(current_path).to eq spree.checkout_state_path('payment')
388
-
389
- choose "Credit Card"
390
- fill_in "Name on card", :with => 'Spree Commerce'
391
- fill_in "Card Number", :with => '4111111111111111'
392
- fill_in "card_expiry", :with => '04 / 20'
393
- fill_in "Card Code", :with => '123'
394
- click_button "Save and Continue"
395
-
396
- expect(current_path).to eq spree.checkout_state_path('confirm')
397
- click_button "Place Order"
398
- end
399
- end
400
-
401
-
402
- context "save my address" do
403
- before do
404
- stock_location.stock_items.update_all(count_on_hand: 1)
405
- add_mug_to_cart
406
- end
407
-
408
- context 'as a guest' do
409
- before do
410
- Spree::Order.last.update_column(:email, "test@example.com")
411
- click_button "Checkout"
412
- end
413
-
414
- it 'should not be displayed' do
415
- expect(page).to_not have_css("[data-hook=save_user_address]")
416
- end
417
- end
418
-
419
- context 'as a User' do
420
- before do
421
- user = create(:user)
422
- Spree::Order.last.update_column :user_id, user.id
423
- allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
424
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
425
- click_button "Checkout"
426
- end
427
-
428
- it 'should be displayed' do
429
- expect(page).to have_css("[data-hook=save_user_address]")
430
- end
431
- end
432
- end
433
-
434
- context "when order is completed" do
435
- let!(:user) { create(:user) }
436
- let!(:order) { OrderWalkthrough.up_to(:delivery) }
437
-
438
- before(:each) do
439
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
440
- allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
441
- allow_any_instance_of(Spree::OrdersController).to receive_messages(:try_spree_current_user => user)
442
-
443
- visit spree.checkout_state_path(:delivery)
444
- click_button "Save and Continue"
445
- click_button "Save and Continue"
446
- click_button "Place Order"
447
- end
448
-
449
- it "displays a thank you message" do
450
- expect(page).to have_content(Spree.t(:thank_you_for_your_order))
451
- end
452
-
453
- it "does not display a thank you message on that order future visits" do
454
- visit spree.order_path(order)
455
- expect(page).to_not have_content(Spree.t(:thank_you_for_your_order))
456
- end
457
- end
458
-
459
- context "with attempted XSS", js: true do
460
- shared_examples "safe from XSS" do
461
- # We need a country with states required but no states so that we have
462
- # access to the state_name input
463
- let!(:canada) { create(:country, name: 'Canada', iso: "CA", states_required: true) }
464
- before do
465
- canada.states.destroy_all
466
- zone.members.create!(zoneable: canada)
467
- end
468
-
469
- it "displays the entered state name without evaluating" do
470
- add_mug_to_cart
471
- visit spree.checkout_state_path(:address)
472
- fill_in_address
473
-
474
- state_name_css = "order_bill_address_attributes_state_name"
475
-
476
- select "Canada", from: "order_bill_address_attributes_country_id"
477
- fill_in state_name_css, with: xss_string
478
- fill_in "Zip", with: "H0H0H0"
479
-
480
- click_on 'Save and Continue'
481
- visit spree.checkout_state_path(:address)
482
-
483
- expect(page).to have_field(state_name_css, with: xss_string)
484
- end
485
- end
486
-
487
- let(:xss_string) { %(<script>throw("XSS")</script>) }
488
- include_examples "safe from XSS"
489
-
490
- context "escaped XSS string" do
491
- let(:xss_string) { '\x27\x3e\x3cscript\x3ethrow(\x27XSS\x27)\x3c/script\x3e' }
492
- include_examples "safe from XSS"
493
- end
494
- end
495
-
496
- def fill_in_address
497
- address = "order_bill_address_attributes"
498
- fill_in "#{address}_firstname", with: "Ryan"
499
- fill_in "#{address}_lastname", with: "Bigg"
500
- fill_in "#{address}_address1", with: "143 Swan Street"
501
- fill_in "#{address}_city", with: "Richmond"
502
- select "United States of America", from: "#{address}_country_id"
503
- select "Alabama", from: "#{address}_state_id"
504
- fill_in "#{address}_zipcode", with: "12345"
505
- fill_in "#{address}_phone", with: "(555) 555-5555"
506
- end
507
-
508
- def add_mug_to_cart
509
- visit spree.root_path
510
- click_link mug.name
511
- click_button "add-to-cart-button"
512
- end
513
- end