Fix duplicate validations in payment methods and shipping methods

Updates the syntax to follow the recommended usage in the code comments of the ActiveModel #validates_with method.

Fixes:

  12) Spree::PaymentMethod raises errors when required fields are missing
      Failure/Error: expect(pm.errors.to_a).to eq(["Name can't be blank", "At least one hub must be selected"])

        expected: ["Name can't be blank", "At least one hub must be selected"]
             got: ["Name can't be blank", "At least one hub must be selected", "At least one hub must be selected"]

        (compared using ==)
      # ./spec/models/spree/payment_method_spec.rb:16:in `block (2 levels) in <module:Spree>'
This commit is contained in:
Matt-Yorkley
2020-03-02 19:02:07 +01:00
parent ddebd47e32
commit ed5351d23e
2 changed files with 12 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ Spree::PaymentMethod.class_eval do
after_initialize :init
validates_with DistributorsValidator
validate :distributor_validation
# -- Scopes
scope :managed_by, lambda { |user|
@@ -73,4 +73,10 @@ Spree::PaymentMethod.class_eval do
name[i..-1]
end
end
private
def distributor_validation
validates_with DistributorsValidator
end
end

View File

@@ -6,7 +6,7 @@ Spree::ShippingMethod.class_eval do
after_save :touch_distributors
validates_with DistributorsValidator
validate :distributor_validation
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
@@ -80,4 +80,8 @@ Spree::ShippingMethod.class_eval do
def touch_distributors
distributors.each(&:touch)
end
def distributor_validation
validates_with DistributorsValidator
end
end