mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Redirect if distributor not chosen
This commit is contained in:
@@ -27,6 +27,14 @@ class ApplicationController < ActionController::Base
|
||||
@total_distributors = Enterprise.is_distributor.distinct_count
|
||||
end
|
||||
|
||||
def require_distributor_chosen
|
||||
unless current_order(false).andand.distributor
|
||||
redirect_to spree.root_path
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# All render calls within the block will be performed with the specified format
|
||||
# Useful for rendering html within a JSON response, particularly if the specified
|
||||
# template or partial then goes on to render further partials without specifying
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
include Spree::ProductsHelper
|
||||
include OrderCyclesHelper
|
||||
|
||||
class EnterprisesController < BaseController
|
||||
include Spree::ProductsHelper
|
||||
include OrderCyclesHelper
|
||||
|
||||
before_filter :require_distributor_chosen, only: :show
|
||||
|
||||
def index
|
||||
@enterprises = Enterprise.all
|
||||
|
||||
@@ -5,6 +5,8 @@ Spree::ProductsController.class_eval do
|
||||
include OrderCyclesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistribution
|
||||
|
||||
before_filter :require_distributor_chosen, only: [:index, :show]
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
if current_order_cycle
|
||||
order_cycle_products = current_order_cycle.products
|
||||
|
||||
@@ -5,6 +5,8 @@ Spree::TaxonsController.class_eval do
|
||||
include OrderCyclesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistribution
|
||||
|
||||
before_filter :require_distributor_chosen, only: :show
|
||||
|
||||
respond_override :show => { :html => { :success => lambda {
|
||||
@products, @products_local, @products_remote = split_products_by_distribution @products, current_distributor, current_order_cycle
|
||||
} } }
|
||||
|
||||
@@ -10,7 +10,7 @@ describe EnterprisesController do
|
||||
assigns(:suppliers).should == [s]
|
||||
end
|
||||
|
||||
context 'shopping for a distributor' do
|
||||
context "shopping for a distributor" do
|
||||
|
||||
before(:each) do
|
||||
@current_distributor = create(:distributor_enterprise)
|
||||
@@ -60,4 +60,12 @@ describe EnterprisesController do
|
||||
controller.current_order.order_cycle.should == @order_cycle1
|
||||
end
|
||||
end
|
||||
|
||||
context "when a distributor has not been chosen" do
|
||||
it "redirects #show to distributor selection" do
|
||||
@distributor = create(:distributor_enterprise)
|
||||
spree_get :show, {id: @distributor}
|
||||
response.should redirect_to spree.root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
spec/controllers/spree/products_controller_spec.rb
Normal file
16
spec/controllers/spree/products_controller_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::ProductsController do
|
||||
context "when a distributor has not been chosen" do
|
||||
it "redirects #index to distributor selection" do
|
||||
spree_get :index
|
||||
response.should redirect_to spree.root_path
|
||||
end
|
||||
|
||||
it "redirects #show to distributor selection" do
|
||||
product = create(:simple_product)
|
||||
spree_get :show, {id: product.permalink}
|
||||
response.should redirect_to spree.root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
11
spec/controllers/spree/taxons_controller_spec.rb
Normal file
11
spec/controllers/spree/taxons_controller_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::TaxonsController do
|
||||
context "when a distributor has not been chosen" do
|
||||
it "redirects #show to distributor selection" do
|
||||
taxon = create(:taxon)
|
||||
spree_get :show, {id: taxon.permalink}
|
||||
response.should redirect_to spree.root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user