solidus_frontend 1.1.0 → 1.1.1

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/Rakefile +15 -0
  4. data/script/rails +9 -0
  5. data/solidus_frontend.gemspec +28 -0
  6. data/spec/controllers/controller_extension_spec.rb +126 -0
  7. data/spec/controllers/controller_helpers_spec.rb +26 -0
  8. data/spec/controllers/spree/checkout_controller_spec.rb +400 -0
  9. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
  10. data/spec/controllers/spree/content_controller_spec.rb +7 -0
  11. data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
  12. data/spec/controllers/spree/home_controller_spec.rb +27 -0
  13. data/spec/controllers/spree/orders_controller_ability_spec.rb +104 -0
  14. data/spec/controllers/spree/orders_controller_spec.rb +134 -0
  15. data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
  16. data/spec/controllers/spree/products_controller_spec.rb +36 -0
  17. data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
  18. data/spec/features/address_spec.rb +76 -0
  19. data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
  20. data/spec/features/caching/products_spec.rb +55 -0
  21. data/spec/features/caching/taxons_spec.rb +22 -0
  22. data/spec/features/cart_spec.rb +81 -0
  23. data/spec/features/checkout_spec.rb +477 -0
  24. data/spec/features/checkout_unshippable_spec.rb +36 -0
  25. data/spec/features/coupon_code_spec.rb +227 -0
  26. data/spec/features/currency_spec.rb +18 -0
  27. data/spec/features/free_shipping_promotions_spec.rb +59 -0
  28. data/spec/features/locale_spec.rb +60 -0
  29. data/spec/features/order_spec.rb +73 -0
  30. data/spec/features/products_spec.rb +260 -0
  31. data/spec/features/promotion_code_invalidation_spec.rb +51 -0
  32. data/spec/features/quantity_promotions_spec.rb +128 -0
  33. data/spec/features/taxons_spec.rb +135 -0
  34. data/spec/features/template_rendering_spec.rb +19 -0
  35. data/spec/fixtures/thinking-cat.jpg +0 -0
  36. data/spec/helpers/base_helper_spec.rb +11 -0
  37. data/spec/spec_helper.rb +129 -0
  38. data/spec/support/shared_contexts/checkout_setup.rb +9 -0
  39. data/spec/support/shared_contexts/custom_products.rb +25 -0
  40. data/spec/support/shared_contexts/product_prototypes.rb +30 -0
  41. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  42. metadata +46 -6
@@ -0,0 +1,47 @@
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", apply_automatically: true)
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
@@ -0,0 +1,55 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,81 @@
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
@@ -0,0 +1,477 @@
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
+ before(:each) do
82
+ order = OrderWalkthrough.up_to(:delivery)
83
+ allow(order).to receive_messages(:available_payment_methods => [ create(:credit_card_payment_method) ])
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
+
113
+ order.reload
114
+ order.user = user
115
+ order.update!
116
+ order
117
+ end
118
+
119
+ before(:each) do
120
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
121
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
122
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:skip_state_validation? => true)
123
+ end
124
+
125
+ it "prevents double clicking the payment button on checkout", :js => true do
126
+ visit spree.checkout_state_path(:payment)
127
+
128
+ # prevent form submit to verify button is disabled
129
+ page.execute_script("$('#checkout_form_payment').submit(function(){return false;})")
130
+
131
+ expect(page).not_to have_selector('input.button[disabled]')
132
+ click_button "Save and Continue"
133
+ expect(page).to have_selector('input.button[disabled]')
134
+ end
135
+
136
+ it "prevents double clicking the confirm button on checkout", :js => true do
137
+ order.payments << create(:payment)
138
+ visit spree.checkout_state_path(:confirm)
139
+
140
+ # prevent form submit to verify button is disabled
141
+ page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
142
+
143
+ expect(page).not_to have_selector('input.button[disabled]')
144
+ click_button "Place Order"
145
+ expect(page).to have_selector('input.button[disabled]')
146
+ end
147
+ end
148
+
149
+ context "when several payment methods are available" do
150
+ let(:credit_cart_payment) {create(:credit_card_payment_method) }
151
+ let(:check_payment) {create(:check_payment_method) }
152
+
153
+ after do
154
+ Capybara.ignore_hidden_elements = true
155
+ end
156
+
157
+ before do
158
+ Capybara.ignore_hidden_elements = false
159
+ order = OrderWalkthrough.up_to(:delivery)
160
+ allow(order).to receive_messages(:available_payment_methods => [check_payment,credit_cart_payment])
161
+ order.user = create(:user)
162
+ order.update!
163
+
164
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
165
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: order.user)
166
+
167
+ visit spree.checkout_state_path(:payment)
168
+ end
169
+
170
+ it "the first payment method should be selected", :js => true do
171
+ payment_method_css = "#order_payments_attributes__payment_method_id_"
172
+ expect(find("#{payment_method_css}#{check_payment.id}")).to be_checked
173
+ expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_checked
174
+ end
175
+
176
+ it "the fields for the other payment methods should be hidden", :js => true do
177
+ payment_method_css = "#payment_method_"
178
+ expect(find("#{payment_method_css}#{check_payment.id}")).to be_visible
179
+ expect(find("#{payment_method_css}#{credit_cart_payment.id}")).not_to be_visible
180
+ end
181
+ end
182
+
183
+ context "user has payment sources", js: true do
184
+ let(:bogus) { create(:credit_card_payment_method) }
185
+ let(:user) { create(:user) }
186
+
187
+ let!(:credit_card) do
188
+ create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: "BGS-WEFWF")
189
+ end
190
+
191
+ before do
192
+ order = OrderWalkthrough.up_to(:delivery)
193
+ allow(order).to receive_messages(:available_payment_methods => [bogus])
194
+
195
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
196
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
197
+ allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
198
+
199
+ visit spree.checkout_state_path(:payment)
200
+ end
201
+
202
+ it "selects first source available and customer moves on" do
203
+ expect(find "#use_existing_card_yes").to be_checked
204
+
205
+ expect {
206
+ click_on "Save and Continue"
207
+ }.not_to change { Spree::CreditCard.count }
208
+
209
+ click_on "Place Order"
210
+ expect(current_path).to eql(spree.order_path(Spree::Order.last))
211
+ end
212
+
213
+ it "allows user to enter a new source" do
214
+ choose "use_existing_card_no"
215
+
216
+ fill_in "Name on card", :with => 'Spree Commerce'
217
+ fill_in "Card Number", :with => '4111111111111111'
218
+ fill_in "card_expiry", :with => '04 / 20'
219
+ fill_in "Card Code", :with => '123'
220
+
221
+ expect {
222
+ click_on "Save and Continue"
223
+ }.to change { Spree::CreditCard.count }.by 1
224
+
225
+ expect(Spree::CreditCard.last.address).to be_present
226
+
227
+ click_on "Place Order"
228
+ expect(current_path).to eql(spree.order_path(Spree::Order.last))
229
+ end
230
+ end
231
+
232
+ # regression for #2921
233
+ context "goes back from payment to add another item", js: true do
234
+ let!(:store) { FactoryGirl.create(:store) }
235
+ let!(:bag) { create(:product, :name => "RoR Bag") }
236
+
237
+ it "transit nicely through checkout steps again" do
238
+ add_mug_to_cart
239
+ click_on "Checkout"
240
+ fill_in "order_email", :with => "test@example.com"
241
+ fill_in_address
242
+ click_on "Save and Continue"
243
+ click_on "Save and Continue"
244
+ expect(current_path).to eql(spree.checkout_state_path("payment"))
245
+
246
+ visit spree.root_path
247
+ click_link bag.name
248
+ click_button "add-to-cart-button"
249
+
250
+ click_on "Checkout"
251
+ # edit an address field
252
+ fill_in "order_bill_address_attributes_firstname", :with => "Ryann"
253
+ click_on "Save and Continue"
254
+ click_on "Save and Continue"
255
+ click_on "Save and Continue"
256
+ click_on "Place Order"
257
+
258
+ expect(current_path).to eql(spree.order_path(Spree::Order.last))
259
+ end
260
+ end
261
+
262
+ context "from payment step customer goes back to cart", js: true do
263
+ before do
264
+ add_mug_to_cart
265
+ click_on "Checkout"
266
+ fill_in "order_email", :with => "test@example.com"
267
+ fill_in_address
268
+ click_on "Save and Continue"
269
+ click_on "Save and Continue"
270
+ expect(current_path).to eql(spree.checkout_state_path("payment"))
271
+ end
272
+
273
+ context "and updates line item quantity and try to reach payment page" do
274
+ before do
275
+ visit spree.cart_path
276
+ within ".cart-item-quantity" do
277
+ fill_in first("input")["name"], with: 3
278
+ end
279
+
280
+ click_on "Update"
281
+ end
282
+
283
+ it "redirects user back to address step" do
284
+ visit spree.checkout_state_path("payment")
285
+ expect(current_path).to eql(spree.checkout_state_path("address"))
286
+ end
287
+
288
+ it "updates shipments properly through step address -> delivery transitions" do
289
+ visit spree.checkout_state_path("payment")
290
+ click_on "Save and Continue"
291
+ click_on "Save and Continue"
292
+
293
+ expect(Spree::InventoryUnit.count).to eq 3
294
+ end
295
+ end
296
+
297
+ context "and adds new product to cart and try to reach payment page" do
298
+ let!(:bag) { create(:product, :name => "RoR Bag") }
299
+
300
+ before do
301
+ visit spree.root_path
302
+ click_link bag.name
303
+ click_button "add-to-cart-button"
304
+ end
305
+
306
+ it "redirects user back to address step" do
307
+ visit spree.checkout_state_path("payment")
308
+ expect(current_path).to eql(spree.checkout_state_path("address"))
309
+ end
310
+
311
+ it "updates shipments properly through step address -> delivery transitions" do
312
+ visit spree.checkout_state_path("payment")
313
+ click_on "Save and Continue"
314
+ click_on "Save and Continue"
315
+
316
+ expect(Spree::InventoryUnit.count).to eq 2
317
+ end
318
+ end
319
+ end
320
+
321
+ context "in coupon promotion, submits coupon along with payment", js: true do
322
+ let!(:promotion) { create(:promotion, name: "Huhuhu", code: "huhu") }
323
+ let!(:calculator) { Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10") }
324
+ let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator) }
325
+
326
+ before do
327
+ promotion.actions << action
328
+
329
+ add_mug_to_cart
330
+ click_on "Checkout"
331
+
332
+ fill_in "order_email", :with => "test@example.com"
333
+ fill_in_address
334
+ click_on "Save and Continue"
335
+
336
+ click_on "Save and Continue"
337
+ expect(current_path).to eql(spree.checkout_state_path("payment"))
338
+ end
339
+
340
+ it "makes sure payment reflects order total with discounts" do
341
+ fill_in "Coupon Code", with: promotion.codes.first.value
342
+ click_on "Save and Continue"
343
+
344
+ expect(page).to have_content(promotion.name)
345
+ expect(Spree::Payment.first.amount.to_f).to eq Spree::Order.last.total.to_f
346
+ end
347
+
348
+ context "invalid coupon" do
349
+ it "doesnt create a payment record" do
350
+ fill_in "Coupon Code", with: 'invalid'
351
+ click_on "Save and Continue"
352
+
353
+ expect(Spree::Payment.count).to eq 0
354
+ expect(page).to have_content(Spree.t(:coupon_code_not_found))
355
+ end
356
+ end
357
+
358
+ context "doesn't fill in coupon code input" do
359
+ it "advances just fine" do
360
+ click_on "Save and Continue"
361
+ expect(current_path).to eql(spree.checkout_state_path("confirm"))
362
+ end
363
+ end
364
+ end
365
+
366
+ context "order has only payment step" do
367
+ before do
368
+ create(:credit_card_payment_method)
369
+ @old_checkout_flow = Spree::Order.checkout_flow
370
+ Spree::Order.class_eval do
371
+ checkout_flow do
372
+ go_to_state :payment
373
+ go_to_state :confirm
374
+ end
375
+ end
376
+
377
+ allow_any_instance_of(Spree::Order).to receive_messages email: "spree@commerce.com"
378
+
379
+ add_mug_to_cart
380
+ click_on "Checkout"
381
+ end
382
+
383
+ after do
384
+ Spree::Order.checkout_flow(&@old_checkout_flow)
385
+ end
386
+
387
+ it "goes right payment step and place order just fine" do
388
+ expect(current_path).to eq spree.checkout_state_path('payment')
389
+
390
+ choose "Credit Card"
391
+ fill_in "Name on card", :with => 'Spree Commerce'
392
+ fill_in "Card Number", :with => '4111111111111111'
393
+ fill_in "card_expiry", :with => '04 / 20'
394
+ fill_in "Card Code", :with => '123'
395
+ click_button "Save and Continue"
396
+
397
+ expect(current_path).to eq spree.checkout_state_path('confirm')
398
+ click_button "Place Order"
399
+ end
400
+ end
401
+
402
+
403
+ context "save my address" do
404
+ before do
405
+ stock_location.stock_items.update_all(count_on_hand: 1)
406
+ add_mug_to_cart
407
+ end
408
+
409
+ context 'as a guest' do
410
+ before do
411
+ Spree::Order.last.update_column(:email, "test@example.com")
412
+ click_button "Checkout"
413
+ end
414
+
415
+ it 'should not be displayed' do
416
+ expect(page).to_not have_css("[data-hook=save_user_address]")
417
+ end
418
+ end
419
+
420
+ context 'as a User' do
421
+ before do
422
+ user = create(:user)
423
+ Spree::Order.last.update_column :user_id, user.id
424
+ allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
425
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
426
+ click_button "Checkout"
427
+ end
428
+
429
+ it 'should be displayed' do
430
+ expect(page).to have_css("[data-hook=save_user_address]")
431
+ end
432
+ end
433
+ end
434
+
435
+ context "when order is completed" do
436
+ let!(:user) { create(:user) }
437
+ let!(:order) { OrderWalkthrough.up_to(:delivery) }
438
+
439
+ before(:each) do
440
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
441
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
442
+ allow_any_instance_of(Spree::OrdersController).to receive_messages(:try_spree_current_user => user)
443
+
444
+ visit spree.checkout_state_path(:delivery)
445
+ click_button "Save and Continue"
446
+ click_button "Save and Continue"
447
+ click_button "Place Order"
448
+ end
449
+
450
+ it "displays a thank you message" do
451
+ expect(page).to have_content(Spree.t(:thank_you_for_your_order))
452
+ end
453
+
454
+ it "does not display a thank you message on that order future visits" do
455
+ visit spree.order_path(order)
456
+ expect(page).to_not have_content(Spree.t(:thank_you_for_your_order))
457
+ end
458
+ end
459
+
460
+ def fill_in_address
461
+ address = "order_bill_address_attributes"
462
+ fill_in "#{address}_firstname", with: "Ryan"
463
+ fill_in "#{address}_lastname", with: "Bigg"
464
+ fill_in "#{address}_address1", with: "143 Swan Street"
465
+ fill_in "#{address}_city", with: "Richmond"
466
+ select "United States of America", from: "#{address}_country_id"
467
+ select "Alabama", from: "#{address}_state_id"
468
+ fill_in "#{address}_zipcode", with: "12345"
469
+ fill_in "#{address}_phone", with: "(555) 555-5555"
470
+ end
471
+
472
+ def add_mug_to_cart
473
+ visit spree.root_path
474
+ click_link mug.name
475
+ click_button "add-to-cart-button"
476
+ end
477
+ end