Changing some validations to be compatible with activemodel.
This commit is contained in:
parent
d4010ad76e
commit
58d621d399
11 changed files with 54 additions and 30 deletions
|
@ -81,18 +81,26 @@ module CouchRest
|
|||
# attr_accessor :password_confirmation
|
||||
# attr_accessor :email_repeated
|
||||
#
|
||||
# validates_is_confirmed :password
|
||||
# validates_is_confirmed :email, :confirm => :email_repeated
|
||||
# validates_confirmation_of :password
|
||||
# validates_confirmation_of :email, :confirm => :email_repeated
|
||||
#
|
||||
# # a call to valid? will return false unless:
|
||||
# # password == password_confirmation
|
||||
# # and
|
||||
# # email == email_repeated
|
||||
#
|
||||
def validates_is_confirmed(*fields)
|
||||
def validates_confirmation_of(*fields)
|
||||
opts = opts_from_validator_args(fields)
|
||||
add_validator_to_context(opts, fields, CouchRest::Validation::ConfirmationValidator)
|
||||
end
|
||||
|
||||
def validates_is_confirmed(*fields)
|
||||
warn "[DEPRECATION] `validates_is_confirmed` is deprecated. Please use `validates_confirmation_of` instead."
|
||||
validates_confirmation_of(*fields)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end # module ValidatesIsConfirmed
|
||||
end # module Validation
|
||||
|
|
|
@ -99,18 +99,23 @@ module CouchRest
|
|||
# property :email, String
|
||||
# property :zip_code, String
|
||||
#
|
||||
# validates_format :email, :as => :email_address
|
||||
# validates_format :zip_code, :with => /^\d{5}$/
|
||||
# validates_format_of :email, :as => :email_address
|
||||
# validates_format_of :zip_code, :with => /^\d{5}$/
|
||||
#
|
||||
# # a call to valid? will return false unless:
|
||||
# # email is formatted like an email address
|
||||
# # and
|
||||
# # zip_code is a string of 5 digits
|
||||
#
|
||||
def validates_format(*fields)
|
||||
def validates_format_of(*fields)
|
||||
opts = opts_from_validator_args(fields)
|
||||
add_validator_to_context(opts, fields, CouchRest::Validation::FormatValidator)
|
||||
end
|
||||
|
||||
def validates_format(*fields)
|
||||
warn "[DEPRECATION] `validates_format` is deprecated. Please use `validates_format_of` instead."
|
||||
validates_format_of(*fields)
|
||||
end
|
||||
|
||||
end # module ValidatesFormat
|
||||
end # module Validation
|
||||
|
|
|
@ -115,20 +115,25 @@ module CouchRest
|
|||
# property low, Integer
|
||||
# property just_right, Integer
|
||||
#
|
||||
# validates_length :high, :min => 100000000000
|
||||
# validates_length :low, :equals => 0
|
||||
# validates_length :just_right, :within => 1..10
|
||||
# validates_length_of :high, :min => 100000000000
|
||||
# validates_length_of :low, :equals => 0
|
||||
# validates_length_of :just_right, :within => 1..10
|
||||
#
|
||||
# # a call to valid? will return false unless:
|
||||
# # high is greater than or equal to 100000000000
|
||||
# # low is equal to 0
|
||||
# # just_right is between 1 and 10 (inclusive of both 1 and 10)
|
||||
#
|
||||
def validates_length(*fields)
|
||||
def validates_length_of(*fields)
|
||||
opts = opts_from_validator_args(fields)
|
||||
add_validator_to_context(opts, fields, CouchRest::Validation::LengthValidator)
|
||||
end
|
||||
|
||||
|
||||
def validates_length(*fields)
|
||||
warn "[DEPRECATION] `validates_length` is deprecated. Please use `validates_length_of` instead."
|
||||
validates_length_of(*fields)
|
||||
end
|
||||
|
||||
end # module ValidatesLength
|
||||
end # module Validation
|
||||
end # module CouchRest
|
||||
|
|
|
@ -94,10 +94,15 @@ module CouchRest
|
|||
|
||||
# Validate whether a field is numeric
|
||||
#
|
||||
def validates_is_number(*fields)
|
||||
def validates_numericality_of(*fields)
|
||||
opts = opts_from_validator_args(fields)
|
||||
add_validator_to_context(opts, fields, CouchRest::Validation::NumericValidator)
|
||||
end
|
||||
|
||||
def validates_is_number(*fields)
|
||||
warn "[DEPRECATION] `validates_is_number` is deprecated. Please use `validates_numericality_of` instead."
|
||||
validates_numericality_of(*fields)
|
||||
end
|
||||
|
||||
end # module ValidatesIsNumber
|
||||
end # module Validation
|
||||
|
|
|
@ -93,16 +93,21 @@ module CouchRest
|
|||
# property :another_required, String
|
||||
# property :yet_again, String
|
||||
#
|
||||
# validates_present :required_attribute
|
||||
# validates_present :another_required, :yet_again
|
||||
# validates_presence_of :required_attribute
|
||||
# validates_presence_of :another_required, :yet_again
|
||||
#
|
||||
# # a call to valid? will return false unless
|
||||
# # all three attributes are !blank?
|
||||
# end
|
||||
def validates_present(*fields)
|
||||
def validates_presence_of(*fields)
|
||||
opts = opts_from_validator_args(fields)
|
||||
add_validator_to_context(opts, fields, CouchRest::Validation::RequiredFieldValidator)
|
||||
end
|
||||
|
||||
def validates_present(*fields)
|
||||
warn "[DEPRECATION] `validates_present` is deprecated. Please use `validates_presence_of` instead."
|
||||
validates_presence_of(*fields)
|
||||
end
|
||||
|
||||
end # module ValidatesPresent
|
||||
end # module Validation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue