Skip to content

Commit

Permalink
Reapply extensions when using except and only
Browse files Browse the repository at this point in the history
  • Loading branch information
iain authored and tenderlove committed Mar 21, 2011
1 parent 5ec7806 commit b8ff5f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activerecord/lib/active_record/relation/spawn_methods.rb
Expand Up @@ -83,6 +83,9 @@ def except(*skips)
result.send(:"#{method}_value=", send(:"#{method}_value"))
end

# Apply scope extension modules
result.send(:apply_modules, extensions)

result
end

Expand All @@ -97,6 +100,9 @@ def only(*onlies)
result.send(:"#{method}_value=", send(:"#{method}_value"))
end

# Apply scope extension modules
result.send(:apply_modules, extensions)

result
end

Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -754,6 +754,10 @@ def test_except
assert_equal Post.all, all_posts.all
end

def test_extensions_with_except
assert_equal 2, Topic.named_extension.order(:author_name).except(:order).two
end

def test_only
relation = Post.where(:author_id => 1).order('id ASC').limit(1)
assert_equal [posts(:welcome)], relation.all
Expand All @@ -765,6 +769,10 @@ def test_only
assert_equal Post.limit(1).all.first, all_posts.first
end

def test_extensions_with_only
assert_equal 2, Topic.named_extension.order(:author_name).only(:order).two
end

def test_anonymous_extension
relation = Post.where(:author_id => 1).order('id ASC').extending do
def author
Expand Down

0 comments on commit b8ff5f0

Please sign in to comment.