Improve ShippingMethod -> Shipment association

5a54a0b6b0
This commit is contained in:
Matt-Yorkley
2020-12-08 18:32:22 +00:00
parent f33c881503
commit 2a0f132b8b
2 changed files with 15 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ module Spree
default_scope -> { where(deleted_at: nil) }
has_many :shipments
has_many :shipments, through: :shipping_rates
has_many :shipping_method_categories
has_many :shipping_categories, through: :shipping_method_categories
has_many :shipping_rates, inverse_of: :shipping_method

View File

@@ -176,5 +176,19 @@ module Spree
expect(shipping_method.calculator.calculable).to eq(shipping_method)
end
end
# Regression test for Spree #4492
context "#shipments" do
let!(:shipping_method) { create(:shipping_method) }
let!(:shipment) do
shipment = create(:shipment)
shipment.shipping_rates.create!(shipping_method: shipping_method)
shipment
end
it "can gather all the related shipments" do
expect(shipping_method.shipments).to include(shipment)
end
end
end
end