Skip to content

ActiveRecord::Relation#except and #only loses scope extensions #231

Closed
wants to merge 1 commit into from
View
6 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -79,6 +79,9 @@ def except(*skips)
result.send(:"#{method}_value=", send(:"#{method}_value"))
end
+ # Apply scope extension modules
+ result.send(:apply_modules, extensions)
+
result
end
@@ -100,6 +103,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
@@ -797,6 +797,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
@@ -808,6 +812,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
Something went wrong with that request. Please try again.