mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user