From 58de03f077b0da1cb923f28835b00cd092de3c08 Mon Sep 17 00:00:00 2001 From: Mike Gehard Date: Wed, 9 Feb 2011 06:32:40 -0700 Subject: Add additional text to NotImplementedErrors [#6328 state:resolved] Signed-off-by: Santiago Pastorino --- activemodel/lib/active_model/validator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel/lib') 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 -- cgit v1.2.3 From f48d3d4df6c8ff6ab544f5fe384af2a0552984d7 Mon Sep 17 00:00:00 2001 From: Andriy Tyurnikov Date: Thu, 10 Mar 2011 19:50:55 +0200 Subject: length validation for fixnums Signed-off-by: Santiago Pastorino --- activemodel/lib/active_model/validations/length.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 7af6c83460..3e6f6e62e6 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -42,7 +42,8 @@ module ActiveModel next unless check_value = options[key] value ||= [] if key == :maximum - + + next if value.kind_of?(Fixnum) && value.to_s.size.send(validity_check, check_value) next if value && value.size.send(validity_check, check_value) errors_options = options.except(*RESERVED_OPTIONS) -- cgit v1.2.3 From 157c37f55854a17fcb50e77b7636fab01773df3c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 12 Mar 2011 21:10:19 -0200 Subject: Refactor length validation --- activemodel/lib/active_model/validations/length.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 3e6f6e62e6..72735cfb89 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -42,9 +42,9 @@ module ActiveModel next unless check_value = options[key] value ||= [] if key == :maximum - - next if value.kind_of?(Fixnum) && value.to_s.size.send(validity_check, check_value) - 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 -- cgit v1.2.3 From 7bd70dcd6c62fb94e3298e926f69a4e1946739cc Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Tue, 15 Mar 2011 10:06:53 -0300 Subject: Add messages to plain assertions. Signed-off-by: Santiago Pastorino --- activemodel/lib/active_model/lint.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 957d1b9d70..35e216ac6b 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 to_param @@ -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 `persited?` returns false" end # == Responds to valid? -- cgit v1.2.3 From e8458d37c56a94fae5f4c762b1767f67e10ddb43 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 16 Mar 2011 10:28:40 +0000 Subject: Fix typo in assertion message --- activemodel/lib/active_model/lint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 35e216ac6b..b71ef4b22e 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -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?, "to_param should return nil when `persited?` returns false" + assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end # == Responds to valid? -- cgit v1.2.3