diff --git a/app/controllers/admin/standing_orders_controller.rb b/app/controllers/admin/standing_orders_controller.rb index 73219a49c6..51d207de90 100644 --- a/app/controllers/admin/standing_orders_controller.rb +++ b/app/controllers/admin/standing_orders_controller.rb @@ -3,6 +3,7 @@ require 'open_food_network/permissions' module Admin class StandingOrdersController < ResourceController before_filter :load_shop, only: [:new] + before_filter :load_shops, only: [:index] before_filter :wrap_sli_attrs, only: [:create] respond_to :json @@ -50,6 +51,10 @@ module Admin @shop = Enterprise.find(params[:shop_id]) end + def load_shops + @shops = Enterprise.managed_by(spree_current_user).is_distributor + end + def json_errors @object.errors.messages.inject({}) do |errors, (k,v)| errors[k] = v.map{ |msg| @object.errors.full_message(k,msg) } diff --git a/spec/controllers/admin/standing_orders_controller_spec.rb b/spec/controllers/admin/standing_orders_controller_spec.rb index 14816863c9..dc8ee09b3b 100644 --- a/spec/controllers/admin/standing_orders_controller_spec.rb +++ b/spec/controllers/admin/standing_orders_controller_spec.rb @@ -25,10 +25,11 @@ describe Admin::StandingOrdersController, type: :controller do context 'as an enterprise user' do before { shop.update_attributes(owner: user) } - it 'renders the index page without loading any data' do + it 'renders the index page with appropriate data' do spree_get :index, params expect(response).to render_template 'index' - expect(assigns(:collection)).to eq [] + expect(assigns(:collection)).to eq [] # No collection loaded + expect(assigns(:shops)).to eq [shop] # Shops are loaded end end end