|
| 1 | +require 'cases/helper_sqlserver' |
| 2 | +require 'models/post' |
| 3 | +require 'models/author' |
| 4 | + |
| 5 | +class InClauseTestSQLServer < ActiveRecord::TestCase |
| 6 | + fixtures :posts, :authors |
| 7 | + |
| 8 | + it 'removes ordering from subqueries' do |
| 9 | + authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name) |
| 10 | + posts = Post.where(author: authors_subquery) |
| 11 | + |
| 12 | + assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]" |
| 13 | + assert_not_includes posts.to_sql, "ORDER BY [authors].[name]" |
| 14 | + assert_equal 10, posts.length |
| 15 | + end |
| 16 | + |
| 17 | + it 'does not remove ordering from subquery that includes a limit' do |
| 18 | + authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name).limit(2) |
| 19 | + posts = Post.where(author: authors_subquery) |
| 20 | + |
| 21 | + assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]" |
| 22 | + assert_includes posts.to_sql, "ORDER BY [authors].[name]" |
| 23 | + assert_equal 7, posts.length |
| 24 | + end |
| 25 | + |
| 26 | + it 'does not remove ordering from subquery that includes an offset' do |
| 27 | + authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name).offset(1) |
| 28 | + posts = Post.where(author: authors_subquery) |
| 29 | + |
| 30 | + assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]" |
| 31 | + assert_includes posts.to_sql, "ORDER BY [authors].[name]" |
| 32 | + assert_equal 8, posts.length |
| 33 | + end |
| 34 | +end |
0 commit comments