diff --git a/app/models/spree/inventory_unit.rb b/app/models/spree/inventory_unit.rb index 0f66dbb8dd..6240883659 100644 --- a/app/models/spree/inventory_unit.rb +++ b/app/models/spree/inventory_unit.rb @@ -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( diff --git a/app/models/spree/stock_item.rb b/app/models/spree/stock_item.rb index 4879d13354..db236f7ecf 100644 --- a/app/models/spree/stock_item.rb +++ b/app/models/spree/stock_item.rb @@ -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) diff --git a/spec/models/spree/inventory_unit_spec.rb b/spec/models/spree/inventory_unit_spec.rb index 3c1f620191..9d4053ad18 100644 --- a/spec/models/spree/inventory_unit_spec.rb +++ b/spec/models/spree/inventory_unit_spec.rb @@ -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)