mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add test case for arel_attribute
with a custom table
Since #29301, `arel_attribute` respects a custom table name.
This commit is contained in:
parent
48ef5e0ad5
commit
801ccab22a
2 changed files with 5 additions and 1 deletions
|
@ -1806,6 +1806,10 @@ class RelationTest < ActiveRecord::TestCase
|
||||||
assert_equal post, custom_post_relation.joins(:author).where!(title: post.title).take
|
assert_equal post, custom_post_relation.joins(:author).where!(title: post.title).take
|
||||||
end
|
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
|
test "#load" do
|
||||||
relation = Post.all
|
relation = Post.all
|
||||||
assert_queries(1) do
|
assert_queries(1) do
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
|
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
|
||||||
scope :titled_with_an_apostrophe, -> { where("title LIKE '%''%'") }
|
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 :limit_by, lambda { |l| limit(l) }
|
||||||
scope :locked, -> { lock }
|
scope :locked, -> { lock }
|
||||||
|
|
Loading…
Reference in a new issue