mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove duplicated assertion in test_count_with_join
The queries both `res2` and `res3` are completely the same. And also, `assert_nothing_raised` is covered by following assertion.
This commit is contained in:
parent
934327e14e
commit
f232642879
1 changed files with 2 additions and 16 deletions
|
@ -1054,29 +1054,15 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
|
||||
def test_count_with_join
|
||||
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
|
||||
|
||||
res2 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
|
||||
assert_equal res, res2
|
||||
|
||||
res3 = nil
|
||||
assert_nothing_raised do
|
||||
res3 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
|
||||
end
|
||||
assert_equal res, res3
|
||||
|
||||
res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
|
||||
res5 = nil
|
||||
assert_nothing_raised do
|
||||
res5 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").count
|
||||
end
|
||||
|
||||
res5 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").count
|
||||
assert_equal res4, res5
|
||||
|
||||
res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
|
||||
res7 = nil
|
||||
assert_nothing_raised do
|
||||
res7 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").distinct.count
|
||||
end
|
||||
res7 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").distinct.count
|
||||
assert_equal res6, res7
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue