mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rename DistributorChangeValidator to DistributionChangeValidator in preparation for expansion to include order cycles
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class DistributorChangeValidator
|
||||
class DistributionChangeValidator
|
||||
|
||||
def initialize order
|
||||
@order = order
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user