Find all producers for which we can create variant overrides

This commit is contained in:
Rohan Mitchell
2015-02-04 10:13:35 +11:00
parent 4c586d1b7e
commit a7bb04b890
2 changed files with 18 additions and 0 deletions

View File

@@ -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, ...], ...}

View File

@@ -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) }