diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 95962f74b6..78bb94d60a 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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 diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index a79d75bba3..226db25ea3 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -755,7 +755,7 @@ module ActiveRecord #:nodoc: 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 diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 1f6a58dee6..30b0b78313 100755 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -199,6 +199,16 @@ class FinderTest < Test::Unit::TestCase 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