Add Permissions#editable_enterprises

This commit is contained in:
Rohan Mitchell
2015-01-14 11:02:38 +11:00
parent a93a824b83
commit cfb69ae7d2
2 changed files with 18 additions and 0 deletions

View File

@@ -15,6 +15,11 @@ module OpenFoodNetwork
managed_and_related_enterprises_with :add_to_order_cycle
end
# Find enterprises for which an admin is allowed to edit their profile
def editable_enterprises
managed_and_related_enterprises_with :edit_profile
end
# For every hub that an admin manages, show all the producers that that hub may add
# to the order cycle
# {hub1_id => [producer1_id, producer2_id, ...], ...}

View File

@@ -21,6 +21,19 @@ module OpenFoodNetwork
end
end
describe "finding enterprises whose profiles can be edited" do
let(:e) { double(:enterprise) }
it "returns managed and related enterprises with edit_profile permission" do
permissions.
should_receive(:managed_and_related_enterprises_with).
with(:edit_profile).
and_return([e])
permissions.editable_enterprises.should == [e]
end
end
describe "finding enterprises that can be added to an order cycle, for each hub" do
let!(:hub) { create(:distributor_enterprise) }
let!(:producer) { create(:supplier_enterprise) }