fixed some serious issues but left some for tomorrow (validations aren't working right)

This commit is contained in:
Matt Aimonetti 2009-02-10 02:15:39 -08:00
parent bc47e72ae0
commit e448112ff6
8 changed files with 89 additions and 48 deletions

View file

@ -6,22 +6,20 @@ module CouchRest
class Property
# flag letting us know if we already checked the autovalidation settings
attr_accessor :autovalidation_check
@@autovalidation_check = false
end
module Validation
module AutoValidate
module AutoValidate
# Turn off auto validation by default
def auto_validation
@@auto_validation ||= false
end
# Force the auto validation for the class properties
# This feature is still not fully ported over,
# test are lacking, so please use with caution
def auto_validate!
@@auto_validation = true
end
# # Force the auto validation for the class properties
# # This feature is still not fully ported over,
# # test are lacking, so please use with caution
# def auto_validate!
# require 'ruby-debug'
# debugger
# auto_validation = true
# end
# adds message for validator
def options_with_message(base_options, property, validator_name)
@ -93,9 +91,7 @@ module CouchRest
# It is just shortcut if only one validation option is set
#
def auto_generate_validations(property)
return unless property.options
return unless property.autovalidation_check || auto_validation || (property.options && property.options.has_key?(:auto_validation) && property.options[:auto_validation])
return unless (property.autovalidation_check && self.auto_validation && (property.options && property.options.has_key?(:auto_validation) && property.options[:auto_validation]))
# value is set by the storage system
opts = {}
opts[:context] = property.options[:validates] if property.options.has_key?(:validates)

View file

@ -40,7 +40,7 @@ module CouchRest
value = target.send(field_name)
return true if @options[:allow_nil] && value.nil?
value = value.kind_of?(BigDecimal) ? value.to_s('F') : value.to_s
value = value.kind_of?(Float) ? value.to_s('F') : value.to_s
error_message = @options[:message]
precision = @options[:precision]