Repository: rails/rails
File: activerecord/test/cases/finder_test.rb (Ruby)

Code before:
    end
  end

  test "#last for a model with composite query constraints" do
    quoted_type = Regexp.escape(quote_table_name("clothing_items.clothing_type"))
    quoted_color = Regexp.escape(quote_table_name("clothing_items.color"))

    assert_queries_match(/ORDER BY #{quoted_type} DESC, #{quoted_color} DESC LIMIT/i) do
      assert_kind_of ClothingItem, ClothingItem.last
    end
  end

  test "#first for a model with composite query constraints" do
    quoted_type = Regexp.escape(quote_table_name("clothing_items.clothing_type"))
    quoted_color = Regexp.escape(quote_table_name("clothing_items.color"))

    assert_queries_match(/ORDER BY #{quoted_type} ASC, #{quoted_color} ASC LIMIT/i) do
      assert_kind_of ClothingItem, ClothingItem.first
    end
  end

  test "#reverse_order for a model with composite query constraints" do
    quoted_type = Regexp.escape(quote_table_name("clothing_items.clothing_type"))
    quoted_color = Regexp.escape(quote_table_name("clothing_items.color"))

    assert_queries_match(/ORDER BY #{quoted_type} DESC, #{quoted_color} DESC LIMIT/i) do
      assert_kind_of ClothingItem, ClothingItem.all.reverse_order.first
    end
  end

  test "#find with a single composite primary key" do
    book = cpk_books(:cpk_great_author_first_book)

    assert_equal book, Cpk::Book.find(book.id)
  end

  test "find with a single composite primary key wrapped in an array" do
    book = cpk_books(:cpk_great_author_first_book)

    assert_equal [book], Cpk::Book.find([book.id])
  end

  test "find with a multiple sets of composite primary key" do
    books = [cpk_books(:cpk_great_author_first_book), cpk_books(:cpk_great_author_second_book)]
    ids = books.map(&:id)
    result = Cpk::Book.find(*ids)

    assert_equal ids, result.map(&:id)
  end

  test "find with a multiple sets of composite primary key wrapped in an array" do

Review comment (suggestion):
Without patch:

![Screenshot 2025-02-24 at 8 15 16 pm](https://github.com/user-attachments/assets/b493f251-2cfd-412e-ac8c-0c19fea17757)

The expected query is the same as `ClothingItem.last` tested above.

Code after:
    end
  end

  test "#last for a model with composite query constraints" do
    quoted_type = Regexp.escape(quote_table_name("clothing_items.clothing_type"))
    quoted_color = Regexp.escape(quote_table_name("clothing_items.color"))

    assert_queries_match(/ORDER BY #{quoted_type} DESC, #{quoted_color} DESC LIMIT/i) do
      assert_kind_of ClothingItem, ClothingItem.last
    end
  end

  test "#first for a model with composite query constraints" do
    quoted_type = Regexp.escape(quote_table_name("clothing_items.clothing_type"))
    quoted_color = Regexp.escape(quote_table_name("clothing_items.color"))

    assert_queries_match(/ORDER BY #{quoted_type} ASC, #{quoted_color} ASC LIMIT/i) do
      assert_kind_of ClothingItem, ClothingItem.first
    end
  end

  test "#find with a single composite primary key" do
    book = cpk_books(:cpk_great_author_first_book)

    assert_equal book, Cpk::Book.find(book.id)
  end

  test "find with a single composite primary key wrapped in an array" do
    book = cpk_books(:cpk_great_author_first_book)

    assert_equal [book], Cpk::Book.find([book.id])
  end

  test "find with a multiple sets of composite primary key" do
    books = [cpk_books(:cpk_great_author_first_book), cpk_books(:cpk_great_author_second_book)]
    ids = books.map(&:id)
    result = Cpk::Book.find(*ids)

    assert_equal ids, result.map(&:id)
  end

  test "find with a multiple sets of composite primary key wrapped in an array" do
    books = [cpk_books(:cpk_great_author_first_book), cpk_books(:cpk_great_author_second_book)]

    assert_equal books.map(&:id), Cpk::Book.where(revision: 1).find(books.map(&:id)).map(&:id)
  end

  test "find with a multiple sets of composite primary key wrapped in an array ordered" do
    books = [cpk_books(:cpk_great_author_first_book), cpk_books(:cpk_great_author_second_book)]

    assert_equal books.map(&:id), Cpk::Book.order(author_id: :asc).find(books.map(&:id)).map(&:id)