aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/test/cases/adapters/sqlite3/explain_test.rb
blob: 2aec32258247dd0259c0ef871658f2dd4e47b219 (plain) (tree)
1
2
3
4
5
6
7
8
9

                          
                         



                           
                                                       
                            
 

                                                     
                                                                                                                   

                                                                                          
 

                                                                           
                                                                                                                   
                                                                                          
                                                                                                                             

                                                           



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

module ActiveRecord
  module ConnectionAdapters
    class SQLite3Adapter
      class ExplainTest < ActiveRecord::SQLite3TestCase
        fixtures :developers

        def test_explain_for_one_query
          explain = Developer.where(:id => 1).explain
          assert_match %(EXPLAIN for: SELECT "developers".* FROM "developers" WHERE "developers"."id" = ?), explain
          assert_match(/(SEARCH )?TABLE developers USING (INTEGER )?PRIMARY KEY/, explain)
        end

        def test_explain_with_eager_loading
          explain = Developer.where(:id => 1).includes(:audit_logs).explain
          assert_match %(EXPLAIN for: SELECT "developers".* FROM "developers" WHERE "developers"."id" = ?), explain
          assert_match(/(SEARCH )?TABLE developers USING (INTEGER )?PRIMARY KEY/, explain)
          assert_match %(EXPLAIN for: SELECT "audit_logs".* FROM "audit_logs" WHERE "audit_logs"."developer_id" = 1), explain
          assert_match(/(SCAN )?TABLE audit_logs/, explain)
        end
      end
    end
  end
end