From 0e08829a2952db7cdf638735aa986156d5f0a3db Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 28 May 2013 12:32:52 +1000 Subject: [PATCH] Rename DistributorChangeValidator to DistributionChangeValidator in preparation for expansion to include order cycles --- app/controllers/spree/orders_controller_decorator.rb | 2 +- app/helpers/add_to_cart_helper.rb | 4 ++-- app/helpers/spree/orders_helper.rb | 2 +- app/models/spree/order_decorator.rb | 4 ++-- app/views/spree/products/_source.html.haml | 2 +- app/views/spree/products/_source_sidebar.html.haml | 2 +- ...e_validator.rb => distribution_change_validator.rb} | 2 +- ...r_spec.rb => distribution_change_validator_spec.rb} | 10 +++++----- 8 files changed, 14 insertions(+), 14 deletions(-) rename lib/open_food_web/{distributor_change_validator.rb => distribution_change_validator.rb} (96%) rename spec/lib/open_food_web/{distributor_change_validator_spec.rb => distribution_change_validator_spec.rb} (95%) diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index d716e58df9..e38721ddbf 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -116,7 +116,7 @@ Spree::OrdersController.class_eval do # -- Distributor can't be changed unless new distributor can service cart order = current_order(false) - if !order.nil? && !DistributorChangeValidator.new(order).can_change_to_distributor?(distributor) + if !order.nil? && !DistributionChangeValidator.new(order).can_change_to_distributor?(distributor) return false end diff --git a/app/helpers/add_to_cart_helper.rb b/app/helpers/add_to_cart_helper.rb index 7fb5604fa1..0dde582f8e 100644 --- a/app/helpers/add_to_cart_helper.rb +++ b/app/helpers/add_to_cart_helper.rb @@ -4,10 +4,10 @@ module AddToCartHelper end def product_incompatible_with_current_order(order, product) - !DistributorChangeValidator.new(order).product_compatible_with_current_order(product) + !DistributionChangeValidator.new(order).product_compatible_with_current_order(product) end def available_distributors_for(order, product) - DistributorChangeValidator.new(order).available_distributors_for(product) + DistributionChangeValidator.new(order).available_distributors_for(product) end end diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 08d5e5492f..d4eaa03484 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -7,7 +7,7 @@ module Spree end def alternative_available_distributors(order) - DistributorChangeValidator.new(order).available_distributors(Enterprise.all) - [order.distributor] + DistributionChangeValidator.new(order).available_distributors(Enterprise.all) - [order.distributor] end end end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 45123d08c7..980f24c777 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -1,4 +1,4 @@ -require 'open_food_web/distributor_change_validator' +require 'open_food_web/distribution_change_validator' Spree::Order.class_eval do belongs_to :order_cycle @@ -13,7 +13,7 @@ Spree::Order.class_eval do def products_available_from_new_distributor # Check that the line_items in the current order are available from a newly selected distributor - errors.add(:distributor_id, "cannot supply the products in your cart") unless DistributorChangeValidator.new(self).can_change_to_distributor?(distributor) + errors.add(:distributor_id, "cannot supply the products in your cart") unless DistributionChangeValidator.new(self).can_change_to_distributor?(distributor) end def set_order_cycle!(order_cycle) diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 13a9e340ea..2c82ae2b85 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %table#product-source.table-display{:width => "100%"} %tbody - order = current_order(false) - - validator = DistributorChangeValidator.new(order) + - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_product(@product).each do |distributor| - if !order.nil? && distributor == order.distributor %tr.odd diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 03fc78ac84..fa9d6232d2 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -9,7 +9,7 @@ %h6.filter_name Shop by Distributor %ul.filter_choices - order = current_order(false) - - validator = DistributorChangeValidator.new(order) + - validator = DistributionChangeValidator.new(order) - @distributors.each do |distributor| %li.nowrap - if order.nil? || validator.can_change_to_distributor?(distributor) diff --git a/lib/open_food_web/distributor_change_validator.rb b/lib/open_food_web/distribution_change_validator.rb similarity index 96% rename from lib/open_food_web/distributor_change_validator.rb rename to lib/open_food_web/distribution_change_validator.rb index 2a40b5f7f7..f972977e95 100644 --- a/lib/open_food_web/distributor_change_validator.rb +++ b/lib/open_food_web/distribution_change_validator.rb @@ -1,4 +1,4 @@ -class DistributorChangeValidator +class DistributionChangeValidator def initialize order @order = order diff --git a/spec/lib/open_food_web/distributor_change_validator_spec.rb b/spec/lib/open_food_web/distribution_change_validator_spec.rb similarity index 95% rename from spec/lib/open_food_web/distributor_change_validator_spec.rb rename to spec/lib/open_food_web/distribution_change_validator_spec.rb index d958d49eae..08bde44faf 100644 --- a/spec/lib/open_food_web/distributor_change_validator_spec.rb +++ b/spec/lib/open_food_web/distribution_change_validator_spec.rb @@ -1,8 +1,8 @@ -require 'open_food_web/distributor_change_validator' +require 'open_food_web/distribution_change_validator' -describe DistributorChangeValidator do +describe DistributionChangeValidator do let(:order) { double(:order) } - let(:subject) { DistributorChangeValidator.new(order) } + let(:subject) { DistributionChangeValidator.new(order) } let(:product) { double(:product) } context "permissions for changing distributor" do @@ -88,7 +88,7 @@ describe DistributorChangeValidator do describe "checking product compatibility with current order" do it "returns true when order is nil" do - subject = DistributorChangeValidator.new(nil) + subject = DistributionChangeValidator.new(nil) subject.product_compatible_with_current_order(product).should be_true end @@ -105,7 +105,7 @@ describe DistributorChangeValidator do describe "finding available distributors for a product" do it "returns enterprises distributing the product when there's no order" do - subject = DistributorChangeValidator.new(nil) + subject = DistributionChangeValidator.new(nil) Enterprise.stub(:distributing_product).and_return([1, 2, 3]) subject.should_receive(:available_distributors).never