aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-07 19:07:07 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-03-07 19:11:43 +0900
commit8309706239769c429bbd323ba4d36d8ef10bb2f1 (patch)
tree14cf578ac7c4eecb10492c7ee6c3a79ca4873ff1 /activerecord/test/cases/relations_test.rb
parenta88b6f257b7c0df816181ce2c36bb7ecb6487a17 (diff)
downloadrails-8309706239769c429bbd323ba4d36d8ef10bb2f1.tar.gz
rails-8309706239769c429bbd323ba4d36d8ef10bb2f1.tar.bz2
rails-8309706239769c429bbd323ba4d36d8ef10bb2f1.zip
Delegate `only` query method to relation as with `except`
I've found the skewness of delegation methods between `except` and `only` in a88b6f2. The `only` method is closely similar with `except` as `SpawnMethods`. https://github.com/rails/rails/blob/e056b9bfb07c4eb3bcc6672d885aadd72bec574f/activerecord/lib/active_record/relation/spawn_methods.rb#L53-L67 It is preferable both behaves the same way.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 85719cb8d0..36b4000018 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1503,9 +1503,11 @@ class RelationTest < ActiveRecord::TestCase
author_posts = relation.except(:order, :limit)
assert_equal Post.where(author_id: 1).sort_by(&:id), author_posts.sort_by(&:id)
+ assert_equal author_posts.sort_by(&:id), relation.scoping { Post.except(:order, :limit).sort_by(&:id) }
all_posts = relation.except(:where, :order, :limit)
assert_equal Post.all.sort_by(&:id), all_posts.sort_by(&:id)
+ assert_equal all_posts.sort_by(&:id), relation.scoping { Post.except(:where, :order, :limit).sort_by(&:id) }
end
def test_only
@@ -1514,9 +1516,11 @@ class RelationTest < ActiveRecord::TestCase
author_posts = relation.only(:where)
assert_equal Post.where(author_id: 1).sort_by(&:id), author_posts.sort_by(&:id)
+ assert_equal author_posts.sort_by(&:id), relation.scoping { Post.only(:where).sort_by(&:id) }
all_posts = relation.only(:order)
assert_equal Post.order("id ASC").to_a, all_posts.to_a
+ assert_equal all_posts.to_a, relation.scoping { Post.only(:order).to_a }
end
def test_anonymous_extension