提交 6a133765 编写于 作者: J jvoorhis 提交者: Pratik Naik

Methods invoked within named scope Procs should respect the scope stack. [#1267 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 c67d25e3
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册