mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Working scopes for child variant and master variants
This commit is contained in:
@@ -39,5 +39,14 @@ module OpenFoodNetwork
|
||||
.joins(:product)
|
||||
.merge(Spree::Product.managed_by(@user))
|
||||
end
|
||||
|
||||
def master_variants
|
||||
Spree::Variant.where(:is_master => true)
|
||||
.joins(:product)
|
||||
.where("(select spree_variants.id from spree_variants as other_spree_variants
|
||||
WHERE other_spree_variants.product_id = spree_variants.product_id
|
||||
AND other_spree_variants.is_master = 'f' LIMIT 1) IS NULL")
|
||||
.merge(Spree::Product.managed_by(@user))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -73,6 +73,22 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching master variants" do
|
||||
it "should only return variants managed by the user" do
|
||||
product1 = create(:simple_product, supplier: create(:supplier_enterprise))
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
|
||||
subject.master_variants.should == [product2.master]
|
||||
end
|
||||
|
||||
it "doesn't return master variants with siblings" do
|
||||
product = create(:simple_product, supplier: supplier)
|
||||
create(:variant, product: product)
|
||||
|
||||
subject.master_variants.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "should fetch variants"
|
||||
|
||||
Reference in New Issue
Block a user