From fdbb274667d44f2535042c29fa944af85d1b0380 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 5 Nov 2014 14:29:36 +1100 Subject: [PATCH] Allow browsing products (but not cart/checkout) for hubs that are not ready for checkout --- app/controllers/base_controller.rb | 1 - .../spree/orders_controller_decorator.rb | 5 +++-- spec/controllers/base_controller_spec.rb | 13 ------------- spec/controllers/checkout_controller_spec.rb | 14 ++++++++++++++ spec/controllers/spree/orders_controller_spec.rb | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index fbb5d44784..88c0f89aec 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -10,7 +10,6 @@ class BaseController < ApplicationController # include Spree::ProductsHelper so that method is available on the controller include Spree::ProductsHelper - before_filter :check_hub_ready_for_checkout before_filter :check_order_cycle_expiry def load_active_distributors diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index e9245b4a32..a1b468ae2d 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -5,8 +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] + prepend_before_filter :require_order_cycle, only: :edit + prepend_before_filter :require_distributor_chosen, only: :edit + before_filter :check_hub_ready_for_checkout, only: :edit include OrderCyclesHelper layout 'darkswarm' diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb index b340112ce2..822da57ba5 100644 --- a/spec/controllers/base_controller_spec.rb +++ b/spec/controllers/base_controller_spec.rb @@ -25,19 +25,6 @@ describe BaseController do flash[:info].should == "The order cycle you've selected has just closed. Please try again!" end - it "redirects to home with message if hub is not ready for checkout" do - hub.stub(:ready_for_checkout?) { false } - controller.stub(:current_order).and_return(order) - - order.should_receive(:empty!) - order.should_receive(:set_distribution!).with(nil, nil) - - get :index - - response.should redirect_to root_url - flash[:info].should == "The hub you have selected is temporarily closed for orders. Please try again later." - end - it "loads active_distributors" do Enterprise.stub_chain(:distributors_with_active_order_cycles, :ready_for_checkout) { 'active distributors' } controller.load_active_distributors.should == 'active distributors' diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 86e9689aa2..dcbd1d5177 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -20,6 +20,20 @@ describe CheckoutController do response.should redirect_to shop_path end + it "redirects home with message if hub is not ready for checkout" do + distributor.stub(:ready_for_checkout?) { false } + order.stub(distributor: distributor, order_cycle: order_cycle) + controller.stub(:current_order).and_return(order) + + order.should_receive(:empty!) + order.should_receive(:set_distribution!).with(nil, nil) + + get :edit + + response.should redirect_to root_url + flash[:info].should == "The hub you have selected is temporarily closed for orders. Please try again later." + end + it "redirects to the shop when no line items are present" do controller.stub(:current_distributor).and_return(distributor) controller.stub(:current_order_cycle).and_return(order_cycle) diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 354ebb8701..1d2f41f86c 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -26,6 +26,20 @@ describe Spree::OrdersController do response.should redirect_to shop_path end + it "redirects home with message if hub is not ready for checkout" do + order = subject.current_order(true) + distributor.stub(:ready_for_checkout?) { false } + order.stub(distributor: distributor, order_cycle: order_cycle) + + order.should_receive(:empty!) + order.should_receive(:set_distribution!).with(nil, nil) + + spree_get :edit + + response.should redirect_to root_url + flash[:info].should == "The hub you have selected is temporarily closed for orders. Please try again later." + end + it "selects distributors" do d = create(:distributor_enterprise) p = create(:product, :distributors => [d])