Browse files

Reapply extensions when using except and only

  • Loading branch information...
1 parent 5ec7806 commit b8ff5f0b672a06b040d8078bfdb14f1630913b11 @iain iain committed with tenderlove Mar 19, 2011
View
6 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -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
@@ -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
View
8 activerecord/test/cases/relations_test.rb
@@ -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
@@ -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

0 comments on commit b8ff5f0

Please sign in to comment.