Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/app/models/spree/stock/inventory_unit_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize(order)
end

def units
ActiveRecord::Associations::Preloader.new(records: @order.line_items, associations: {variant: :product}).call
@order.line_items.flat_map do |line_item|
build_units(line_item, line_item.quantity)
end
Expand Down
10 changes: 10 additions & 0 deletions core/spec/models/spree/stock/inventory_unit_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ module Stock
it "builds the inventory units as pending" do
expect(subject.units.map(&:pending).uniq).to eq [true]
end

context "with multiple line items" do
Comment thread
ikraamg marked this conversation as resolved.
let(:order) { create(:order_with_line_items, line_items_count: 3) }

before { order.reload }

it "loads line item variants in a single query" do
Comment thread
ikraamg marked this conversation as resolved.
expect { described_class.new(order).units }.to make_database_queries(matching: /from .spree_variants..*\bid. IN \(/im, count: 1)
Comment thread
ikraamg marked this conversation as resolved.
end
end
end

describe "#missing_units_for_line_item" do
Expand Down
Loading