Permalink
Browse files

Fix generated WHERE IN query for named scopes. [#583 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 0048f55 commit 2092f26edbd6de6d542a7bbd5b4dd30d5fd66ef4 @phallstrom phallstrom committed with tarmo Aug 21, 2008
@@ -1722,7 +1722,7 @@ def all_attributes_exists?(attribute_names)
def attribute_condition(argument)
case argument
when nil then "IS ?"
- when Array, ActiveRecord::Associations::AssociationCollection then "IN (?)"
+ when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "IN (?)"
when Range then "BETWEEN ? AND ?"
else "= ?"
end
@@ -4,6 +4,7 @@
require 'models/comment'
require 'models/reply'
require 'models/author'
+require 'models/developer'
class NamedScopeTest < ActiveRecord::TestCase
fixtures :posts, :authors, :topics, :comments, :author_addresses
@@ -189,4 +190,8 @@ def test_empty_should_not_load_results
def test_find_all_should_behave_like_select
assert_equal Topic.base.select(&:approved), Topic.base.find_all(&:approved)
end
+
+ def test_should_use_where_in_query_for_named_scope
+ assert_equal Developer.find_all_by_name('Jamis'), Developer.find_all_by_id(Developer.jamises)
+ end
end
@@ -43,6 +43,8 @@ def find_least_recent
has_many :audit_logs
+ named_scope :jamises, :conditions => {:name => 'Jamis'}
+
validates_inclusion_of :salary, :in => 50000..200000
validates_length_of :name, :within => 3..20

0 comments on commit 2092f26

Please sign in to comment.