aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/named_scope.rb6
-rw-r--r--activerecord/test/cases/named_scope_test.rb5
2 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index aeed52e72a..3d8f4a030b 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -99,11 +99,7 @@ module ActiveRecord
block_given? ? relation.extending(Module.new(&block)) : relation
end
- singleton_class.instance_eval do
- define_method name do |*args|
- scopes[name].call(*args)
- end
- end
+ singleton_class.send :define_method, name, &scopes[name]
end
def named_scope(*args, &block)
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index e4cafad11e..9db0e7c143 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -142,6 +142,11 @@ class NamedScopeTest < ActiveRecord::TestCase
assert_equal authors(:david).posts & Post.containing_the_letter_a, authors(:david).posts.containing_the_letter_a
end
+ def test_named_scope_with_STI
+ assert_equal 3,Post.containing_the_letter_a.count
+ assert_equal 1,SpecialPost.containing_the_letter_a.count
+ end
+
def test_has_many_through_associations_have_access_to_named_scopes
assert_not_equal Comment.containing_the_letter_e, authors(:david).comments
assert !Comment.containing_the_letter_e.empty?