When order cycle expires, clear cart and display a message (from BaseController)

This commit is contained in:
Rohan Mitchell
2013-10-23 17:16:07 +11:00
parent aec21b1a54
commit e3307623dd
5 changed files with 43 additions and 14 deletions

View File

@@ -35,6 +35,15 @@ class ApplicationController < ActionController::Base
end
end
def check_order_cycle_expiry
if current_order_cycle.andand.expired?
session[:expired_order_cycle_id] = current_order_cycle.id
current_order.empty!
current_order.set_order_cycle! nil
redirect_to spree.order_cycle_expired_orders_path
end
end
# There are several domains that point to the production server, but only one
# (vic.openfoodnetwork.org) that has the SSL certificate. Redirect all requests to this
# domain to avoid showing customers a scary invalid certificate error.

View File

@@ -7,4 +7,6 @@ class BaseController < ApplicationController
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
# include Spree::ProductsHelper so that method is available on the controller
include Spree::ProductsHelper
before_filter :check_order_cycle_expiry
end

View File

@@ -1,18 +1,4 @@
Spree::StoreController.class_eval do
include OrderCyclesHelper
before_filter :check_order_cycle_expiry
private
def check_order_cycle_expiry
if current_order_cycle.andand.expired?
session[:expired_order_cycle_id] = current_order_cycle.id
current_order.empty!
current_order.set_order_cycle! nil
redirect_to order_cycle_expired_orders_path
end
end
end

View File

@@ -68,4 +68,20 @@ describe EnterprisesController do
response.should redirect_to spree.root_path
end
end
context "BaseController: handling order cycles expiring mid-order" do
it "clears the order and displays an expiry message" do
oc = double(:order_cycle, id: 123, expired?: true)
controller.stub(:current_order_cycle) { oc }
order = double(:order)
order.should_receive(:empty!)
order.should_receive(:set_order_cycle!).with(nil)
controller.stub(:current_order) { order }
spree_get :index
session[:expired_order_cycle_id].should == 123
response.should redirect_to spree.order_cycle_expired_orders_path
end
end
end

View File

@@ -61,4 +61,20 @@ describe Spree::HomeController do
spree_get :index
end
end
context "StoreController: handling order cycles expiring mid-order" do
it "clears the order and displays an expiry message" do
oc = double(:order_cycle, id: 123, expired?: true)
controller.stub(:current_order_cycle) { oc }
order = double(:order)
order.should_receive(:empty!)
order.should_receive(:set_order_cycle!).with(nil)
controller.stub(:current_order) { order }
spree_get :index
session[:expired_order_cycle_id].should == 123
response.should redirect_to spree.order_cycle_expired_orders_path
end
end
end