Skip to content

Commit

Permalink
Dont lazy load variants in Shipment manifest
Browse files Browse the repository at this point in the history
Rails 4.0.1 fixes an issue where `default_scope` would not be applied to
`joins` association, see rails/rails@b407839
(I liked that bug pretty much myself). Side effect is users upgrading to
Rails 4.0.1 would see errors when displaying orders with deleted variants
  • Loading branch information
huoxito committed Oct 22, 2013
1 parent d36374e commit 4e8ba75
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def editable_by?(user)
end

def manifest
inventory_units.joins(:variant).includes(:variant).group_by(&:variant).map do |variant, units|
inventory_units.group_by(&:variant).map do |variant, units|
states = {}
units.group_by(&:state).each { |state, iu| states[state] = iu.count }
OpenStruct.new(variant: variant, quantity: units.length, states: states)
Expand Down
1 change: 1 addition & 0 deletions core/spec/models/spree/inventory_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
end

it "can still fetch variants by eager loading (remove default_scope)" do
pending "find a way to remove default scope when eager loading associations"
unit.variant.destroy
expect(Spree::InventoryUnit.joins(:variant).includes(:variant).first.variant).to be_a Spree::Variant
end
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
end

it 'restocks the items' do
shipment.stub_chain(:inventory_units, :joins, includes: [mock_model(Spree::InventoryUnit, variant: variant)])
shipment.stub_chain(inventory_units: [mock_model(Spree::InventoryUnit, variant: variant)])
shipment.stock_location = mock_model(Spree::StockLocation)
shipment.stock_location.should_receive(:restock).with(variant, 1, shipment)
shipment.after_cancel
Expand All @@ -265,7 +265,7 @@
end

it 'unstocks them items' do
shipment.stub_chain(:inventory_units, :joins, includes: [mock_model(Spree::InventoryUnit, variant: variant)])
shipment.stub_chain(inventory_units: [mock_model(Spree::InventoryUnit, variant: variant)])
shipment.stock_location = mock_model(Spree::StockLocation)
shipment.stock_location.should_receive(:unstock).with(variant, 1, shipment)
shipment.after_resume
Expand Down

0 comments on commit 4e8ba75

Please sign in to comment.