diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-03-16 18:54:51 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-03-16 18:54:51 +0000 |
commit | 8aaf3c1e553d18b40d9980951d496bffad56f37b (patch) | |
tree | 2eddd2b50a5924420b30caa5c6d867f4870a71dc /activemodel/lib/active_model | |
parent | 9abc94c44516afdcfe4a3b202c336c9578fd6d0d (diff) | |
parent | 0eae62525696b57fe7fc4bbb0bf9c0bc7ee4e480 (diff) | |
download | rails-8aaf3c1e553d18b40d9980951d496bffad56f37b.tar.gz rails-8aaf3c1e553d18b40d9980951d496bffad56f37b.tar.bz2 rails-8aaf3c1e553d18b40d9980951d496bffad56f37b.zip |
Merge branch 'master' into nested_has_many_through
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/lint.rb | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 3 | ||||
-rw-r--r-- | activemodel/lib/active_model/validator.rb | 4 |
3 files changed, 6 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 957d1b9d70..b71ef4b22e 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -23,7 +23,7 @@ module ActiveModel def test_to_key assert model.respond_to?(:to_key), "The model should respond to to_key" def model.persisted?() false end - assert model.to_key.nil? + assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false" end # == Responds to <tt>to_param</tt> @@ -40,7 +40,7 @@ module ActiveModel assert model.respond_to?(:to_param), "The model should respond to to_param" def model.to_key() [1] end def model.persisted?() false end - assert model.to_param.nil? + assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end # == Responds to <tt>valid?</tt> diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 7af6c83460..72735cfb89 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -43,7 +43,8 @@ module ActiveModel value ||= [] if key == :maximum - next if value && value.size.send(validity_check, check_value) + value_length = value.respond_to?(:length) ? value.length : value.to_s.length + next if value_length.send(validity_check, check_value) errors_options = options.except(*RESERVED_OPTIONS) errors_options[:count] = check_value diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 1c6123eb09..c5ed8d22d3 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -120,7 +120,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with validation logic, adding errors # to the records +errors+ array where necessary. def validate(record) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate(record) method." end end @@ -156,7 +156,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with the validation logic, adding # errors to the records +errors+ array where necessary. def validate_each(record, attribute, value) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate_each(record, attribute, value) method" end # Hook method that gets called by the initializer allowing verification |