Allow browsing products (but not cart/checkout) for hubs that are not ready for checkout

This commit is contained in:
Rohan Mitchell
2014-11-05 14:29:36 +11:00
parent a2f4732547
commit fdbb274667
5 changed files with 31 additions and 16 deletions

View File

@@ -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

View File

@@ -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'

View File

@@ -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'

View File

@@ -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)

View File

@@ -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])