Sha256: aeaec1c6f8f21720d033b6feab633e64e91e8590452f4bc0a237b9649b99df26

Contents?: true

Size: 1.93 KB

Versions: 19

Compression:

Stored size: 1.93 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-jdbcsqlserver-adapter-51.1.0 test/cases/showplan_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.1.0 test/cases/showplan_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.1 test/cases/showplan_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.0 test/cases/showplan_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.0.0 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.2.0.rc1 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.6 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.8 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.5 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.2 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.1 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.0 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.7 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.6 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.5 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.4 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.3 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.1 test/cases/showplan_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.0 test/cases/showplan_test_sqlserver.rb