From 74fb266748046a25aba35a6db44df74242d7a332 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 20 Mar 2014 17:18:15 +1100 Subject: [PATCH] Adding some requirement filters to the Orders controller --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/shop/checkout_controller.rb | 7 ------- .../spree/orders_controller_decorator.rb | 3 +++ app/helpers/application_helper.rb | 1 + spec/controllers/spree/orders_controller_spec.rb | 13 +++++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b0cc37e9f..d2f58096e8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base before_filter :load_data_for_sidebar before_filter :require_certified_hostname + include EnterprisesHelper def after_sign_in_path_for(resource) if request.referer and referer_path = URI(request.referer).path @@ -44,6 +45,12 @@ class ApplicationController < ActionController::Base end end + def require_order_cycle + unless current_order_cycle + redirect_to main_app.shop_path + end + end + def check_order_cycle_expiry if current_order_cycle.andand.closed? session[:expired_order_cycle_id] = current_order_cycle.id diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index 5a193e392d..2e817150f5 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -1,6 +1,5 @@ class Shop::CheckoutController < Spree::CheckoutController layout 'darkswarm' - prepend_before_filter :require_order_cycle prepend_before_filter :require_distributor_chosen skip_before_filter :check_registration @@ -62,12 +61,6 @@ class Shop::CheckoutController < Spree::CheckoutController redirect_to main_app.root_path end end - - def require_order_cycle - unless current_order_cycle - redirect_to main_app.shop_path - end - end def load_order @order = current_order diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 92211bf6a6..65d1908723 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -5,6 +5,9 @@ Spree::OrdersController.class_eval do before_filter :update_distribution, :only => :update before_filter :filter_order_params, :only => :update + prepend_before_filter :require_order_cycle, only: [:edit] + prepend_before_filter :require_distributor_chosen, only: [:edit] + layout 'darkswarm' # Patch Orders#populate to populate multi_cart (if enabled) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7afe5e180b..15c20dfd55 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,7 @@ module ApplicationHelper include FoundationRailsHelper::FlashHelper + def home_page_cms_content if controller.controller_name == 'home' && controller.action_name == 'index' cms_page_content(:content, Cms::Page.find_by_full_path('/')) diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 322c4a9ef2..a9118355d6 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -1,6 +1,19 @@ require 'spec_helper' describe Spree::OrdersController do + let(:distributor) { double(:distributor) } + + it "redirects home when no distributor is selected" do + spree_get :edit + response.should redirect_to root_path + end + + it "redirects to the shop when no order cycle is selected" do + controller.stub(:current_distributor).and_return(distributor) + spree_get :edit + response.should redirect_to shop_path + end + it "selects distributors" do d = create(:distributor_enterprise) p = create(:product, :distributors => [d])