Skip to content
This repository
Browse code

Reapply extensions when using except and only

  • Loading branch information...
commit b8ff5f0b672a06b040d8078bfdb14f1630913b11 1 parent 5ec7806
Iain Hecker iain authored tenderlove committed
6 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -83,6 +83,9 @@ def except(*skips)
83 83 result.send(:"#{method}_value=", send(:"#{method}_value"))
84 84 end
85 85
  86 + # Apply scope extension modules
  87 + result.send(:apply_modules, extensions)
  88 +
86 89 result
87 90 end
88 91
@@ -97,6 +100,9 @@ def only(*onlies)
97 100 result.send(:"#{method}_value=", send(:"#{method}_value"))
98 101 end
99 102
  103 + # Apply scope extension modules
  104 + result.send(:apply_modules, extensions)
  105 +
100 106 result
101 107 end
102 108
8 activerecord/test/cases/relations_test.rb
@@ -754,6 +754,10 @@ def test_except
754 754 assert_equal Post.all, all_posts.all
755 755 end
756 756
  757 + def test_extensions_with_except
  758 + assert_equal 2, Topic.named_extension.order(:author_name).except(:order).two
  759 + end
  760 +
757 761 def test_only
758 762 relation = Post.where(:author_id => 1).order('id ASC').limit(1)
759 763 assert_equal [posts(:welcome)], relation.all
@@ -765,6 +769,10 @@ def test_only
765 769 assert_equal Post.limit(1).all.first, all_posts.first
766 770 end
767 771
  772 + def test_extensions_with_only
  773 + assert_equal 2, Topic.named_extension.order(:author_name).only(:order).two
  774 + end
  775 +
768 776 def test_anonymous_extension
769 777 relation = Post.where(:author_id => 1).order('id ASC').extending do
770 778 def author

0 comments on commit b8ff5f0

Please sign in to comment.
Something went wrong with that request. Please try again.