diff options
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations/acceptance.rb | 7 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 3 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/numericality.rb | 7 |
3 files changed, 11 insertions, 6 deletions
diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index a5de58cd41..bd9463ed27 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -1,6 +1,10 @@ module ActiveModel module Validations class AcceptanceValidator < EachValidator + def initialize(options) + super(options.reverse_merge(:allow_nil => true, :accept => "1")) + end + def validate_each(record, attribute, value) unless value == options[:accept] record.errors.add(attribute, :accepted, :default => options[:message]) @@ -33,8 +37,7 @@ module ActiveModel # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The # method, proc or string should return or evaluate to a true or false value. def validates_acceptance_of(*attr_names) - options = { :allow_nil => true, :accept => "1" } - options.update(attr_names.extract_options!) + options = attr_names.extract_options! db_cols = begin column_names diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 04280b401b..6e90a75c17 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -9,9 +9,8 @@ module ActiveModel attr_reader :type def initialize(options) - options[:tokenizer] ||= DEFAULT_TOKENIZER @type = (OPTIONS & options.keys).first - super + super(options.reverse_merge(:tokenizer => DEFAULT_TOKENIZER)) end def check_validity! diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index 914a3133cf..f2aab8c5b8 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -5,6 +5,10 @@ module ActiveModel :equal_to => :==, :less_than => :<, :less_than_or_equal_to => :<=, :odd => :odd?, :even => :even? }.freeze + def initialize(options) + super(options.reverse_merge(:only_integer => false, :allow_nil => false)) + end + def check_validity! options.slice(*CHECKS.keys) do |option, value| next if [:odd, :even].include?(option) @@ -99,8 +103,7 @@ module ActiveModel # end # def validates_numericality_of(*attr_names) - options = { :only_integer => false, :allow_nil => false } - options.update(attr_names.extract_options!) + options = attr_names.extract_options! validates_with NumericalityValidator, options.merge(:attributes => attr_names) end end |