aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/explain_test.rb
blob: 16fec94ede24f8062b3313480c5eda6ab32a9cb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

require "cases/helper"
require "models/developer"
require "models/computer"

class PostgreSQLExplainTest < ActiveRecord::PostgreSQLTestCase
  fixtures :developers

  def test_explain_for_one_query
    explain = Developer.where(id: 1).explain
    assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
    assert_match %(QUERY PLAN), explain
  end

  def test_explain_with_eager_loading
    explain = Developer.where(id: 1).includes(:audit_logs).explain
    assert_match %(QUERY PLAN), explain
    assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\$1 \[\["id", 1\]\]|1)), explain
    assert_match %r(EXPLAIN for: SELECT "audit_logs"\.\* FROM "audit_logs" WHERE "audit_logs"\."developer_id" = (?:\$1 \[\["developer_id", 1\]\]|1)), explain
  end
end