Skip to content

Commit

Permalink
Fixed validates_numericality_of to work with overrided getter-method …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
dhh committed Jul 2, 2005
1 parent 9ac0277 commit 20d27f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Fixed validates_numericality_of to work with overrided getter-method when :allow_nil is on #1316 [raidel@onemail.at]

* Added roots, root, and siblings to the batch of methods added by acts_as_tree #1541 [michael@schuerig.de]

* Added support for limit/offset with the MS SQL Server driver so that pagination will now work #1569 [DeLynn Berry]
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ def validates_numericality_of(*attr_names)
end
else
validates_each(attr_names,configuration) do |record, attr_name,value|
next if configuration[:allow_nil] and record.send("#{attr_name}_before_type_cast").nil?
begin
Kernel.Float(record.send("#{attr_name}_before_type_cast").to_s)
rescue ArgumentError, TypeError
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ def test_validates_inclusion_of_with_allow_nil
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 ) )

Expand Down

0 comments on commit 20d27f6

Please sign in to comment.