From c8c16f0e8a5f411cd694dc0b7510358b3d578062 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 8 Oct 2018 16:54:22 +0200 Subject: [PATCH] Use Rails 3.2 validates syntax --- app/models/spree/variant_decorator.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 4c7e6ed5ab..cefb7917da 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -18,11 +18,13 @@ Spree::Variant.class_eval do attr_accessible :unit_value, :unit_description, :images_attributes, :display_as, :display_name, :import_date accepts_nested_attributes_for :images - validates_presence_of :unit_value, - if: -> v { %w(weight volume).include? v.product.andand.variant_unit } + validates :unit_value, presence: true, if: -> (variant) { + %w(weight volume).include?(variant.product.andand.variant_unit) + } - validates_presence_of :unit_description, - if: -> v { v.product.andand.variant_unit.present? && v.unit_value.nil? } + validates :unit_description, presence: true, if: -> (variant) { + variant.product.andand.variant_unit.present? && variant.unit_value.nil? + } before_validation :update_weight_from_unit_value, if: -> v { v.product.present? } after_save :update_units