activerecord-sqlserver-adapter 6.0.0.rc1 → 6.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +29 -0
  4. data/CHANGELOG.md +20 -0
  5. data/Gemfile +11 -5
  6. data/Guardfile +9 -8
  7. data/Rakefile +12 -16
  8. data/VERSION +1 -1
  9. data/activerecord-sqlserver-adapter.gemspec +3 -3
  10. data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +0 -4
  11. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -4
  12. data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +3 -4
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -3
  14. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +2 -3
  15. data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +2 -3
  16. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +35 -32
  17. data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +7 -12
  18. data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -3
  19. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +8 -8
  20. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +0 -2
  21. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +7 -7
  22. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +106 -103
  23. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +6 -8
  24. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
  25. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
  26. data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +0 -2
  27. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +1 -4
  28. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -8
  29. data/lib/active_record/connection_adapters/sqlserver/type.rb +35 -35
  30. data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +0 -2
  31. data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +0 -2
  32. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +0 -2
  33. data/lib/active_record/connection_adapters/sqlserver/type/char.rb +2 -2
  34. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +0 -2
  35. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +2 -3
  36. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +2 -3
  37. data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +0 -2
  38. data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +0 -2
  39. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +0 -2
  40. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +0 -2
  41. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +0 -2
  42. data/lib/active_record/connection_adapters/sqlserver/type/json.rb +0 -1
  43. data/lib/active_record/connection_adapters/sqlserver/type/money.rb +0 -2
  44. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +0 -2
  45. data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +0 -2
  46. data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +0 -2
  47. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +0 -2
  48. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +0 -2
  49. data/lib/active_record/connection_adapters/sqlserver/type/text.rb +0 -2
  50. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +2 -3
  51. data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +6 -9
  52. data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +0 -2
  53. data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +0 -2
  54. data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +1 -3
  55. data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +0 -2
  56. data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +0 -2
  57. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +0 -2
  58. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +0 -2
  59. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +1 -2
  60. data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +1 -3
  61. data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +0 -2
  62. data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +1 -3
  63. data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +0 -2
  64. data/lib/active_record/connection_adapters/sqlserver/utils.rb +8 -11
  65. data/lib/active_record/connection_adapters/sqlserver/version.rb +0 -2
  66. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +85 -83
  67. data/lib/active_record/connection_adapters/sqlserver_column.rb +0 -2
  68. data/lib/active_record/sqlserver_base.rb +1 -1
  69. data/lib/active_record/tasks/sqlserver_database_tasks.rb +26 -32
  70. data/lib/activerecord-sqlserver-adapter.rb +1 -1
  71. data/lib/arel/visitors/sqlserver.rb +18 -14
  72. data/lib/arel_sqlserver.rb +2 -2
  73. data/test/cases/adapter_test_sqlserver.rb +161 -182
  74. data/test/cases/change_column_null_test_sqlserver.rb +12 -12
  75. data/test/cases/coerced_tests.rb +88 -270
  76. data/test/cases/column_test_sqlserver.rb +281 -283
  77. data/test/cases/connection_test_sqlserver.rb +15 -20
  78. data/test/cases/execute_procedure_test_sqlserver.rb +18 -20
  79. data/test/cases/fetch_test_sqlserver.rb +14 -22
  80. data/test/cases/fully_qualified_identifier_test_sqlserver.rb +12 -18
  81. data/test/cases/helper_sqlserver.rb +13 -15
  82. data/test/cases/in_clause_test_sqlserver.rb +9 -9
  83. data/test/cases/index_test_sqlserver.rb +13 -15
  84. data/test/cases/json_test_sqlserver.rb +23 -25
  85. data/test/cases/migration_test_sqlserver.rb +22 -28
  86. data/test/cases/order_test_sqlserver.rb +51 -54
  87. data/test/cases/pessimistic_locking_test_sqlserver.rb +25 -33
  88. data/test/cases/rake_test_sqlserver.rb +31 -45
  89. data/test/cases/schema_dumper_test_sqlserver.rb +104 -108
  90. data/test/cases/schema_test_sqlserver.rb +18 -26
  91. data/test/cases/scratchpad_test_sqlserver.rb +2 -4
  92. data/test/cases/showplan_test_sqlserver.rb +24 -33
  93. data/test/cases/specific_schema_test_sqlserver.rb +66 -65
  94. data/test/cases/transaction_test_sqlserver.rb +16 -19
  95. data/test/cases/trigger_test_sqlserver.rb +12 -12
  96. data/test/cases/utils_test_sqlserver.rb +68 -70
  97. data/test/cases/uuid_test_sqlserver.rb +11 -13
  98. data/test/debug.rb +6 -6
  99. data/test/migrations/create_clients_and_change_column_null.rb +1 -1
  100. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +2 -4
  101. data/test/models/sqlserver/booking.rb +1 -1
  102. data/test/models/sqlserver/customers_view.rb +1 -1
  103. data/test/models/sqlserver/dollar_table_name.rb +1 -1
  104. data/test/models/sqlserver/edge_schema.rb +1 -3
  105. data/test/models/sqlserver/fk_has_fk.rb +1 -1
  106. data/test/models/sqlserver/fk_has_pk.rb +1 -1
  107. data/test/models/sqlserver/natural_pk_data.rb +2 -2
  108. data/test/models/sqlserver/natural_pk_int_data.rb +1 -1
  109. data/test/models/sqlserver/no_pk_data.rb +1 -1
  110. data/test/models/sqlserver/object_default.rb +1 -1
  111. data/test/models/sqlserver/quoted_table.rb +2 -2
  112. data/test/models/sqlserver/quoted_view_1.rb +1 -1
  113. data/test/models/sqlserver/quoted_view_2.rb +1 -1
  114. data/test/models/sqlserver/sst_memory.rb +1 -1
  115. data/test/models/sqlserver/string_default.rb +1 -1
  116. data/test/models/sqlserver/string_defaults_big_view.rb +1 -1
  117. data/test/models/sqlserver/string_defaults_view.rb +1 -1
  118. data/test/models/sqlserver/tinyint_pk.rb +1 -1
  119. data/test/models/sqlserver/trigger.rb +2 -2
  120. data/test/models/sqlserver/trigger_history.rb +1 -1
  121. data/test/models/sqlserver/upper.rb +1 -1
  122. data/test/models/sqlserver/uppered.rb +1 -1
  123. data/test/models/sqlserver/uuid.rb +1 -1
  124. data/test/schema/sqlserver_specific_schema.rb +20 -22
  125. data/test/support/coerceable_test_sqlserver.rb +1 -4
  126. data/test/support/connection_reflection.rb +1 -2
  127. data/test/support/core_ext/query_cache.rb +1 -1
  128. data/test/support/load_schema_sqlserver.rb +3 -5
  129. data/test/support/minitest_sqlserver.rb +1 -1
  130. data/test/support/paths_sqlserver.rb +9 -11
  131. data/test/support/rake_helpers.rb +12 -10
  132. data/test/support/sql_counter_sqlserver.rb +0 -4
  133. data/test/support/test_in_memory_oltp.rb +7 -7
  134. metadata +5 -4
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
4
- require 'models/reply'
5
- require 'models/topic'
3
+ require "cases/helper_sqlserver"
4
+ require "models/reply"
5
+ require "models/topic"
6
6
 
7
7
  class ConnectionTestSQLServer < ActiveRecord::TestCase
8
-
9
8
  self.use_transactional_tests = false
10
9
 
11
10
  fixtures :topics, :accounts
@@ -15,7 +14,7 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
15
14
  assert connection.active?
16
15
  end
17
16
 
18
- it 'affect rows' do
17
+ it "affect rows" do
19
18
  topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
20
19
  updated = Topic.update(topic_data.keys, topic_data.values)
21
20
  assert_equal 2, updated.size
@@ -24,43 +23,40 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
24
23
  assert_equal 2, Topic.delete([1, 2])
25
24
  end
26
25
 
27
- it 'allow usage of :database connection option to remove setting from dsn' do
28
- assert_equal 'activerecord_unittest', connection.current_database
26
+ it "allow usage of :database connection option to remove setting from dsn" do
27
+ assert_equal "activerecord_unittest", connection.current_database
29
28
  begin
30
- connection.use_database('activerecord_unittest2')
31
- assert_equal 'activerecord_unittest2', connection.current_database
29
+ connection.use_database("activerecord_unittest2")
30
+ assert_equal "activerecord_unittest2", connection.current_database
32
31
  ensure
33
32
  connection.use_database
34
- assert_equal 'activerecord_unittest', connection.current_database, 'Would default back to connection options'
33
+ assert_equal "activerecord_unittest", connection.current_database, "Would default back to connection options"
35
34
  end
36
35
  end unless connection_sqlserver_azure?
37
36
 
38
- describe 'Connection management' do
39
-
40
- it 'set spid on connect' do
41
- _(['Fixnum', 'Integer']).must_include connection.spid.class.name
37
+ describe "Connection management" do
38
+ it "set spid on connect" do
39
+ _(["Fixnum", "Integer"]).must_include connection.spid.class.name
42
40
  end
43
41
 
44
- it 'reset spid on disconnect!' do
42
+ it "reset spid on disconnect!" do
45
43
  connection.disconnect!
46
44
  assert connection.spid.nil?
47
45
  end
48
46
 
49
- it 'reset the connection' do
47
+ it "reset the connection" do
50
48
  connection.disconnect!
51
49
  _(connection.raw_connection).must_be_nil
52
50
  end
53
51
 
54
- it 'be able to disconnect and reconnect at will' do
52
+ it "be able to disconnect and reconnect at will" do
55
53
  disconnect_raw_connection!
56
54
  assert !connection.active?
57
55
  connection.reconnect!
58
56
  assert connection.active?
59
57
  end
60
-
61
58
  end
62
59
 
63
-
64
60
  private
65
61
 
66
62
  def disconnect_raw_connection!
@@ -69,5 +65,4 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
69
65
  connection.raw_connection.close rescue nil
70
66
  end
71
67
  end
72
-
73
68
  end
@@ -1,46 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
3
+ require "cases/helper_sqlserver"
4
4
 
5
5
  class ExecuteProcedureTestSQLServer < ActiveRecord::TestCase
6
-
7
- it 'execute a simple procedure' do
6
+ it "execute a simple procedure" do
8
7
  tables = ActiveRecord::Base.execute_procedure :sp_tables
9
8
  assert_instance_of Array, tables
10
9
  assert tables.first.respond_to?(:keys)
11
10
  end
12
11
 
13
- it 'take parameter arguments' do
14
- tables = ActiveRecord::Base.execute_procedure :sp_tables, 'sst_datatypes'
12
+ it "take parameter arguments" do
13
+ tables = ActiveRecord::Base.execute_procedure :sp_tables, "sst_datatypes"
15
14
  table_info = tables.first
16
15
  assert_equal 1, tables.size
17
- assert_equal (ENV['ARUNIT_DB_NAME'] || 'activerecord_unittest'), table_info['TABLE_QUALIFIER'], "Table Info: #{table_info.inspect}"
18
- assert_equal 'TABLE', table_info['TABLE_TYPE'], "Table Info: #{table_info.inspect}"
16
+ assert_equal (ENV["ARUNIT_DB_NAME"] || "activerecord_unittest"), table_info["TABLE_QUALIFIER"], "Table Info: #{table_info.inspect}"
17
+ assert_equal "TABLE", table_info["TABLE_TYPE"], "Table Info: #{table_info.inspect}"
19
18
  end
20
19
 
21
- it 'allow multiple result sets to be returned' do
22
- results1, results2 = ActiveRecord::Base.execute_procedure('sp_helpconstraint','accounts')
20
+ it "allow multiple result sets to be returned" do
21
+ results1, results2 = ActiveRecord::Base.execute_procedure("sp_helpconstraint", "accounts")
23
22
  assert_instance_of Array, results1
24
23
  assert results1.first.respond_to?(:keys)
25
- assert results1.first['Object Name']
24
+ assert results1.first["Object Name"]
26
25
  assert_instance_of Array, results2
27
26
  assert results2.first.respond_to?(:keys)
28
- assert results2.first['constraint_name']
29
- assert results2.first['constraint_type']
27
+ assert results2.first["constraint_name"]
28
+ assert results2.first["constraint_type"]
30
29
  end
31
30
 
32
- it 'take named parameter arguments' do
33
- tables = ActiveRecord::Base.execute_procedure :sp_tables, table_name: 'tables', table_owner: 'sys'
31
+ it "take named parameter arguments" do
32
+ tables = ActiveRecord::Base.execute_procedure :sp_tables, table_name: "tables", table_owner: "sys"
34
33
  table_info = tables.first
35
34
  assert_equal 1, tables.size
36
- assert_equal (ENV['ARUNIT_DB_NAME'] || 'activerecord_unittest'), table_info['TABLE_QUALIFIER'], "Table Info: #{table_info.inspect}"
37
- assert_equal 'VIEW', table_info['TABLE_TYPE'], "Table Info: #{table_info.inspect}"
35
+ assert_equal (ENV["ARUNIT_DB_NAME"] || "activerecord_unittest"), table_info["TABLE_QUALIFIER"], "Table Info: #{table_info.inspect}"
36
+ assert_equal "VIEW", table_info["TABLE_TYPE"], "Table Info: #{table_info.inspect}"
38
37
  end
39
38
 
40
- it 'uses the proper timezone' do
41
- date_proc = connection.execute_procedure('my_getutcdate').first['utcdate']
42
- date_base = connection.select_value('select GETUTCDATE()')
39
+ it "uses the proper timezone" do
40
+ date_proc = connection.execute_procedure("my_getutcdate").first["utcdate"]
41
+ date_base = connection.select_value("select GETUTCDATE()")
43
42
  assert_equal date_base.change(usec: 0), date_proc.change(usec: 0)
44
43
  end
45
-
46
44
  end
@@ -1,22 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
4
- require 'models/book'
3
+ require "cases/helper_sqlserver"
4
+ require "models/book"
5
5
 
6
6
  class FetchTestSqlserver < ActiveRecord::TestCase
7
-
8
7
  let(:books) { @books }
9
8
 
10
9
  before { create_10_books }
11
10
 
12
- it 'work with fully qualified table and columns in select' do
13
- books = Book.select('books.id, books.name').limit(3).offset(5)
14
- assert_equal Book.all[5,3].map(&:id), books.map(&:id)
11
+ it "work with fully qualified table and columns in select" do
12
+ books = Book.select("books.id, books.name").limit(3).offset(5)
13
+ assert_equal Book.all[5, 3].map(&:id), books.map(&:id)
15
14
  end
16
15
 
17
- describe 'count' do
18
-
19
- it 'gauntlet' do
16
+ describe "count" do
17
+ it "gauntlet" do
20
18
  books[0].destroy
21
19
  books[1].destroy
22
20
  books[2].destroy
@@ -31,29 +29,23 @@ class FetchTestSqlserver < ActiveRecord::TestCase
31
29
  assert_equal 0, Book.limit(3).offset(7).count
32
30
  assert_equal 0, Book.limit(3).offset(8).count
33
31
  end
34
-
35
32
  end
36
33
 
37
- describe 'order' do
38
-
39
- it 'gauntlet' do
40
- Book.where(name:'Name-10').delete_all
41
- _(Book.order(:name).limit(1).offset(1).map(&:name)).must_equal ['Name-2']
42
- _(Book.order(:name).limit(2).offset(2).map(&:name)).must_equal ['Name-3', 'Name-4']
43
- _(Book.order(:name).limit(2).offset(7).map(&:name)).must_equal ['Name-8', 'Name-9']
44
- _(Book.order(:name).limit(3).offset(7).map(&:name)).must_equal ['Name-8', 'Name-9']
34
+ describe "order" do
35
+ it "gauntlet" do
36
+ Book.where(name: "Name-10").delete_all
37
+ _(Book.order(:name).limit(1).offset(1).map(&:name)).must_equal ["Name-2"]
38
+ _(Book.order(:name).limit(2).offset(2).map(&:name)).must_equal ["Name-3", "Name-4"]
39
+ _(Book.order(:name).limit(2).offset(7).map(&:name)).must_equal ["Name-8", "Name-9"]
40
+ _(Book.order(:name).limit(3).offset(7).map(&:name)).must_equal ["Name-8", "Name-9"]
45
41
  _(Book.order(:name).limit(3).offset(9).map(&:name)).must_equal []
46
42
  end
47
-
48
43
  end
49
44
 
50
-
51
45
  protected
52
46
 
53
47
  def create_10_books
54
48
  Book.delete_all
55
49
  @books = (1..10).map { |i| Book.create! name: "Name-#{i}" }
56
50
  end
57
-
58
51
  end
59
-
@@ -1,21 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
3
+ require "cases/helper_sqlserver"
4
4
 
5
5
  class FullyQualifiedIdentifierTestSQLServer < ActiveRecord::TestCase
6
-
7
- describe 'local server' do
8
-
9
- it 'should use table name in select projections' do
6
+ describe "local server" do
7
+ it "should use table name in select projections" do
10
8
  table = Arel::Table.new(:table)
11
9
  expected_sql = "SELECT [table].[name] FROM [table]"
12
10
  assert_equal expected_sql, table.project(table[:name]).to_sql
13
11
  end
14
-
15
12
  end
16
13
 
17
- describe 'remote server' do
18
-
14
+ describe "remote server" do
19
15
  before do
20
16
  connection_options[:database_prefix] = "[my.server].db.schema."
21
17
  end
@@ -24,39 +20,39 @@ class FullyQualifiedIdentifierTestSQLServer < ActiveRecord::TestCase
24
20
  connection_options.delete :database_prefix
25
21
  end
26
22
 
27
- it 'should use fully qualified table name in select from clause' do
23
+ it "should use fully qualified table name in select from clause" do
28
24
  table = Arel::Table.new(:table)
29
25
  expected_sql = "SELECT * FROM [my.server].[db].[schema].[table]"
30
26
  assert_equal expected_sql, table.project(Arel.star).to_sql
31
27
  end
32
28
 
33
- it 'should not use fully qualified table name in select projections' do
29
+ it "should not use fully qualified table name in select projections" do
34
30
  table = Arel::Table.new(:table)
35
31
  expected_sql = "SELECT [table].[name] FROM [my.server].[db].[schema].[table]"
36
32
  assert_equal expected_sql, table.project(table[:name]).to_sql
37
33
  end
38
34
 
39
- it 'should not use fully qualified table name in where clause' do
35
+ it "should not use fully qualified table name in where clause" do
40
36
  table = Arel::Table.new(:table)
41
37
  expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
42
38
  quietly { assert_equal expected_sql, table.project(Arel.star).where(table[:id].eq(42)).to_sql }
43
39
  end
44
40
 
45
- it 'should not use fully qualified table name in order clause' do
41
+ it "should not use fully qualified table name in order clause" do
46
42
  table = Arel::Table.new(:table)
47
43
  expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] ORDER BY [table].[name]"
48
44
  assert_equal expected_sql, table.project(Arel.star).order(table[:name]).to_sql
49
45
  end
50
46
 
51
- it 'should use fully qualified table name in insert statement' do
47
+ it "should use fully qualified table name in insert statement" do
52
48
  manager = Arel::InsertManager.new
53
49
  manager.into Arel::Table.new(:table)
54
- manager.values = manager.create_values [Arel.sql('*')]
50
+ manager.values = manager.create_values [Arel.sql("*")]
55
51
  expected_sql = "INSERT INTO [my.server].[db].[schema].[table] VALUES (*)"
56
52
  quietly { assert_equal expected_sql, manager.to_sql }
57
53
  end
58
54
 
59
- it 'should use fully qualified table name in update statement' do
55
+ it "should use fully qualified table name in update statement" do
60
56
  table = Arel::Table.new(:table)
61
57
  manager = Arel::UpdateManager.new
62
58
  manager.table(table).where(table[:id].eq(42))
@@ -65,14 +61,12 @@ class FullyQualifiedIdentifierTestSQLServer < ActiveRecord::TestCase
65
61
  quietly { assert_equal expected_sql, manager.to_sql }
66
62
  end
67
63
 
68
- it 'should use fully qualified table name in delete statement' do
64
+ it "should use fully qualified table name in delete statement" do
69
65
  table = Arel::Table.new(:table)
70
66
  manager = Arel::DeleteManager.new
71
67
  manager.from(table).where(table[:id].eq(42))
72
68
  expected_sql = "DELETE FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
73
69
  quietly { assert_equal expected_sql, manager.to_sql }
74
70
  end
75
-
76
71
  end
77
-
78
72
  end
@@ -1,22 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'support/paths_sqlserver'
4
- require 'bundler/setup'
3
+ require "support/paths_sqlserver"
4
+ require "bundler/setup"
5
5
  Bundler.require :default, :development
6
- require 'pry'
7
- require 'support/core_ext/query_cache'
8
- require 'support/minitest_sqlserver'
9
- require 'support/test_in_memory_oltp'
10
- require 'cases/helper'
11
- require 'support/load_schema_sqlserver'
12
- require 'support/coerceable_test_sqlserver'
13
- require 'support/sql_counter_sqlserver'
14
- require 'support/connection_reflection'
15
- require 'mocha/minitest'
6
+ require "pry"
7
+ require "support/core_ext/query_cache"
8
+ require "support/minitest_sqlserver"
9
+ require "support/test_in_memory_oltp"
10
+ require "cases/helper"
11
+ require "support/load_schema_sqlserver"
12
+ require "support/coerceable_test_sqlserver"
13
+ require "support/sql_counter_sqlserver"
14
+ require "support/connection_reflection"
15
+ require "mocha/minitest"
16
16
 
17
17
  module ActiveRecord
18
18
  class TestCase < ActiveSupport::TestCase
19
-
20
19
  SQLServer = ActiveRecord::ConnectionAdapters::SQLServer
21
20
 
22
21
  include ARTest::SQLServer::CoerceableTest,
@@ -40,7 +39,7 @@ module ActiveRecord
40
39
  end
41
40
 
42
41
  def host_windows?
43
- RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
42
+ RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
44
43
  end
45
44
 
46
45
  def with_use_output_inserted_disabled
@@ -50,7 +49,6 @@ module ActiveRecord
50
49
  ensure
51
50
  klass.use_output_inserted = true
52
51
  end
53
-
54
52
  end
55
53
  end
56
54
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
4
- require 'models/post'
5
- require 'models/author'
3
+ require "cases/helper_sqlserver"
4
+ require "models/post"
5
+ require "models/author"
6
6
 
7
7
  class InClauseTestSQLServer < ActiveRecord::TestCase
8
8
  fixtures :posts, :authors
9
9
 
10
- it 'removes ordering from subqueries' do
11
- authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name)
10
+ it "removes ordering from subqueries" do
11
+ authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name)
12
12
  posts = Post.where(author: authors_subquery)
13
13
 
14
14
  assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
@@ -16,8 +16,8 @@ class InClauseTestSQLServer < ActiveRecord::TestCase
16
16
  assert_equal 10, posts.length
17
17
  end
18
18
 
19
- it 'does not remove ordering from subquery that includes a limit' do
20
- authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name).limit(2)
19
+ it "does not remove ordering from subquery that includes a limit" do
20
+ authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name).limit(2)
21
21
  posts = Post.where(author: authors_subquery)
22
22
 
23
23
  assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
@@ -25,8 +25,8 @@ class InClauseTestSQLServer < ActiveRecord::TestCase
25
25
  assert_equal 7, posts.length
26
26
  end
27
27
 
28
- it 'does not remove ordering from subquery that includes an offset' do
29
- authors_subquery = Author.where(name: ['David', 'Mary', 'Bob']).order(:name).offset(1)
28
+ it "does not remove ordering from subquery that includes an offset" do
29
+ authors_subquery = Author.where(name: ["David", "Mary", "Bob"]).order(:name).offset(1)
30
30
  posts = Post.where(author: authors_subquery)
31
31
 
32
32
  assert_includes authors_subquery.to_sql, "ORDER BY [authors].[name]"
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
3
+ require "cases/helper_sqlserver"
4
4
 
5
5
  class IndexTestSQLServer < ActiveRecord::TestCase
6
-
7
6
  before do
8
7
  connection.create_table(:testings) do |t|
9
8
  t.column :foo, :string, limit: 100
@@ -19,31 +18,30 @@ class IndexTestSQLServer < ActiveRecord::TestCase
19
18
  connection.drop_table :testings rescue nil
20
19
  end
21
20
 
22
- it 'add index with order' do
21
+ it "add index with order" do
23
22
  assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC\)/i) do
24
- connection.add_index 'testings', ['last_name'], order: { last_name: :desc }
25
- connection.remove_index 'testings', ['last_name']
23
+ connection.add_index "testings", ["last_name"], order: { last_name: :desc }
24
+ connection.remove_index "testings", ["last_name"]
26
25
  end
27
26
  assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\]\)/i) do
28
- connection.add_index 'testings', ['last_name', 'first_name'], order: { last_name: :desc }
29
- connection.remove_index 'testings', ['last_name', 'first_name']
27
+ connection.add_index "testings", ["last_name", "first_name"], order: { last_name: :desc }
28
+ connection.remove_index "testings", ["last_name", "first_name"]
30
29
  end
31
30
  assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\] ASC\)/i) do
32
- connection.add_index 'testings', ['last_name', 'first_name'], order: { last_name: :desc, first_name: :asc }
33
- connection.remove_index 'testings', ['last_name', 'first_name']
31
+ connection.add_index "testings", ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc }
32
+ connection.remove_index "testings", ["last_name", "first_name"]
34
33
  end
35
34
  end
36
35
 
37
- it 'add index with where' do
36
+ it "add index with where" do
38
37
  assert_sql(/CREATE.*INDEX.*\(\[last_name\]\) WHERE \[first_name\] = N'john doe'/i) do
39
- connection.add_index 'testings', 'last_name', where: "[first_name] = N'john doe'"
40
- connection.remove_index 'testings', 'last_name'
38
+ connection.add_index "testings", "last_name", where: "[first_name] = N'john doe'"
39
+ connection.remove_index "testings", "last_name"
41
40
  end
42
41
  end
43
42
 
44
- it 'add index with expression' do
43
+ it "add index with expression" do
45
44
  connection.execute "ALTER TABLE [testings] ADD [first_name_upper] AS UPPER([first_name])"
46
- connection.add_index 'testings', 'first_name_upper'
45
+ connection.add_index "testings", "first_name_upper"
47
46
  end
48
-
49
47
  end