Skip to content

Commit c7cd293

Browse files
committed
EXPLAIN it to them!
1 parent 5a0ffa6 commit c7cd293

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

test/cases/showplan_test_sqlserver.rb

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,47 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
55

66
fixtures :cars
77

8-
context 'Unprepare previously prepared SQL' do
8+
describe 'Unprepare previously prepared SQL' do
99

10-
should 'from simple statement' do
10+
it 'from simple statement' do
1111
plan = Car.where(id: 1).explain
12-
assert plan.starts_with?("EXPLAIN for: SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1")
13-
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
12+
plan.must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1"
13+
plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
1414
end
1515

16-
should 'from multiline statement' do
16+
it 'from multiline statement' do
1717
plan = Car.where("\n id = 1 \n").explain
18-
assert plan.starts_with?("EXPLAIN for: SELECT [cars].* FROM [cars] WHERE (\n id = 1 \n)")
19-
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
18+
plan.must_include "SELECT [cars].* FROM [cars] WHERE (\n id = 1 \n)"
19+
plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
2020
end
2121

22-
should 'from prepared statement ...' do
22+
it 'from prepared statement ...' do
2323
plan = Car.where(name: ',').limit(1).explain
24-
assert plan.include?("SELECT TOP (1) [cars].* FROM [cars] WHERE [cars].[name] = N','")
25-
assert plan.include?("TOP EXPRESSION"), 'make sure we do not showplan the sp_executesql'
26-
assert plan.include?("Clustered Index Scan"), 'make sure we do not showplan the sp_executesql'
24+
plan.must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name]"
25+
plan.must_include "TOP EXPRESSION", 'make sure we do not showplan the sp_executesql'
26+
plan.must_include "Clustered Index Scan", 'make sure we do not showplan the sp_executesql'
2727
end
2828

2929
end
3030

31-
context 'With SHOWPLAN_TEXT option' do
31+
describe 'With SHOWPLAN_TEXT option' do
3232

33-
should 'use simple table printer' do
33+
it 'use simple table printer' do
3434
with_showplan_option('SHOWPLAN_TEXT') do
3535
plan = Car.where(id: 1).explain
36-
assert plan.starts_with?("EXPLAIN for: SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1")
37-
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
36+
plan.must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
37+
plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
3838
end
3939
end
4040

4141
end
4242

43-
context 'With SHOWPLAN_XML option' do
43+
describe 'With SHOWPLAN_XML option' do
4444

45-
should 'show formatted xml' do
45+
it 'show formatted xml' do
4646
with_showplan_option('SHOWPLAN_XML') do
4747
plan = Car.where(id: 1).explain
48-
assert plan.include?('ShowPlanXML')
48+
plan.must_include 'ShowPlanXML'
4949
end
5050
end
5151

@@ -54,14 +54,6 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
5454

5555
private
5656

57-
def base
58-
ActiveRecord::Base
59-
end
60-
61-
def connection
62-
base.connection
63-
end
64-
6557
def with_showplan_option(option)
6658
old_option = ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option
6759
ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = option

0 commit comments

Comments
 (0)