aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-07 21:32:18 +0900
committerGitHub <noreply@github.com>2019-03-07 21:32:18 +0900
commit6746eea789f3285c66ee618c2786ff3c1ea64b45 (patch)
tree23c7c5265bbfacf7788e282831b329778fad2256 /activerecord
parent60c953c9715a116b17757fa6f5ee38ee3844f01e (diff)
parent8309706239769c429bbd323ba4d36d8ef10bb2f1 (diff)
downloadrails-6746eea789f3285c66ee618c2786ff3c1ea64b45.tar.gz
rails-6746eea789f3285c66ee618c2786ff3c1ea64b45.tar.bz2
rails-6746eea789f3285c66ee618c2786ff3c1ea64b45.zip
Merge pull request #35512 from kamipo/delegate_only
Delegate `only` query method to relation as with `except`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/querying.rb2
-rw-r--r--activerecord/test/cases/relation/delegation_test.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb4
3 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb
index 36e2134c46..7a8d0cb663 100644
--- a/activerecord/lib/active_record/querying.rb
+++ b/activerecord/lib/active_record/querying.rb
@@ -14,7 +14,7 @@ module ActiveRecord
:find_each, :find_in_batches, :in_batches,
:select, :reselect, :order, :reorder, :group, :limit, :offset, :joins, :left_joins, :left_outer_joins,
:where, :rewhere, :preload, :eager_load, :includes, :from, :lock, :readonly, :extending, :or,
- :having, :create_with, :distinct, :references, :none, :unscope, :merge, :except,
+ :having, :create_with, :distinct, :references, :none, :unscope, :merge, :except, :only,
:count, :average, :minimum, :maximum, :sum, :calculate,
:pluck, :pick, :ids
].freeze # :nodoc:
diff --git a/activerecord/test/cases/relation/delegation_test.rb b/activerecord/test/cases/relation/delegation_test.rb
index d04c409cb5..172fa20bc3 100644
--- a/activerecord/test/cases/relation/delegation_test.rb
+++ b/activerecord/test/cases/relation/delegation_test.rb
@@ -48,7 +48,7 @@ module ActiveRecord
ActiveRecord::Batches.public_instance_methods(false) +
ActiveRecord::Calculations.public_instance_methods(false) +
ActiveRecord::FinderMethods.public_instance_methods(false) - [:raise_record_not_found_exception!] +
- ActiveRecord::SpawnMethods.public_instance_methods(false) - [:spawn, :merge!, :only] +
+ ActiveRecord::SpawnMethods.public_instance_methods(false) - [:spawn, :merge!] +
ActiveRecord::QueryMethods.public_instance_methods(false).reject { |method|
method.to_s.end_with?("=", "!", "value", "values", "clause")
} - [:reverse_order, :arel, :extensions] + [
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