Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Methods invoked within named scope Procs should respect the scope sta…

…ck. [#1267 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 6a13376525f34a00e013fc3a6022838329dfe856 1 parent c67d25e
jvoorhis authored lifo committed
View
7 activerecord/lib/active_record/named_scope.rb
@@ -89,7 +89,12 @@ def named_scope(name, options = {}, &block)
when Hash
options
when Proc
- options.call(*args)
+ case parent_scope
+ when Scope
+ with_scope(:find => parent_scope.proxy_options) { options.call(*args) }
+ else
+ options.call(*args)
+ end
end, &block)
end
(class << self; self end).instance_eval do
View
4 activerecord/test/cases/named_scope_test.rb
@@ -306,6 +306,10 @@ def test_chanining_should_use_latest_conditions_when_searching
# Nested hash conditions with different keys
assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq
end
+
+ def test_methods_invoked_within_scopes_should_respect_scope
+ assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id]
+ end
end
class DynamicScopeMatchTest < ActiveRecord::TestCase
View
2  activerecord/test/models/topic.rb
@@ -33,6 +33,8 @@ def extension_two
end
named_scope :named_extension, :extend => NamedExtension
named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
+
+ named_scope :by_rejected_ids, lambda {{ :conditions => { :id => all(:conditions => {:approved => false}).map(&:id) } }}
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
serialize :content
Please sign in to comment.
Something went wrong with that request. Please try again.