提交 13547c16 编写于 作者: E Eric Allam 提交者: Aaron Patterson

fixes: ActiveRecord::Base.scopes includes all scopes defined in all subclasses

上级 5f1fc0c8
......@@ -102,10 +102,9 @@ def scoped(options = nil)
def scope(name, scope_options = {})
name = name.to_sym
valid_scope_name?(name)
extension = Module.new(&Proc.new) if block_given?
scopes[name] = lambda do |*args|
scope_proc = lambda do |*args|
options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options
relation = if options.is_a?(Hash)
......@@ -119,6 +118,8 @@ def scope(name, scope_options = {})
extension ? relation.extending(extension) : relation
end
self.scopes = self.scopes.merge name => scope_proc
singleton_class.send(:redefine_method, name, &scopes[name])
end
......
......@@ -64,6 +64,10 @@ def test_subclasses_inherit_scopes
assert Reply.scopes.include?(:base)
assert_equal Reply.find(:all), Reply.base
end
def test_classes_dont_inherit_subclasses_scopes
assert !ActiveRecord::Base.scopes.include?(:base)
end
def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
assert !Topic.find(:all, :conditions => {:approved => true}).empty?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册