Sha256: 98824b955472729054664ea842519ddab2b4b76137161956d112a2dc263e5115

Contents?: true

Size: 1.94 KB

Versions: 19

Compression:

Stored size: 1.94 KB

Contents

require 'cases/helper_sqlserver'
require 'models/car'

class ShowplanTestSQLServer < ActiveRecord::TestCase

  fixtures :cars

  describe 'Unprepare previously prepared SQL' do

    it 'from simple statement' do
      plan = Car.where(id: 1).explain
      plan.must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1"
      plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
    end

    it 'from multiline statement' do
      plan = Car.where("\n id = 1 \n").explain
      plan.must_include "SELECT [cars].* FROM [cars] WHERE (\n id = 1 \n)"
      plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
    end

    it 'from prepared statement ...' do
      plan = Car.where(name: ',').limit(1).explain
      plan.must_include " SELECT  [cars].* FROM [cars] WHERE [cars].[name]"
      plan.must_include "TOP EXPRESSION", 'make sure we do not showplan the sp_executesql'
      plan.must_include "Clustered Index Scan", 'make sure we do not showplan the sp_executesql'
    end

  end

  describe 'With SHOWPLAN_TEXT option' do

    it 'use simple table printer' do
      with_showplan_option('SHOWPLAN_TEXT') do
        plan = Car.where(id: 1).explain
        plan.must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
        plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
      end
    end

  end

  describe 'With SHOWPLAN_XML option' do

    it 'show formatted xml' do
      with_showplan_option('SHOWPLAN_XML') do
        plan = Car.where(id: 1).explain
        plan.must_include 'ShowPlanXML'
      end
    end

  end


  private

  def with_showplan_option(option)
    old_option = ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option
    ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = option
    yield
  ensure
    ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = old_option
  end

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
activerecord-sqlserver-adapter-4.2.18 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.17 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.16 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter_new-4.2.15 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.15 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.13 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.12 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.11 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.10 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.9 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.8 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.6 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.5 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.4 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.3 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.2 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.1 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.0 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-4.2.0.pre test/cases/showplan_test_sqlserver.rb