mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Do not return duplicates with Spree::Property.sold_by
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user