Skip to content

Commit

Permalink
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.
  • Loading branch information
mamhoff committed Mar 16, 2022
1 parent e69353c commit 1b2cf01
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
Expand Up @@ -10,11 +10,16 @@

let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment, user: user) }
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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1b2cf01

Please sign in to comment.