Skip to content

Commit

Permalink
Update line_item spec to create a target_shipment for destroy test
Browse files Browse the repository at this point in the history
This test is demonstrating a false passing because the OrderInventory
instance actually receives the `verify` message on being created, and
previous to this change, that would happen after the `expect_` line,
causing this test to pass despite `verify` not being received during
the `destory`. This change adds a `target_shipment` to the
`line_item`, which is needed to trigger the `verify` call.
  • Loading branch information
harmonymjb committed Jan 7, 2025
1 parent 3c25783 commit 3a39c53
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/spec/models/spree/line_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
RSpec.describe Spree::LineItem, type: :model do
let(:order) { create :order_with_line_items, line_items_count: 1 }
let(:line_item) { order.line_items.first }
let(:target_shipment) { Spree::Shipment.new }

context '#destroy' do
it "fetches soft-deleted products" do
Expand All @@ -18,7 +19,8 @@
end

it "returns inventory when a line item is destroyed" do
expect_any_instance_of(Spree::OrderInventory).to receive(:verify)
line_item.target_shipment = target_shipment
expect_any_instance_of(Spree::OrderInventory).to receive(:verify).with(target_shipment)
line_item.destroy
end

Expand All @@ -30,8 +32,8 @@
context "#save" do
context "target_shipment is provided" do
it "verifies inventory" do
line_item.target_shipment = Spree::Shipment.new
expect_any_instance_of(Spree::OrderInventory).to receive(:verify)
line_item.target_shipment = target_shipment
expect_any_instance_of(Spree::OrderInventory).to receive(:verify).with(target_shipment)
line_item.save
end
end
Expand Down

0 comments on commit 3a39c53

Please sign in to comment.