Moving from darkswarm to home

This commit is contained in:
Will Marshall
2014-04-24 16:53:00 +10:00
parent f6bfc71c4b
commit f9b7b602da
7 changed files with 105 additions and 113 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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