Sha256: 4eff0d383772eb99b719c5330b84cb86ec13ad1d08600055fda09f5eff7d5d6e

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "cases/helper_sqlserver"
require "models/post"
require "models/author"

class InClauseTestSQLServer < ActiveRecord::TestCase
  fixtures :posts, :authors

  it "removes ordering from subqueries" do
    authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name)
    posts = Post.where(author: authors_subquery)

    assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
    assert_not_includes posts.to_sql, "ORDER BY [authors].[name]"
    assert_equal 10, posts.length
  end

  it "does not remove ordering from subquery that includes a limit" do
    authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name).limit(2)
    posts = Post.where(author: authors_subquery)

    assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
    assert_includes posts.to_sql, "ORDER BY [authors].[name]"
    assert_equal 7, posts.length
  end

  it "does not remove ordering from subquery that includes an offset" do
    authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name).offset(1)
    posts = Post.where(author: authors_subquery)

    assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
    assert_includes posts.to_sql, "ORDER BY [authors].[name]"
    assert_equal 8, posts.length
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-6.0.3 test/cases/in_clause_test_sqlserver.rb
activerecord-sqlserver-adapter-6.0.2 test/cases/in_clause_test_sqlserver.rb
activerecord-sqlserver-adapter-6.0.1 test/cases/in_clause_test_sqlserver.rb
activerecord-sqlserver-adapter-6.0.0 test/cases/in_clause_test_sqlserver.rb
activerecord-sqlserver-adapter-6.0.0.rc2 test/cases/in_clause_test_sqlserver.rb