STI should not ignore type condition while applying scopes from parent class scopes

[#4507 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Neeraj Singh
2010-05-03 12:18:25 -04:00
committed by José Valim
parent bcf5fea5e5
commit 58adc67371
2 changed files with 6 additions and 5 deletions

View File

@@ -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)

View File

@@ -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?