Skip to content

Commit

Permalink
STI should not ignore type condition while applying scopes from paren…
Browse files Browse the repository at this point in the history
…t class scopes

[#4507 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed May 15, 2010
1 parent bcf5fea commit 58adc67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 1 addition & 5 deletions activerecord/lib/active_record/named_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ def scope(name, scope_options = {}, &block)
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)
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/named_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def test_has_many_associations_have_access_to_named_scopes
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?
Expand Down

0 comments on commit 58adc67

Please sign in to comment.