diff --git a/app/controllers/darkswarm_controller.rb b/app/controllers/darkswarm_controller.rb deleted file mode 100644 index 8e0a477f67..0000000000 --- a/app/controllers/darkswarm_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -class DarkswarmController < BaseController - layout 'darkswarm' - - # TODO - # custom filter - # Get list of producers - # New? - # "Orders closing soon" etc, details - def index - @active_distributors ||= Enterprise.distributors_with_active_order_cycles - end -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 9f07e1d064..43c5216a8a 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,9 @@ class HomeController < BaseController - layout 'landing_page' + layout 'darkswarm' + + def index + @active_distributors ||= Enterprise.distributors_with_active_order_cycles + end def new_landing_page end @@ -9,7 +13,6 @@ class HomeController < BaseController def temp_landing_page @groups = EnterpriseGroup.on_front_page.by_position - render layout: false end end diff --git a/app/views/darkswarm/index.html.haml b/app/views/home/index.html.haml similarity index 100% rename from app/views/darkswarm/index.html.haml rename to app/views/home/index.html.haml diff --git a/config/routes.rb b/config/routes.rb index 27a6a4b61d..10a1cfd921 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Openfoodnetwork::Application.routes.draw do - root :to => 'darkswarm#index' + root :to => 'home#index' resource :shop, controller: "shop/shop" do get :products @@ -60,7 +60,6 @@ Openfoodnetwork::Application.routes.draw do end get "new_landing_page", :controller => 'home', :action => "new_landing_page" - get "darkswarm", controller: :darkswarm, action: :index get "about_us", :controller => 'home', :action => "about_us" namespace :open_food_network do @@ -71,6 +70,7 @@ Openfoodnetwork::Application.routes.draw do # Mount Spree's routes mount Spree::Core::Engine, :at => '/' + end @@ -129,4 +129,5 @@ Spree::Core::Engine.routes.prepend do get :clear, :on => :collection get :order_cycle_expired, :on => :collection end + end diff --git a/spec/archive/controllers/home_controller_spec.rb b/spec/archive/controllers/home_controller_spec.rb new file mode 100644 index 0000000000..18be4a0700 --- /dev/null +++ b/spec/archive/controllers/home_controller_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper' + +describe Spree::HomeController do + it "loads products" do + product = create(:product) + spree_get :index + assigns(:products).should == [product] + assigns(:products_local).should be_nil + assigns(:products_remote).should be_nil + end + + it "splits products by local/remote distributor when distributor is selected" do + # Given two distributors with a product under each + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + p1 = create(:product, :distributors => [d1]) + p2 = create(:product, :distributors => [d2]) + + # And the first distributor is selected + controller.stub(:current_distributor).and_return(d1) + + # When I fetch the home page, the products should be split by local/remote distributor + spree_get :index + assigns(:products).should be_nil + assigns(:products_local).should == [p1] + assigns(:products_remote).should == [p2] + end + + context "BaseController: merging incomplete orders" do + it "loads the incomplete order when there is no current order" do + incomplete_order = double(:order, id: 1, distributor: 2, order_cycle: 3) + current_order = nil + + user = double(:user, last_incomplete_spree_order: incomplete_order) + controller.stub(:try_spree_current_user).and_return(user) + controller.stub(:current_order).and_return(current_order) + + incomplete_order.should_receive(:destroy).never + incomplete_order.should_receive(:merge!).never + + session[:order_id] = nil + spree_get :index + session[:order_id].should == incomplete_order.id + end + + it "destroys the incomplete order when there is a current order" do + oc = double(:order_cycle, closed?: false) + incomplete_order = double(:order, distributor: 1, order_cycle: oc) + current_order = double(:order, distributor: 1, order_cycle: oc) + + user = double(:user, last_incomplete_spree_order: incomplete_order) + controller.stub(:try_spree_current_user).and_return(user) + controller.stub(:current_order).and_return(current_order) + + incomplete_order.should_receive(:destroy) + incomplete_order.should_receive(:merge!).never + current_order.should_receive(:merge!).never + + session[:order_id] = 123 + + 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, closed?: 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 diff --git a/spec/controllers/darkswarm_controller_spec.rb b/spec/controllers/darkswarm_controller_spec.rb deleted file mode 100644 index 975ffa5995..0000000000 --- a/spec/controllers/darkswarm_controller_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe DarkswarmController do - render_views - let(:distributor) { create(:distributor_enterprise) } - - before do - controller.stub(:load_data_for_sidebar).and_return nil - Enterprise.stub(:distributors_with_active_order_cycles).and_return [distributor] - Enterprise.stub(:is_distributor).and_return [distributor] - end - it "sets active distributors" do - get :index - assigns[:active_distributors].should == [distributor] - end - - # This is done inside the json/hubs RABL template - it "gets the next order cycle for each hub" do - OrderCycle.should_receive(:first_closing_for).with(distributor) - get :index - end -end - diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 18be4a0700..2f4ad05d8f 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,80 +1,23 @@ require 'spec_helper' -describe Spree::HomeController do - it "loads products" do - product = create(:product) - spree_get :index - assigns(:products).should == [product] - assigns(:products_local).should be_nil - assigns(:products_remote).should be_nil +describe HomeController do + render_views + let(:distributor) { create(:distributor_enterprise) } + + before do + controller.stub(:load_data_for_sidebar).and_return nil + Enterprise.stub(:distributors_with_active_order_cycles).and_return [distributor] + Enterprise.stub(:is_distributor).and_return [distributor] end - - it "splits products by local/remote distributor when distributor is selected" do - # Given two distributors with a product under each - d1 = create(:distributor_enterprise) - d2 = create(:distributor_enterprise) - p1 = create(:product, :distributors => [d1]) - p2 = create(:product, :distributors => [d2]) - - # And the first distributor is selected - controller.stub(:current_distributor).and_return(d1) - - # When I fetch the home page, the products should be split by local/remote distributor - spree_get :index - assigns(:products).should be_nil - assigns(:products_local).should == [p1] - assigns(:products_remote).should == [p2] + it "sets active distributors" do + get :index + assigns[:active_distributors].should == [distributor] end - - context "BaseController: merging incomplete orders" do - it "loads the incomplete order when there is no current order" do - incomplete_order = double(:order, id: 1, distributor: 2, order_cycle: 3) - current_order = nil - - user = double(:user, last_incomplete_spree_order: incomplete_order) - controller.stub(:try_spree_current_user).and_return(user) - controller.stub(:current_order).and_return(current_order) - - incomplete_order.should_receive(:destroy).never - incomplete_order.should_receive(:merge!).never - - session[:order_id] = nil - spree_get :index - session[:order_id].should == incomplete_order.id - end - - it "destroys the incomplete order when there is a current order" do - oc = double(:order_cycle, closed?: false) - incomplete_order = double(:order, distributor: 1, order_cycle: oc) - current_order = double(:order, distributor: 1, order_cycle: oc) - - user = double(:user, last_incomplete_spree_order: incomplete_order) - controller.stub(:try_spree_current_user).and_return(user) - controller.stub(:current_order).and_return(current_order) - - incomplete_order.should_receive(:destroy) - incomplete_order.should_receive(:merge!).never - current_order.should_receive(:merge!).never - - session[:order_id] = 123 - - 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, closed?: 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 + + # This is done inside the json/hubs RABL template + it "gets the next order cycle for each hub" do + OrderCycle.should_receive(:first_closing_for).with(distributor) + get :index end end +