mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Find all producers for which we can create variant overrides
This commit is contained in:
@@ -20,6 +20,11 @@ module OpenFoodNetwork
|
||||
managed_and_related_enterprises_with :edit_profile
|
||||
end
|
||||
|
||||
def variant_override_producers
|
||||
producer_ids = variant_override_enterprises_per_hub.values.flatten.uniq
|
||||
Enterprise.where(id: producer_ids)
|
||||
end
|
||||
|
||||
# For every hub that an admin manages, show all the producers for which that hub may
|
||||
# override variants
|
||||
# {hub1_id => [producer1_id, producer2_id, ...], ...}
|
||||
|
||||
@@ -34,6 +34,19 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding all producers for which we can create variant overrides" do
|
||||
let(:e1) { create(:supplier_enterprise) }
|
||||
let(:e2) { create(:supplier_enterprise) }
|
||||
|
||||
it "compiles the list from variant_override_enterprises_per_hub" do
|
||||
permissions.stub(:variant_override_enterprises_per_hub) do
|
||||
{1 => [e1.id], 2 => [e1.id, e2.id]}
|
||||
end
|
||||
|
||||
permissions.variant_override_producers.sort.should == [e1, e2].sort
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding enterprises for which variant overrides can be created, for each hub" do
|
||||
let!(:hub) { create(:distributor_enterprise) }
|
||||
let!(:producer) { create(:supplier_enterprise) }
|
||||
|
||||
Reference in New Issue
Block a user