From 5f712a89842d2bdddb46cacebc5a8ab5e08519fd Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 14 May 2014 15:16:29 +1000 Subject: [PATCH] Removing code --- app/controllers/checkout_controller.rb | 4 + .../spree/home_controller_decorator.rb | 11 --- .../spree/orders_controller_decorator.rb | 1 + .../spree/products_controller_decorator.rb | 11 --- .../spree/store_controller_decorator.rb | 4 - .../spree/taxons_controller_decorator.rb | 13 ---- app/helpers/spree/base_helper_decorator.rb | 32 -------- .../split_products_by_distribution.rb | 27 ------- .../enterprises_controller_spec.rb | 2 +- .../spree/products_controller_spec.rb | 20 ----- .../spree/taxons_controller_spec.rb | 11 --- .../split_products_by_distribution_spec.rb | 75 ------------------- 12 files changed, 6 insertions(+), 205 deletions(-) delete mode 100644 app/controllers/spree/home_controller_decorator.rb delete mode 100644 app/controllers/spree/products_controller_decorator.rb delete mode 100644 app/controllers/spree/store_controller_decorator.rb delete mode 100644 app/controllers/spree/taxons_controller_decorator.rb delete mode 100644 app/helpers/spree/base_helper_decorator.rb delete mode 100644 lib/open_food_network/split_products_by_distribution.rb delete mode 100644 spec/controllers/spree/products_controller_spec.rb delete mode 100644 spec/controllers/spree/taxons_controller_spec.rb delete mode 100644 spec/lib/open_food_network/split_products_by_distribution_spec.rb diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index daab4ec52b..5cf940c223 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -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 diff --git a/app/controllers/spree/home_controller_decorator.rb b/app/controllers/spree/home_controller_decorator.rb deleted file mode 100644 index a01d94c431..0000000000 --- a/app/controllers/spree/home_controller_decorator.rb +++ /dev/null @@ -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 diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 65d1908723..af1d5621c5 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -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) diff --git a/app/controllers/spree/products_controller_decorator.rb b/app/controllers/spree/products_controller_decorator.rb deleted file mode 100644 index 74eb382238..0000000000 --- a/app/controllers/spree/products_controller_decorator.rb +++ /dev/null @@ -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 diff --git a/app/controllers/spree/store_controller_decorator.rb b/app/controllers/spree/store_controller_decorator.rb deleted file mode 100644 index 00c28176cb..0000000000 --- a/app/controllers/spree/store_controller_decorator.rb +++ /dev/null @@ -1,4 +0,0 @@ -Spree::StoreController.class_eval do - include OrderCyclesHelper - before_filter :check_order_cycle_expiry -end diff --git a/app/controllers/spree/taxons_controller_decorator.rb b/app/controllers/spree/taxons_controller_decorator.rb deleted file mode 100644 index a4c2811a86..0000000000 --- a/app/controllers/spree/taxons_controller_decorator.rb +++ /dev/null @@ -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 diff --git a/app/helpers/spree/base_helper_decorator.rb b/app/helpers/spree/base_helper_decorator.rb deleted file mode 100644 index 8abdace556..0000000000 --- a/app/helpers/spree/base_helper_decorator.rb +++ /dev/null @@ -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 diff --git a/lib/open_food_network/split_products_by_distribution.rb b/lib/open_food_network/split_products_by_distribution.rb deleted file mode 100644 index 637c91b3d4..0000000000 --- a/lib/open_food_network/split_products_by_distribution.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 77a01e42de..c0864b6a0c 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -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 diff --git a/spec/controllers/spree/products_controller_spec.rb b/spec/controllers/spree/products_controller_spec.rb deleted file mode 100644 index b0d88e0b70..0000000000 --- a/spec/controllers/spree/products_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/spree/taxons_controller_spec.rb b/spec/controllers/spree/taxons_controller_spec.rb deleted file mode 100644 index 9ef4a34cc1..0000000000 --- a/spec/controllers/spree/taxons_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/lib/open_food_network/split_products_by_distribution_spec.rb b/spec/lib/open_food_network/split_products_by_distribution_spec.rb deleted file mode 100644 index 2431180c11..0000000000 --- a/spec/lib/open_food_network/split_products_by_distribution_spec.rb +++ /dev/null @@ -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