Adding visibility permissions for standing orders

This commit is contained in:
Rob Harrington
2016-09-25 17:28:57 +10:00
parent cd2d73810d
commit c18c1c67d1
3 changed files with 21 additions and 3 deletions

View File

@@ -135,6 +135,13 @@ module OpenFoodNetwork
Schedule.joins(:order_cycles).where(order_cycles: { id: OrderCycle.accessible_by(@user).pluck(:id) }).select("DISTINCT schedules.*")
end
def editable_standing_orders
StandingOrder.where('standing_orders.shop_id IN (?)', managed_enterprises)
end
def visible_standing_orders
editable_standing_orders
end
private

View File

@@ -140,10 +140,10 @@ FactoryGirl.define do
factory :standing_order, :class => StandingOrder do
shop { FactoryGirl.create :enterprise }
schedule
schedule { FactoryGirl.create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)]) }
customer { create(:customer, enterprise: shop) }
payment_method
shipping_method
payment_method { create(:payment_method, distributors: [shop]) }
shipping_method { create(:shipping_method, distributors: [shop]) }
begins_at { 1.month.ago }
end

View File

@@ -394,5 +394,16 @@ module OpenFoodNetwork
end
end
end
describe "finding visible standing orders" do
let!(:so1) { create(:standing_order) }
let!(:so2) { create(:standing_order) }
it "returns standing orders placed with managed shops" do
expect(permissions).to receive(:managed_enterprises) { [so1.shop] }
expect(permissions.visible_standing_orders).to eq [so1]
end
end
end
end