aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/statement_invalid_test.rb
blob: 16ea69c1bdd52e920ce0da429083f81a3cb6bf59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

require "cases/helper"
require "models/book"

module ActiveRecord
  class StatementInvalidTest < ActiveRecord::TestCase
    fixtures :books

    class MockDatabaseError < StandardError
      def result
        0
      end

      def error_number
        0
      end
    end

    test "message contains no sql" do
      sql = Book.where(author_id: 96, cover: "hard").to_sql
      error = assert_raises(ActiveRecord::StatementInvalid) do
        Book.connection.send(:log, sql, Book.name) do
          raise MockDatabaseError
        end
      end
      assert_not error.message.include?("SELECT")
    end

    test "statement and binds are set on select" do
      sql = Book.where(author_id: 96, cover: "hard").to_sql
      binds = [Minitest::Mock.new, Minitest::Mock.new]
      error = assert_raises(ActiveRecord::StatementInvalid) do
        Book.connection.send(:log, sql, Book.name, binds) do
          raise MockDatabaseError
        end
      end
      assert_equal error.sql, sql
      assert_equal error.binds, binds
    end
  end
end