aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-27 13:25:14 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-27 13:25:14 +0900
commit801ccab22a8efc2611300a14a8b373a43aa0de28 (patch)
treebbf708272660796a96aa6be02994c349feec7643 /activerecord
parent48ef5e0ad500bdba706f10b65456f3b03b556212 (diff)
downloadrails-801ccab22a8efc2611300a14a8b373a43aa0de28.tar.gz
rails-801ccab22a8efc2611300a14a8b373a43aa0de28.tar.bz2
rails-801ccab22a8efc2611300a14a8b373a43aa0de28.zip
Add test case for `arel_attribute` with a custom table
Since #29301, `arel_attribute` respects a custom table name.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/relations_test.rb4
-rw-r--r--activerecord/test/models/post.rb2
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 6270533dc2..4edaf79e9a 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1806,6 +1806,10 @@ class RelationTest < ActiveRecord::TestCase
assert_equal post, custom_post_relation.joins(:author).where!(title: post.title).take
end
+ test "arel_attribute respects a custom table" do
+ assert_equal [posts(:welcome)], custom_post_relation.ranked_by_comments.limit_by(1).to_a
+ end
+
test "#load" do
relation = Post.all
assert_queries(1) do
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 4c8e847354..935a11e811 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -21,7 +21,7 @@ class Post < ActiveRecord::Base
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
scope :titled_with_an_apostrophe, -> { where("title LIKE '%''%'") }
- scope :ranked_by_comments, -> { order("comments_count DESC") }
+ scope :ranked_by_comments, -> { order(arel_attribute(:comments_count).desc) }
scope :limit_by, lambda { |l| limit(l) }
scope :locked, -> { lock }