Skip to content

Commit b39a150

Browse files
Merge pull request #342 from spark-solutions/fix/spree-4-1
Fixed Specs for Spree 4.1 new UI
2 parents a8409fb + f124837 commit b39a150

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

spec/features/stripe_checkout_spec.rb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Spree::CheckoutController.any_instance.stub(:current_order => order)
3030
Spree::CheckoutController.any_instance.stub(:try_spree_current_user => user)
3131
Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)
32+
Spree::OrdersController.any_instance.stub(try_spree_current_user: user)
3233

3334
# Capybara should wait up to 10 seconds for async. changes to be applied
3435
Capybara.default_max_wait_time = 10
@@ -42,64 +43,68 @@
4243

4344
# This will pass the CC data to the server and the StripeGateway class handles it
4445
it "can process a valid payment (without JS)" do
45-
fill_in "Card Number", :with => "4242 4242 4242 4242"
46-
fill_in "Card Code", :with => "123"
47-
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
46+
fill_in 'card_number', with: '4242 4242 4242 4242'
47+
fill_in 'card_code', with: '123'
48+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
4849
click_button "Save and Continue"
4950
expect(page.current_url).to include("/checkout/confirm")
5051
click_button "Place Order"
51-
expect(page).to have_content("Your order has been processed successfully")
52+
order = Spree::Order.complete.last
53+
expect(page.current_url).to include("/orders/#{order.number}")
54+
expect(page).to have_content(order.number)
5255
end
5356

5457
# This will fetch a token from Stripe.com and then pass that to the webserver.
5558
# The server then processes the payment using that token.
5659
it "can process a valid payment (with JS)", :js => true do
57-
fill_in "Card Number", :with => "4242 4242 4242 4242"
60+
fill_in 'card_number', with: '4242 4242 4242 4242'
5861
# Otherwise ccType field does not get updated correctly
5962
page.execute_script("$('.cardNumber').trigger('change')")
60-
fill_in "Card Code", :with => "123"
61-
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
63+
fill_in 'card_code', with: '123'
64+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
6265
click_button "Save and Continue"
6366
wait_for_stripe # Wait for Stripe API to return + form to submit
6467
expect(page).to have_css('#checkout_form_confirm')
6568
expect(page.current_url).to include("/checkout/confirm")
6669
click_button "Place Order"
67-
expect(page).to have_content("Your order has been processed successfully")
70+
order = Spree::Order.complete.last
71+
expect(page.current_url).to include("/orders/#{order.number}")
72+
expect(page).to have_content(order.number)
6873
end
6974

7075
it "shows an error with an invalid credit card number", :js => true do
7176
# Card number is NOT valid. Fails Luhn checksum
72-
fill_in "Card Number", :with => "4242 4242 4242 4249"
77+
fill_in 'card_number', with: '4242 4242 4242 4249'
7378
click_button "Save and Continue"
7479
wait_for_stripe
7580
expect(page).to have_content("Your card number is incorrect")
7681
expect(page).to have_css('.has-error #card_number.error')
7782
end
7883

7984
it "shows an error with invalid security fields", :js => true do
80-
fill_in "Card Number", :with => "4242 4242 4242 4242"
81-
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
82-
fill_in "Card Code", :with => "99"
85+
fill_in 'card_number', with: '4242 4242 4242 4242'
86+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
87+
fill_in 'card_code', with: '99'
8388
click_button "Save and Continue"
8489
wait_for_stripe
8590
expect(page).to have_content("Your card's security code is invalid.")
8691
expect(page).to have_css('.has-error #card_code.error')
8792
end
8893

8994
it "shows an error with invalid expiry month field", :js => true do
90-
fill_in "Card Number", :with => "4242 4242 4242 4242"
91-
fill_in "Expiration", :with => "00 / #{Time.now.year + 1}"
92-
fill_in "Card Code", :with => "123"
95+
fill_in 'card_number', with: '4242 4242 4242 4242'
96+
fill_in 'card_expiry', :with => "00 / #{Time.now.year + 1}"
97+
fill_in 'card_code', with: '123'
9398
click_button "Save and Continue"
9499
wait_for_stripe
95100
expect(page).to have_content("Your card's expiration month is invalid.")
96101
expect(page).to have_css('.has-error #card_expiry.error')
97102
end
98103

99104
it "shows an error with invalid expiry year field", :js => true do
100-
fill_in "Card Number", :with => "4242 4242 4242 4242"
101-
fill_in "Expiration", :with => "12 / "
102-
fill_in "Card Code", :with => "123"
105+
fill_in 'card_number', with: '4242 4242 4242 4242'
106+
fill_in 'card_expiry', with: '12 / '
107+
fill_in 'card_code', with: '123'
103108
click_button "Save and Continue"
104109
wait_for_stripe
105110
expect(page).to have_content("Your card's expiration year is invalid.")

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
4949
DatabaseCleaner.start
5050
reset_spree_preferences
51+
create(:store)
5152
end
5253

5354
config.after do

0 commit comments

Comments
 (0)