Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes: ActiveRecord::Base.scopes includes all scopes defined in all s…

…ubclasses
  • Loading branch information...
commit 13547c16d97b5f52db11d9f48704bbea20b54a4c 1 parent 5f1fc0c
Eric Allam ericallam authored tenderlove committed
5 activerecord/lib/active_record/named_scope.rb
View
@@ -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
4 activerecord/test/cases/named_scope_test.rb
View
@@ -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?
Please sign in to comment.
Something went wrong with that request. Please try again.