Removing code

This commit is contained in:
Will Marshall
2014-05-14 15:16:29 +10:00
parent 151702d685
commit 5f712a8984
12 changed files with 6 additions and 205 deletions

View File

@@ -1,10 +1,14 @@
class CheckoutController < Spree::CheckoutController
layout 'darkswarm'
prepend_before_filter :check_order_cycle_expiry
prepend_before_filter :require_order_cycle
prepend_before_filter :require_distributor_chosen
skip_before_filter :check_registration
skip_before_filter :redirect_to_paypal_express_form_if_needed
include OrderCyclesHelper
include EnterprisesHelper
def edit

View File

@@ -1,11 +0,0 @@
require 'open_food_network/split_products_by_distribution'
Spree::HomeController.class_eval do
include EnterprisesHelper
include OrderCyclesHelper
include OpenFoodNetwork::SplitProductsByDistribution
respond_override :index => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distribution @products, current_distributor, current_order_cycle
} } }
end

View File

@@ -8,6 +8,7 @@ Spree::OrdersController.class_eval do
prepend_before_filter :require_order_cycle, only: [:edit]
prepend_before_filter :require_distributor_chosen, only: [:edit]
include OrderCyclesHelper
layout 'darkswarm'
# Patch Orders#populate to populate multi_cart (if enabled)

View File

@@ -1,11 +0,0 @@
Spree::ProductsController.class_eval do
include EnterprisesHelper
include OrderCyclesHelper
before_filter :require_distributor_chosen, only: :index
respond_override :index => { :html => { :success => lambda {
redirect_to main_app.enterprise_path(current_distributor)
} } }
end

View File

@@ -1,4 +0,0 @@
Spree::StoreController.class_eval do
include OrderCyclesHelper
before_filter :check_order_cycle_expiry
end

View File

@@ -1,13 +0,0 @@
require 'open_food_network/split_products_by_distribution'
Spree::TaxonsController.class_eval do
include EnterprisesHelper
include OrderCyclesHelper
include OpenFoodNetwork::SplitProductsByDistribution
before_filter :require_distributor_chosen, only: :show
respond_override :show => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distribution @products, current_distributor, current_order_cycle
} } }
end

View File

@@ -1,32 +0,0 @@
module Spree
BaseHelper.class_eval do
# TODO can we delete this?
# Spree code we are overriding to render sidebar
# No longer rendering sidebar
def taxons_tree(root_taxon, current_taxon, max_level = 1)
return '' if max_level < 1 || root_taxon.children.empty?
content_tag :ul, :class => 'taxons-list' do
root_taxon.children.map do |taxon|
css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil
# The concern of separating products by distributor and order cycle is dealt with in
# a few other places: OpenFoodNetwork::Searcher (for searching over products) and in
# OpenFoodNetwork::SplitProductsByDistribution (for splitting the main product display).
products = Product.in_taxon(taxon)
products = products.in_distributor(current_distributor) if current_distributor
products = products.in_order_cycle(current_order_cycle) if current_order_cycle
num_products = products.count
content_tag :li, :class => css_class do
link_to(taxon.name, seo_url(taxon)) +
" (#{num_products})" +
taxons_tree(taxon, current_taxon, max_level - 1)
end
end.join("\n").html_safe
end
end
end
end

View File

@@ -1,27 +0,0 @@
module OpenFoodNetwork
# The concern of separating products by distributor and order cycle is dealt with in a few
# other places: OpenFoodNetwork::Searcher (for searching over products) and in
# Spree::BaseHelper decorator (for taxon counts).
module SplitProductsByDistribution
# If a distributor or order cycle is provided, split the list of products into local (at that
# distributor/order cycle) and remote (available elsewhere). If a distributor is not
# provided, perform no split.
def split_products_by_distribution(products, distributor, order_cycle)
products_local = products_remote = nil
if distributor || order_cycle
selector = proc do |product|
(!distributor || product.in_distributor?(distributor)) && (!order_cycle || product.in_order_cycle?(order_cycle))
end
products_local = products.select &selector
products_remote = products.reject &selector
products = nil
end
[products, products_local, products_remote]
end
end
end

View File

@@ -122,7 +122,7 @@ describe EnterprisesController do
spree_get :index
session[:expired_order_cycle_id].should == 123
response.should redirect_to spree.order_cycle_expired_orders_path
response.should redirect_to root_url
end
end
end

View File

@@ -1,20 +0,0 @@
require 'spec_helper'
describe Spree::ProductsController do
context "when a distributor has not been chosen" do
it "redirects #index to distributor selection" do
spree_get :index
response.should redirect_to spree.root_path
end
end
context "when a distributor has been chosen" do
it "redirects #index to the distributor page" do
d = create(:distributor_enterprise)
controller.stub(:current_distributor) { d }
spree_get :index
response.should redirect_to enterprise_path(d)
end
end
end

View File

@@ -1,11 +0,0 @@
require 'spec_helper'
describe Spree::TaxonsController do
context "when a distributor has not been chosen" do
it "redirects #show to distributor selection" do
taxon = create(:taxon)
spree_get :show, {id: taxon.permalink}
response.should redirect_to spree.root_path
end
end
end

View File

@@ -1,75 +0,0 @@
require 'open_food_network/split_products_by_distribution'
describe OpenFoodNetwork::SplitProductsByDistribution do
let(:products_splitter) { Class.new { include OpenFoodNetwork::SplitProductsByDistribution } }
let(:subject) { products_splitter.new }
it "does nothing when no distributor or order cycle is selected" do
orig_products = [double(:product)]
products, products_local, products_remote = subject.split_products_by_distribution orig_products, nil, nil
products.should == orig_products
products_local.should be_nil
products_remote.should be_nil
end
it "splits products by distributor when a distributor is selected" do
distributor = double(:distributor)
local_product = build_product distributor, true, nil, false
remote_product = build_product distributor, false, nil, false
products, products_local, products_remote = subject.split_products_by_distribution [local_product, remote_product], distributor, nil
products.should be_nil
products_local.should == [local_product]
products_remote.should == [remote_product]
end
it "splits products by order cycle when an order cycle is selected" do
order_cycle = double(:order_cycle)
local_product = build_product nil, false, order_cycle, true
remote_product = build_product nil, false, order_cycle, false
products, products_local, products_remote = subject.split_products_by_distribution [local_product, remote_product], nil, order_cycle
products.should be_nil
products_local.should == [local_product]
products_remote.should == [remote_product]
end
it "splits products by both order cycle and distributor when both are selected" do
distributor = double(:distributor)
order_cycle = double(:order_cycle)
neither_product = build_product distributor, false, order_cycle, false
distributor_product = build_product distributor, true, order_cycle, false
order_cycle_product = build_product distributor, false, order_cycle, true
both_product = build_product distributor, true, order_cycle, true
orig_products = [neither_product, distributor_product, order_cycle_product, both_product]
products, products_local, products_remote = subject.split_products_by_distribution orig_products, distributor, order_cycle
products.should be_nil
products_local.should == [both_product]
products_remote.should == [neither_product, distributor_product, order_cycle_product]
end
private
def build_product(distributor, in_distributor, order_cycle, in_order_cycle)
product = double(:product)
product.stub(:in_distributor?) { in_distributor } if distributor
product.stub(:in_order_cycle?) { in_order_cycle } if order_cycle
product
end
end