From 20d27f6b743bc3425a75b0d07fd79b76e68d37e8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 2 Jul 2005 07:52:29 +0000 Subject: Fixed validates_numericality_of to work with overrided getter-method when :allow_nil is on #1316 [raidel@onemail.at] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1603 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/validations_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test/validations_test.rb') diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 8a918e2255..afd11c6d62 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -319,6 +319,13 @@ class ValidationsTest < Test::Unit::TestCase assert Topic.create("title" => nil, "content" => "abc").valid? end + def test_numericality_with_allow_nil_and_getter_method + Developer.validates_numericality_of( :salary, :allow_nil => true) + developer = Developer.new("name" => "michael", "salary" => nil) + developer.instance_eval("def salary; read_attribute('salary') ? read_attribute('salary') : 100000; end") + assert developer.valid? + end + def test_validates_exclusion_of Topic.validates_exclusion_of( :title, :in => %w( abe monkey ) ) -- cgit v1.2.3