Remove now useless wrapper method

This commit is contained in:
Maikel Linke
2025-01-22 11:31:27 +11:00
parent c27aa00bed
commit f098327808
3 changed files with 1 additions and 52 deletions

View File

@@ -35,16 +35,6 @@ module Spree
end
end
# This was refactored from a simpler query because the previous implementation
# lead to issues once users tried to modify the objects returned. That's due
# to ActiveRecord `joins(shipment: :stock_location)` only return readonly
# objects
#
# Returns an array of backordered inventory units as per a given stock item
def self.backordered_for_stock_item(stock_item)
backordered_per_variant(stock_item)
end
def self.finalize_units!(inventory_units)
inventory_units.map do |iu|
iu.update_columns(

View File

@@ -16,7 +16,7 @@ module Spree
delegate :name, to: :variant, prefix: true
def backordered_inventory_units
Spree::InventoryUnit.backordered_for_stock_item(self)
Spree::InventoryUnit.backordered_per_variant(self)
end
def adjust_count_on_hand(value)

View File

@@ -6,47 +6,6 @@ RSpec.describe Spree::InventoryUnit do
let!(:stock_location) { create(:stock_location_with_items) }
let(:stock_item) { Spree::StockItem.order(:id).first }
context "#backordered_for_stock_item" do
let(:order) { create(:order) }
let(:shipment) do
shipment = Spree::Shipment.new
shipment.shipping_methods << create(:shipping_method)
shipment.order = order
# We don't care about this in this test
allow(shipment).to receive(:ensure_correct_adjustment)
shipment.tap(&:save!)
end
let!(:unit) do
unit = shipment.inventory_units.build
unit.state = 'backordered'
unit.variant_id = stock_item.variant.id
unit.tap(&:save!)
end
# Regression for Spree #3066
it "returns modifiable objects" do
units = Spree::InventoryUnit.backordered_for_stock_item(stock_item)
expect { units.first.save! }.not_to raise_error
end
it "finds inventory units from its stock location " \
"when the unit's variant matches the stock item's variant" do
expect(Spree::InventoryUnit.backordered_for_stock_item(stock_item)).to eq [unit]
end
it "does not find inventory units that don't match the stock item's variant" do
other_variant_unit = shipment.inventory_units.build
other_variant_unit.state = 'backordered'
other_variant_unit.variant = create(:variant)
other_variant_unit.save!
expect(Spree::InventoryUnit.backordered_for_stock_item(stock_item))
.not_to include(other_variant_unit)
end
end
context "variants deleted" do
let!(:unit) do
Spree::InventoryUnit.create(variant: stock_item.variant)