Skip to content

Commit c5a859f

Browse files
committed
Pass a few more tests.
1 parent 7d0a082 commit c5a859f

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

test/cases/coerced_tests.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ class RelationTest < ActiveRecord::TestCase
320320
# We are not doing order duplicate removal anymore.
321321
coerce_tests! :test_order_using_scoping
322322

323+
# Account for our `EXEC sp_executesql...` statements.
324+
coerce_tests! :test_to_sql_on_eager_join
325+
def test_to_sql_on_eager_join_coerced
326+
expected = assert_sql { Post.eager_load(:last_comment).order('comments.id DESC').to_a }.first
327+
actual = Post.eager_load(:last_comment).order('comments.id DESC').to_sql
328+
actual = "EXEC sp_executesql N'#{ActiveRecord::ConnectionAdapters::SQLServer::Utils.quote_string(actual)}'"
329+
assert_equal expected, actual
330+
end
331+
323332
end
324333

325334

@@ -351,7 +360,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
351360
coerce_tests! :test_schema_dump_keeps_large_precision_integer_columns_as_decimal
352361
def test_schema_dump_keeps_large_precision_integer_columns_as_decimal_coerced
353362
output = standard_dump
354-
assert_match %r{t.integer\s+"atoms_in_universe",\s+precision: 38}, output
363+
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 38}, output
355364
end
356365

357366
# This accidently returns the wrong number because of our tables too.

test/cases/helper_sqlserver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
module ActiveRecord
1111
class TestCase < ActiveSupport::TestCase
1212

13+
SQLServer = ActiveRecord::ConnectionAdapters::SQLServer
14+
1315
include ARTest::SQLServer::CoerceableTest
1416

1517
let(:logger) { ActiveRecord::Base.logger }

test/cases/utils_test_sqlserver.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
class UtilsTestSQLServer < ActiveRecord::TestCase
44

5-
Utils = ActiveRecord::ConnectionAdapters::SQLServer::Utils
6-
75
it '.quote_string' do
8-
Utils.quote_string("I'll store this in C:\\Users").must_equal "I''ll store this in C:\\Users"
6+
SQLServer::Utils.quote_string("I'll store this in C:\\Users").must_equal "I''ll store this in C:\\Users"
97
end
108

119
it '.unquote_string' do
12-
Utils.unquote_string("I''ll store this in C:\\Users").must_equal "I'll store this in C:\\Users"
10+
SQLServer::Utils.unquote_string("I''ll store this in C:\\Users").must_equal "I'll store this in C:\\Users"
1311
end
1412

1513
describe '.extract_identifiers constructor and thus SQLServer::Utils::Name value object' do
@@ -44,7 +42,7 @@ class UtilsTestSQLServer < ActiveRecord::TestCase
4442

4543
it 'extracts and returns #object identifier unquoted by default or quoted as needed' do
4644
valid_names.each do |n|
47-
name = Utils.extract_identifiers(n)
45+
name = SQLServer::Utils.extract_identifiers(n)
4846
name.object.must_equal 'object', "With #{n.inspect} for #object"
4947
name.object_quoted.must_equal '[object]', "With #{n.inspect} for #object_quoted"
5048
end
@@ -55,12 +53,12 @@ class UtilsTestSQLServer < ActiveRecord::TestCase
5553
it "extracts and returns #{part} identifier unquoted by default or quoted as needed" do
5654
present, blank = send(:"#{part}_names")
5755
present.each do |n|
58-
name = Utils.extract_identifiers(n)
56+
name = SQLServer::Utils.extract_identifiers(n)
5957
name.send(:"#{part}").must_equal "#{part}", "With #{n.inspect} for ##{part} method"
6058
name.send(:"#{part}_quoted").must_equal "[#{part}]", "With #{n.inspect} for ##{part}_quoted method"
6159
end
6260
blank.each do |n|
63-
name = Utils.extract_identifiers(n)
61+
name = SQLServer::Utils.extract_identifiers(n)
6462
name.send(:"#{part}").must_be_nil "With #{n.inspect} for ##{part} method"
6563
name.send(:"#{part}_quoted").must_be_nil "With #{n.inspect} for ##{part}_quoted method"
6664
end
@@ -69,23 +67,23 @@ class UtilsTestSQLServer < ActiveRecord::TestCase
6967
end
7068

7169
it 'does not blow up on nil or blank string name' do
72-
Utils.extract_identifiers(nil).object.must_be_nil
73-
Utils.extract_identifiers(' ').object.must_be_nil
70+
SQLServer::Utils.extract_identifiers(nil).object.must_be_nil
71+
SQLServer::Utils.extract_identifiers(' ').object.must_be_nil
7472
end
7573

7674
it 'has a #quoted that returns a fully quoted name with all identifiers as orginially passed in' do
77-
Utils.extract_identifiers('object').quoted.must_equal '[object]'
78-
Utils.extract_identifiers('server.database..object').quoted.must_equal '[server].[database]..[object]'
79-
Utils.extract_identifiers('[server]...[object]').quoted.must_equal '[server]...[object]'
75+
SQLServer::Utils.extract_identifiers('object').quoted.must_equal '[object]'
76+
SQLServer::Utils.extract_identifiers('server.database..object').quoted.must_equal '[server].[database]..[object]'
77+
SQLServer::Utils.extract_identifiers('[server]...[object]').quoted.must_equal '[server]...[object]'
8078
end
8179

8280
it 'can take a symbol argument' do
83-
Utils.extract_identifiers(:object).object.must_equal 'object'
81+
SQLServer::Utils.extract_identifiers(:object).object.must_equal 'object'
8482
end
8583

8684
it 'allows identifiers with periods to work' do
87-
Utils.extract_identifiers('[obj.name]').quoted.must_equal '[obj.name]'
88-
Utils.extract_identifiers('[obj.name].[foo]').quoted.must_equal '[obj.name].[foo]'
85+
SQLServer::Utils.extract_identifiers('[obj.name]').quoted.must_equal '[obj.name]'
86+
SQLServer::Utils.extract_identifiers('[obj.name].[foo]').quoted.must_equal '[obj.name].[foo]'
8987
end
9088

9189
end

test/support/sql_counter_sqlserver.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def ignored_sql
1010
/INFORMATION_SCHEMA\.(TABLES|VIEWS|COLUMNS)/,
1111
/SELECT @@version/,
1212
/SELECT @@TRANCOUNT/,
13-
/(BEGIN|COMMIT|ROLLBACK|SAVE) TRANSACTION/ ]
13+
/(BEGIN|COMMIT|ROLLBACK|SAVE) TRANSACTION/,
14+
/SELECT CAST\(.* AS .*\) AS value/ ]
1415
end
1516

1617
def sql_counter_listenters

0 commit comments

Comments
 (0)