Permalink
Browse files

Fixed that the dynamic finder like find_all_by_something_boolean(fals…

…e) didn't work #649 [lmarlow@yahoo.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@666 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 37249f6 commit 28edbca47728c8fe045a2b47bae925c09c6d5113 @dhh dhh committed Feb 18, 2005
Showing with 13 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/base.rb
  3. +10 −0 activerecord/test/finder_test.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that the dynamic finder like find_all_by_something_boolean(false) didn't work #649 [lmarlow@yahoo.com]
+
* Added validates_each that validates each specified attribute against a block #610 [bitsweat]. Example:
class Person < ActiveRecord::Base
@@ -755,7 +755,7 @@ def method_missing(method_id, *arguments)
attributes.each { |attr_name| super unless column_methods_hash[attr_name.intern] }
attr_index = -1
- conditions = attributes.collect { |attr_name| attr_index += 1; "#{attr_name} #{arguments[attr_index] ? "=" : "IS"} ? " }.join(" AND ")
+ conditions = attributes.collect { |attr_name| attr_index += 1; "#{attr_name} #{arguments[attr_index].nil? ? "IS" : "="} ? " }.join(" AND ")
send(finder, [conditions, *arguments[0...attributes.length]], *arguments[attributes.length..-1])
else
super
@@ -199,6 +199,16 @@ def test_find_all_by_one_attribute
assert_equal [], Topic.find_all_by_title("The First Topic!!")
end
+
+ def test_find_all_by_boolean_attribute
+ topics = Topic.find_all_by_approved(false)
+ assert_equal 1, topics.size
+ assert topics.include?(@topics["first"].find)
+
+ topics = Topic.find_all_by_approved(true)
+ assert_equal 1, topics.size
+ assert topics.include?(@topics["second"].find)
+ end
def test_find_by_nil_attribute
topic = Topic.find_by_last_read nil

0 comments on commit 28edbca

Please sign in to comment.