spec/support/validator_detector.rb in riveter-0.2.0 vs spec/support/validator_detector.rb in riveter-0.2.1

- old
+ new

@@ -28,16 +28,20 @@ # next, evaluate the condition to determine whether the validator is active # NOTE: any errors are ignored, and the default therefore is false if method.instance_of?(Symbol) || method.instance_of?(String) # it's a model method, so evalulate within context self.new().instance_eval do - send(method, self) rescue false + # call the method assocated with the validation + # if a method is called in an unless, we need to flip the boolean result + ( validator.options[:unless].present? ? !send(method) : send(method) ) rescue false end elsif method.instance_of?(Proc) # it's a lambda, so invoke within context self.new().instance_eval do - method.call(self) rescue false + # call the proc assocated with the validation + # if a method is called in an unless, we need to flip the boolean result + ( validator.options[:unless].present? ? !method.call(self) : method.call(self) ) rescue false end else # default is applied true