diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 362fe49a08..acbafeea50 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -5,15 +5,15 @@ Spree::Order.class_eval do belongs_to :distributor, :class_name => 'Enterprise' before_validation :shipping_address_from_distributor - validate :products_available_from_new_distributor, :if => :distributor_id_changed? + validate :products_available_from_new_distribution, :if => lambda { distributor_id_changed? || order_cycle_id_changed? } attr_accessible :order_cycle_id, :distributor_id after_create :set_default_shipping_method - 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 DistributionChangeValidator.new(self).can_change_to_distribution?(distributor, order_cycle) + def products_available_from_new_distribution + # Check that the line_items in the current order are available from a newly selected distribution + errors.add(:base, "Distributor or order cycle cannot supply the products in your cart") unless DistributionChangeValidator.new(self).can_change_to_distribution?(distributor, order_cycle) end def set_order_cycle!(order_cycle) diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index c9a3d86520..e107e36e68 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -121,7 +121,7 @@ describe Spree::Order do subject.distributor = test_enterprise subject.should_not be_valid - subject.errors.should include :distributor_id + subject.errors.messages.should == {base: ["Distributor or order cycle cannot supply the products in your cart"]} end end end