From 7ac706aa7153290421bc1d63a0931aa58620318b Mon Sep 17 00:00:00 2001 From: Joseph Palermo Date: Tue, 28 Jul 2009 12:40:29 -0700 Subject: [PATCH] jp - named_scope test --- activerecord/test/cases/named_scope_test.rb | 4 ++++ activerecord/test/models/topic.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 92fe48c..26028de 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -358,6 +358,10 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id] end + def test_finds_inside_lambdas_should_not_use_chained_scopes + assert Topic.rejected.with_replies_using_find.include?(topics(:first)) + end + def test_named_scopes_batch_finders assert_equal 3, Topic.approved.count diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 201d96d..0e11ea9 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -38,6 +38,11 @@ class Topic < ActiveRecord::Base named_scope :by_rejected_ids, lambda {{ :conditions => { :id => all(:conditions => {:approved => false}).map(&:id) } }} + named_scope :with_replies_using_find, lambda { + ids = Topic.find(:all, :conditions => ['parent_id IS NOT NULL']).collect{|t| t.parent_id}.uniq + { :conditions => { :id => ids } } + } + has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" has_many :replies_with_primary_key, :class_name => "Reply", :dependent => :destroy, :primary_key => "title", :foreign_key => "parent_title" serialize :content -- 1.6.0.4