Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix insufficient stock spec
Browse files Browse the repository at this point in the history
This has to make use of a helper method instead of a memoized
`let` now, because the object graph in the spec is otherwise different
than the one in the tested code.
mamhoff committed Mar 4, 2022
1 parent fe82039 commit e0c6c91
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frontend/spec/features/checkout_confirm_insufficient_stock_spec.rb
Original file line number Diff line number Diff line change
@@ -10,11 +10,16 @@

let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
let(:order_product) { order.products.first }
let(:order_stock_item) { order_product.stock_items.first }

# This can't be memoized now in a `let` block, otherwise we
# get a different stock item in the object graph than in the spec setup
def stock_item
order.line_items.first.variant.stock_items.first
end

before do
order_stock_item.update! backorderable: false
order_stock_item.set_count_on_hand(1)
stock_item.update! backorderable: false
stock_item.set_count_on_hand(1)
allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)
allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user)
@@ -24,7 +29,7 @@
context 'when the customer is on the confirm page and the availabilty drops to zero' do
before do
visit spree.checkout_state_path(:confirm)
order_stock_item.set_count_on_hand(0)
stock_item.set_count_on_hand(0)
end

it 'redirects to cart page and shows an unavailable product message' do
@@ -43,7 +48,7 @@
context 'when the customer is on the confirm page and the availabilty drops to zero' do
before do
visit spree.checkout_state_path(:confirm)
order_stock_item.set_count_on_hand(0)
stock_item.set_count_on_hand(0)
end

it "redirects to the address checkout page and shows an availability changed message" do

0 comments on commit e0c6c91

Please sign in to comment.