Do not return duplicates with Spree::Property.sold_by

This commit is contained in:
Rohan Mitchell
2016-08-19 09:48:12 +10:00
parent 4529ced3f2
commit aa6e7cba30
2 changed files with 15 additions and 1 deletions

View File

@@ -10,7 +10,8 @@ module Spree
joins(products: {variants: {exchanges: :order_cycle}}).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
merge(OrderCycle.active)
merge(OrderCycle.active).
select('DISTINCT spree_properties.*')
}
after_save :refresh_products_cache

View File

@@ -68,6 +68,19 @@ module Spree
it "doesn't return the property from a closed order cycle" do
expect(Property.sold_by(shop)).not_to include property_closed_oc
end
context "with another product in the order cycle" do
let!(:product2) { create(:simple_product) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first, product2.variants.first]) }
before do
product2.set_property 'Organic', 'NASAA 12345'
end
it "doesn't return duplicates" do
expect(Property.sold_by(shop).to_a.count).to eq 1
end
end
end
end