From b5cfc5444c95158be360fec601ed866daa45000e Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Fri, 20 Apr 2018 15:37:07 +0200 Subject: [PATCH] Replace `uniq` with `distinct` for cartons association Spree::Shipment#cartons should return a carton collection --- core/app/models/spree/shipment.rb | 2 +- core/spec/models/spree/shipment_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 388b8836ec1..67203f8e9c0 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -12,7 +12,7 @@ class Shipment < Spree::Base has_many :shipping_rates, -> { order(:cost) }, dependent: :destroy, inverse_of: :shipment has_many :shipping_methods, through: :shipping_rates has_many :state_changes, as: :stateful - has_many :cartons, -> { uniq }, through: :inventory_units + has_many :cartons, -> { distinct }, through: :inventory_units before_validation :set_cost_zero_when_nil diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 4cc6911b9bb..6057955ffd5 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -895,4 +895,13 @@ end end end + + describe '#cartons' do + let(:carton) { create(:carton) } + let(:shipment) { carton.shipments.first } + + subject { shipment.cartons } + + it { is_expected.to include carton } + end end