activerecord-sqlserver-adapter 5.2.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +9 -0
  3. data/.github/issue_template.md +23 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +29 -0
  6. data/.travis.yml +6 -8
  7. data/CHANGELOG.md +46 -11
  8. data/{Dockerfile → Dockerfile.ci} +2 -2
  9. data/Gemfile +48 -41
  10. data/Guardfile +9 -8
  11. data/README.md +9 -37
  12. data/RUNNING_UNIT_TESTS.md +3 -0
  13. data/Rakefile +14 -16
  14. data/VERSION +1 -1
  15. data/activerecord-sqlserver-adapter.gemspec +25 -14
  16. data/appveyor.yml +24 -17
  17. data/docker-compose.ci.yml +7 -5
  18. data/guides/RELEASING.md +11 -0
  19. data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +2 -4
  20. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +3 -4
  21. data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +22 -2
  22. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +3 -3
  23. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +2 -0
  24. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +44 -0
  25. data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +36 -0
  26. data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +28 -0
  27. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +9 -0
  28. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +88 -44
  29. data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +10 -12
  30. data/lib/active_record/connection_adapters/sqlserver/errors.rb +2 -3
  31. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +46 -8
  32. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +16 -5
  33. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +9 -7
  34. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +197 -165
  35. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +8 -8
  36. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +4 -2
  37. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +3 -1
  38. data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +2 -2
  39. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +43 -44
  40. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +7 -9
  41. data/lib/active_record/connection_adapters/sqlserver/type.rb +37 -35
  42. data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +3 -3
  43. data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +5 -4
  44. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +3 -3
  45. data/lib/active_record/connection_adapters/sqlserver/type/char.rb +7 -4
  46. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +2 -2
  47. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +4 -3
  48. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +8 -8
  49. data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +2 -2
  50. data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +2 -2
  51. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +5 -4
  52. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +3 -3
  53. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +3 -3
  54. data/lib/active_record/connection_adapters/sqlserver/type/json.rb +2 -1
  55. data/lib/active_record/connection_adapters/sqlserver/type/money.rb +4 -4
  56. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +3 -3
  57. data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +3 -3
  58. data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +4 -4
  59. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +3 -3
  60. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +2 -2
  61. data/lib/active_record/connection_adapters/sqlserver/type/text.rb +3 -3
  62. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +6 -6
  63. data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +8 -9
  64. data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +3 -3
  65. data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +3 -3
  66. data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +5 -4
  67. data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +2 -2
  68. data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +3 -3
  69. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +6 -5
  70. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +4 -4
  71. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +4 -3
  72. data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +6 -5
  73. data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +4 -4
  74. data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +6 -5
  75. data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +4 -4
  76. data/lib/active_record/connection_adapters/sqlserver/utils.rb +10 -11
  77. data/lib/active_record/connection_adapters/sqlserver/version.rb +2 -2
  78. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +132 -92
  79. data/lib/active_record/connection_adapters/sqlserver_column.rb +9 -5
  80. data/lib/active_record/sqlserver_base.rb +9 -1
  81. data/lib/active_record/tasks/sqlserver_database_tasks.rb +28 -32
  82. data/lib/activerecord-sqlserver-adapter.rb +3 -1
  83. data/lib/arel/visitors/sqlserver.rb +58 -24
  84. data/lib/arel_sqlserver.rb +4 -2
  85. data/test/appveyor/dbsetup.ps1 +4 -4
  86. data/test/cases/adapter_test_sqlserver.rb +223 -180
  87. data/test/cases/change_column_null_test_sqlserver.rb +17 -15
  88. data/test/cases/coerced_tests.rb +654 -360
  89. data/test/cases/column_test_sqlserver.rb +635 -604
  90. data/test/cases/connection_test_sqlserver.rb +18 -21
  91. data/test/cases/execute_procedure_test_sqlserver.rb +20 -20
  92. data/test/cases/fetch_test_sqlserver.rb +17 -23
  93. data/test/cases/fully_qualified_identifier_test_sqlserver.rb +15 -19
  94. data/test/cases/helper_sqlserver.rb +20 -15
  95. data/test/cases/in_clause_test_sqlserver.rb +36 -0
  96. data/test/cases/index_test_sqlserver.rb +15 -15
  97. data/test/cases/json_test_sqlserver.rb +25 -25
  98. data/test/cases/migration_test_sqlserver.rb +30 -26
  99. data/test/cases/order_test_sqlserver.rb +53 -54
  100. data/test/cases/pessimistic_locking_test_sqlserver.rb +31 -37
  101. data/test/cases/rake_test_sqlserver.rb +44 -56
  102. data/test/cases/schema_dumper_test_sqlserver.rb +117 -112
  103. data/test/cases/schema_test_sqlserver.rb +20 -26
  104. data/test/cases/scratchpad_test_sqlserver.rb +4 -4
  105. data/test/cases/showplan_test_sqlserver.rb +32 -39
  106. data/test/cases/specific_schema_test_sqlserver.rb +75 -72
  107. data/test/cases/transaction_test_sqlserver.rb +27 -29
  108. data/test/cases/trigger_test_sqlserver.rb +18 -17
  109. data/test/cases/utils_test_sqlserver.rb +78 -78
  110. data/test/cases/uuid_test_sqlserver.rb +19 -20
  111. data/test/debug.rb +8 -6
  112. data/test/migrations/create_clients_and_change_column_null.rb +3 -1
  113. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +4 -4
  114. data/test/models/sqlserver/booking.rb +3 -1
  115. data/test/models/sqlserver/customers_view.rb +3 -1
  116. data/test/models/sqlserver/datatype.rb +2 -0
  117. data/test/models/sqlserver/datatype_migration.rb +2 -0
  118. data/test/models/sqlserver/dollar_table_name.rb +3 -1
  119. data/test/models/sqlserver/edge_schema.rb +3 -3
  120. data/test/models/sqlserver/fk_has_fk.rb +3 -1
  121. data/test/models/sqlserver/fk_has_pk.rb +3 -1
  122. data/test/models/sqlserver/natural_pk_data.rb +4 -2
  123. data/test/models/sqlserver/natural_pk_int_data.rb +3 -1
  124. data/test/models/sqlserver/no_pk_data.rb +3 -1
  125. data/test/models/sqlserver/object_default.rb +3 -1
  126. data/test/models/sqlserver/quoted_table.rb +4 -2
  127. data/test/models/sqlserver/quoted_view_1.rb +3 -1
  128. data/test/models/sqlserver/quoted_view_2.rb +3 -1
  129. data/test/models/sqlserver/sst_memory.rb +3 -1
  130. data/test/models/sqlserver/string_default.rb +3 -1
  131. data/test/models/sqlserver/string_defaults_big_view.rb +3 -1
  132. data/test/models/sqlserver/string_defaults_view.rb +3 -1
  133. data/test/models/sqlserver/tinyint_pk.rb +3 -1
  134. data/test/models/sqlserver/trigger.rb +4 -2
  135. data/test/models/sqlserver/trigger_history.rb +3 -1
  136. data/test/models/sqlserver/upper.rb +3 -1
  137. data/test/models/sqlserver/uppered.rb +3 -1
  138. data/test/models/sqlserver/uuid.rb +3 -1
  139. data/test/schema/datatypes/2012.sql +1 -0
  140. data/test/schema/sqlserver_specific_schema.rb +31 -21
  141. data/test/support/coerceable_test_sqlserver.rb +15 -9
  142. data/test/support/connection_reflection.rb +3 -2
  143. data/test/support/core_ext/query_cache.rb +4 -1
  144. data/test/support/load_schema_sqlserver.rb +5 -5
  145. data/test/support/minitest_sqlserver.rb +3 -1
  146. data/test/support/paths_sqlserver.rb +11 -11
  147. data/test/support/rake_helpers.rb +13 -10
  148. data/test/support/sql_counter_sqlserver.rb +3 -4
  149. data/test/support/test_in_memory_oltp.rb +9 -7
  150. metadata +23 -13
  151. data/BACKERS.md +0 -32
  152. data/circle.yml +0 -38
@@ -1,30 +1,28 @@
1
- require 'cases/helper_sqlserver'
1
+ # frozen_string_literal: true
2
2
 
3
- class SchemaTestSQLServer < ActiveRecord::TestCase
4
-
5
- describe 'When table is dbo schema' do
3
+ require "cases/helper_sqlserver"
6
4
 
7
- it 'find primary key for tables with odd schema' do
8
- connection.primary_key('sst_natural_pk_data').must_equal 'legacy_id'
5
+ class SchemaTestSQLServer < ActiveRecord::TestCase
6
+ describe "When table is dbo schema" do
7
+ it "find primary key for tables with odd schema" do
8
+ _(connection.primary_key("sst_natural_pk_data")).must_equal "legacy_id"
9
9
  end
10
-
11
10
  end
12
11
 
13
- describe 'When table is in non-dbo schema' do
14
-
15
- it 'work with table exists' do
16
- assert connection.data_source_exists?('test.sst_schema_natural_id')
17
- assert connection.data_source_exists?('[test].[sst_schema_natural_id]')
12
+ describe "When table is in non-dbo schema" do
13
+ it "work with table exists" do
14
+ assert connection.data_source_exists?("test.sst_schema_natural_id")
15
+ assert connection.data_source_exists?("[test].[sst_schema_natural_id]")
18
16
  end
19
17
 
20
- it 'find primary key for tables with odd schema' do
21
- connection.primary_key('test.sst_schema_natural_id').must_equal 'legacy_id'
18
+ it "find primary key for tables with odd schema" do
19
+ _(connection.primary_key("test.sst_schema_natural_id")).must_equal "legacy_id"
22
20
  end
23
21
 
24
22
  it "have only one identity column" do
25
23
  columns = connection.columns("test.sst_schema_identity")
26
24
  assert_equal 2, columns.size
27
- assert_equal 1, columns.select{ |c| c.is_identity? }.size
25
+ assert_equal 1, columns.select { |c| c.is_identity? }.size
28
26
  end
29
27
 
30
28
  it "read only column properties for table in specific schema" do
@@ -34,21 +32,17 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
34
32
  assert_equal 7, test_columns.size
35
33
  assert_equal 2, dbo_columns.size
36
34
  assert_equal 2, columns.size
37
- assert_equal 1, test_columns.select{ |c| c.is_identity? }.size
38
- assert_equal 1, dbo_columns.select{ |c| c.is_identity? }.size
39
- assert_equal 1, columns.select{ |c| c.is_identity? }.size
35
+ assert_equal 1, test_columns.select { |c| c.is_identity? }.size
36
+ assert_equal 1, dbo_columns.select { |c| c.is_identity? }.size
37
+ assert_equal 1, columns.select { |c| c.is_identity? }.size
40
38
  end
41
39
 
42
40
  it "return correct varchar and nvarchar column limit length when table is in non dbo schema" do
43
41
  columns = connection.columns("test.sst_schema_columns")
44
- assert_equal 255, columns.find {|c| c.name == 'name'}.limit
45
- assert_equal 1000, columns.find {|c| c.name == 'description'}.limit
46
- assert_equal 255, columns.find {|c| c.name == 'n_name'}.limit
47
- assert_equal 1000, columns.find {|c| c.name == 'n_description'}.limit
42
+ assert_equal 255, columns.find { |c| c.name == "name" }.limit
43
+ assert_equal 1000, columns.find { |c| c.name == "description" }.limit
44
+ assert_equal 255, columns.find { |c| c.name == "n_name" }.limit
45
+ assert_equal 1000, columns.find { |c| c.name == "n_description" }.limit
48
46
  end
49
-
50
47
  end
51
-
52
-
53
48
  end
54
-
@@ -1,8 +1,8 @@
1
- require 'cases/helper_sqlserver'
1
+ # frozen_string_literal: true
2
2
 
3
- class ScratchpadTestSQLServer < ActiveRecord::TestCase
3
+ require "cases/helper_sqlserver"
4
4
 
5
- it 'helps debug things' do
5
+ class ScratchpadTestSQLServer < ActiveRecord::TestCase
6
+ it "helps debug things" do
6
7
  end
7
-
8
8
  end
@@ -1,69 +1,63 @@
1
- require 'cases/helper_sqlserver'
2
- require 'models/car'
1
+ # frozen_string_literal: true
3
2
 
4
- class ShowplanTestSQLServer < ActiveRecord::TestCase
3
+ require "cases/helper_sqlserver"
4
+ require "models/car"
5
5
 
6
+ class ShowplanTestSQLServer < ActiveRecord::TestCase
6
7
  fixtures :cars
7
8
 
8
- describe 'Unprepare previously prepared SQL' do
9
-
10
- it 'from simple statement' do
9
+ describe "Unprepare previously prepared SQL" do
10
+ it "from simple statement" do
11
11
  plan = Car.where(id: 1).explain
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'
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"
14
14
  end
15
15
 
16
- it 'from multiline statement' do
16
+ it "from multiline statement" do
17
17
  plan = Car.where("\n id = 1 \n").explain
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'
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"
20
20
  end
21
21
 
22
- it 'from prepared statement' do
23
- plan = Car.where(name: ',').limit(1).explain
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'
22
+ it "from prepared statement" do
23
+ plan = Car.where(name: ",").limit(1).explain
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"
27
27
  end
28
28
 
29
- it 'from array condition using index' do
29
+ it "from array condition using index" do
30
30
  plan = Car.where(id: [1, 2]).explain
31
- plan.must_include " SELECT [cars].* FROM [cars] WHERE [cars].[id] IN (1, 2)"
32
- plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
31
+ _(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] IN (1, 2)"
32
+ _(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
33
33
  end
34
34
 
35
- it 'from array condition' do
36
- plan = Car.where(name: ['honda', 'zyke']).explain
37
- plan.must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name] IN (N'honda', N'zyke')"
38
- plan.must_include "Clustered Index Scan", 'make sure we do not showplan the sp_executesql'
35
+ it "from array condition" do
36
+ plan = Car.where(name: ["honda", "zyke"]).explain
37
+ _(plan).must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name] IN (N'honda', N'zyke')"
38
+ _(plan).must_include "Clustered Index Scan", "make sure we do not showplan the sp_executesql"
39
39
  end
40
-
41
40
  end
42
41
 
43
- describe 'With SHOWPLAN_TEXT option' do
44
-
45
- it 'use simple table printer' do
46
- with_showplan_option('SHOWPLAN_TEXT') do
42
+ describe "With SHOWPLAN_TEXT option" do
43
+ it "use simple table printer" do
44
+ with_showplan_option("SHOWPLAN_TEXT") do
47
45
  plan = Car.where(id: 1).explain
48
- plan.must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
49
- plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
46
+ _(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
47
+ _(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
50
48
  end
51
49
  end
52
-
53
50
  end
54
51
 
55
- describe 'With SHOWPLAN_XML option' do
56
-
57
- it 'show formatted xml' do
58
- with_showplan_option('SHOWPLAN_XML') do
52
+ describe "With SHOWPLAN_XML option" do
53
+ it "show formatted xml" do
54
+ with_showplan_option("SHOWPLAN_XML") do
59
55
  plan = Car.where(id: 1).explain
60
- plan.must_include 'ShowPlanXML'
56
+ _(plan).must_include "ShowPlanXML"
61
57
  end
62
58
  end
63
-
64
59
  end
65
60
 
66
-
67
61
  private
68
62
 
69
63
  def with_showplan_option(option)
@@ -73,5 +67,4 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
73
67
  ensure
74
68
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = old_option
75
69
  end
76
-
77
70
  end
@@ -1,107 +1,111 @@
1
- require 'cases/helper_sqlserver'
1
+ # frozen_string_literal: true
2
2
 
3
- class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
3
+ require "cases/helper_sqlserver"
4
4
 
5
+ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
5
6
  after { SSTestEdgeSchema.delete_all }
6
7
 
7
- it 'handle dollar symbols' do
8
+ it "handle dollar symbols" do
8
9
  SSTestDollarTableName.create!
9
10
  SSTestDollarTableName.limit(20).offset(1)
10
11
  end
11
12
 
12
- it 'models can use tinyint pk tables' do
13
- obj = SSTestTinyintPk.create! name: '1'
14
- ['Fixnum', 'Integer'].must_include obj.id.class.name
15
- SSTestTinyintPk.find(obj.id).must_equal obj
13
+ it "models can use tinyint pk tables" do
14
+ obj = SSTestTinyintPk.create! name: "1"
15
+ _(["Fixnum", "Integer"]).must_include obj.id.class.name
16
+ _(SSTestTinyintPk.find(obj.id)).must_equal obj
16
17
  end
17
18
 
18
- it 'be able to complex count tables with no primary key' do
19
+ it "be able to complex count tables with no primary key" do
19
20
  SSTestNoPkData.delete_all
20
21
  10.times { |n| SSTestNoPkData.create! name: "Test#{n}" }
21
- assert_equal 1, SSTestNoPkData.where(name: 'Test5').count
22
+ assert_equal 1, SSTestNoPkData.where(name: "Test5").count
22
23
  end
23
24
 
24
- it 'quote table names properly even when they are views' do
25
- obj = SSTestQuotedTable.create!
25
+ it "quote table names properly even when they are views" do
26
+ SSTestQuotedTable.create!
26
27
  assert_nothing_raised { assert SSTestQuotedTable.first }
27
- obj = SSTestQuotedTableUser.create!
28
+
29
+ SSTestQuotedTableUser.create!
28
30
  assert_nothing_raised { assert SSTestQuotedTableUser.first }
29
- obj = SSTestQuotedView1.create!
31
+
32
+ SSTestQuotedView1.create!
30
33
  assert_nothing_raised { assert SSTestQuotedView1.first }
31
- obj = SSTestQuotedView2.create!
34
+
35
+ SSTestQuotedView2.create!
32
36
  assert_nothing_raised { assert SSTestQuotedView2.first }
33
37
  end
34
38
 
35
- it 'cope with multi line defaults' do
39
+ it "cope with multi line defaults" do
36
40
  default = SSTestStringDefault.new
37
41
  assert_equal "Some long default with a\nnew line.", default.string_with_multiline_default
38
42
  end
39
43
 
40
- it 'default strings before save' do
44
+ it "default strings before save" do
41
45
  default = SSTestStringDefault.new
42
46
  assert_nil default.string_with_null_default
43
- assert_equal 'null', default.string_with_pretend_null_one
44
- assert_equal '(null)', default.string_with_pretend_null_two
45
- assert_equal 'NULL', default.string_with_pretend_null_three
46
- assert_equal '(NULL)', default.string_with_pretend_null_four
47
- assert_equal '(3)', default.string_with_pretend_paren_three
47
+ assert_equal "null", default.string_with_pretend_null_one
48
+ assert_equal "(null)", default.string_with_pretend_null_two
49
+ assert_equal "NULL", default.string_with_pretend_null_three
50
+ assert_equal "(NULL)", default.string_with_pretend_null_four
51
+ assert_equal "(3)", default.string_with_pretend_paren_three
48
52
  end
49
53
 
50
- it 'default strings after save' do
54
+ it "default strings after save" do
51
55
  default = SSTestStringDefault.create
52
56
  assert_nil default.string_with_null_default
53
- assert_equal 'null', default.string_with_pretend_null_one
54
- assert_equal '(null)', default.string_with_pretend_null_two
55
- assert_equal 'NULL', default.string_with_pretend_null_three
56
- assert_equal '(NULL)', default.string_with_pretend_null_four
57
+ assert_equal "null", default.string_with_pretend_null_one
58
+ assert_equal "(null)", default.string_with_pretend_null_two
59
+ assert_equal "NULL", default.string_with_pretend_null_three
60
+ assert_equal "(NULL)", default.string_with_pretend_null_four
57
61
  end
58
62
 
59
- it 'default objects work' do
60
- obj = SSTestObjectDefault.create! name: 'MetaSkills'
61
- obj.date.must_be_nil 'since this is set on insert'
62
- obj.reload.date.must_be_instance_of Date
63
+ it "default objects work" do
64
+ obj = SSTestObjectDefault.create! name: "MetaSkills"
65
+ _(obj.date).must_be_nil "since this is set on insert"
66
+ _(obj.reload.date).must_be_instance_of Date
63
67
  end
64
68
 
65
- it 'allows datetime2 as timestamps' do
66
- SSTestBooking.columns_hash['created_at'].sql_type.must_equal 'datetime2(7)'
67
- SSTestBooking.columns_hash['updated_at'].sql_type.must_equal 'datetime2(7)'
68
- obj1 = SSTestBooking.new name: 'test1'
69
+ it "allows datetime2 as timestamps" do
70
+ _(SSTestBooking.columns_hash["created_at"].sql_type).must_equal "datetime2(7)"
71
+ _(SSTestBooking.columns_hash["updated_at"].sql_type).must_equal "datetime2(7)"
72
+ obj1 = SSTestBooking.new name: "test1"
69
73
  obj1.save!
70
- obj1.created_at.must_be_instance_of Time
71
- obj1.updated_at.must_be_instance_of Time
74
+ _(obj1.created_at).must_be_instance_of Time
75
+ _(obj1.updated_at).must_be_instance_of Time
72
76
  end
73
77
 
74
78
  # Natural primary keys.
75
79
 
76
- it 'work with identity inserts' do
77
- record = SSTestNaturalPkData.new name: 'Test', description: 'Natural identity inserts.'
78
- record.id = '12345ABCDE'
80
+ it "work with identity inserts" do
81
+ record = SSTestNaturalPkData.new name: "Test", description: "Natural identity inserts."
82
+ record.id = "12345ABCDE"
79
83
  assert record.save
80
- assert_equal '12345ABCDE', record.reload.id
84
+ assert_equal "12345ABCDE", record.reload.id
81
85
  end
82
86
 
83
- it 'work with identity inserts when the key is an int' do
84
- record = SSTestNaturalPkIntData.new name: 'Test', description: 'Natural identity inserts.'
87
+ it "work with identity inserts when the key is an int" do
88
+ record = SSTestNaturalPkIntData.new name: "Test", description: "Natural identity inserts."
85
89
  record.id = 12
86
90
  assert record.save
87
91
  assert_equal 12, record.reload.id
88
92
  end
89
93
 
90
- it 'use primary key for row table order in pagination sql' do
94
+ it "use primary key for row table order in pagination sql" do
91
95
  sql = /ORDER BY \[sst_natural_pk_data\]\.\[legacy_id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY/
92
96
  assert_sql(sql) { SSTestNaturalPkData.limit(5).offset(5).load }
93
97
  end
94
98
 
95
99
  # Special quoted column
96
100
 
97
- it 'work as normal' do
101
+ it "work as normal" do
98
102
  SSTestEdgeSchema.delete_all
99
- r = SSTestEdgeSchema.create! 'crazy]]quote' => 'crazyqoute'
100
- assert SSTestEdgeSchema.columns_hash['crazy]]quote']
101
- assert_equal r, SSTestEdgeSchema.where('crazy]]quote' => 'crazyqoute').first
103
+ r = SSTestEdgeSchema.create! "crazy]]quote" => "crazyqoute"
104
+ assert SSTestEdgeSchema.columns_hash["crazy]]quote"]
105
+ assert_equal r, SSTestEdgeSchema.where("crazy]]quote" => "crazyqoute").first
102
106
  end
103
107
 
104
- it 'various methods to bypass national quoted columns for any column, but primarily useful for char/varchar' do
108
+ it "various methods to bypass national quoted columns for any column, but primarily useful for char/varchar" do
105
109
  value = Class.new do
106
110
  def quoted_id
107
111
  "'T'"
@@ -113,58 +117,57 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
113
117
  # Using our custom char type data.
114
118
  type = ActiveRecord::Type::SQLServer::Char
115
119
  data = ActiveRecord::Type::SQLServer::Data
116
- assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new('T', type.new)).first }
117
- assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new('T', type.new)).first }
120
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new("T", type.new)).first }
121
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new("T", type.new)).first }
118
122
  # Taking care of everything.
119
- assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: 'T').first }
120
- assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: 'T').first }
123
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: "T").first }
124
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: "T").first }
121
125
  end
122
126
 
123
- it 'can update and hence properly quoted non-national char/varchar columns' do
127
+ it "can update and hence properly quoted non-national char/varchar columns" do
124
128
  o = SSTestDatatypeMigration.create!
125
129
  o.varchar_col = "O'Reilly"
126
130
  o.save!
127
- o.reload.varchar_col.must_equal "O'Reilly"
131
+ _(o.reload.varchar_col).must_equal "O'Reilly"
128
132
  o.varchar_col = nil
129
133
  o.save!
130
- o.reload.varchar_col.must_be_nil
134
+ _(o.reload.varchar_col).must_be_nil
131
135
  end
132
136
 
133
137
  # With column names that have spaces
134
138
 
135
- it 'create record using a custom attribute reader and be able to load it back in' do
136
- value = 'Saved value into a column that has a space in the name.'
139
+ it "create record using a custom attribute reader and be able to load it back in" do
140
+ value = "Saved value into a column that has a space in the name."
137
141
  record = SSTestEdgeSchema.create! with_spaces: value
138
142
  assert_equal value, SSTestEdgeSchema.find(record.id).with_spaces
139
143
  end
140
144
 
141
145
  # With description column
142
146
 
143
- it 'allow all sorts of ordering without adapter munging it up with special description column' do
144
- SSTestEdgeSchema.create! description: 'A'
145
- SSTestEdgeSchema.create! description: 'B'
146
- SSTestEdgeSchema.create! description: 'C'
147
- assert_equal ['A','B','C'], SSTestEdgeSchema.order('description').map(&:description)
148
- assert_equal ['A','B','C'], SSTestEdgeSchema.order('description asc').map(&:description)
149
- assert_equal ['A','B','C'], SSTestEdgeSchema.order('description ASC').map(&:description)
150
- assert_equal ['C','B','A'], SSTestEdgeSchema.order('description desc').map(&:description)
151
- assert_equal ['C','B','A'], SSTestEdgeSchema.order('description DESC').map(&:description)
147
+ it "allow all sorts of ordering without adapter munging it up with special description column" do
148
+ SSTestEdgeSchema.create! description: "A"
149
+ SSTestEdgeSchema.create! description: "B"
150
+ SSTestEdgeSchema.create! description: "C"
151
+ assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description").map(&:description)
152
+ assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description asc").map(&:description)
153
+ assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description ASC").map(&:description)
154
+ assert_equal ["C", "B", "A"], SSTestEdgeSchema.order("description desc").map(&:description)
155
+ assert_equal ["C", "B", "A"], SSTestEdgeSchema.order("description DESC").map(&:description)
152
156
  end
153
157
 
154
158
  # For uniqueidentifier model helpers
155
159
 
156
- it 'returns a new id via connection newid_function' do
160
+ it "returns a new id via connection newid_function" do
157
161
  acceptable_uuid = ActiveRecord::ConnectionAdapters::SQLServer::Type::Uuid::ACCEPTABLE_UUID
158
162
  db_uuid = ActiveRecord::Base.connection.newid_function
159
- db_uuid.must_match(acceptable_uuid)
163
+ _(db_uuid).must_match(acceptable_uuid)
160
164
  end
161
165
 
162
166
  # with similar table definition in two schemas
163
167
 
164
- it 'returns the correct primary columns' do
168
+ it "returns the correct primary columns" do
165
169
  connection = ActiveRecord::Base.connection
166
- assert_equal 'field_1', connection.columns('test.sst_schema_test_mulitple_schema').detect(&:is_primary?).name
167
- assert_equal 'field_2', connection.columns('test2.sst_schema_test_mulitple_schema').detect(&:is_primary?).name
170
+ assert_equal "field_1", connection.columns("test.sst_schema_test_mulitple_schema").detect(&:is_primary?).name
171
+ assert_equal "field_2", connection.columns("test2.sst_schema_test_mulitple_schema").detect(&:is_primary?).name
168
172
  end
169
-
170
173
  end
@@ -1,58 +1,58 @@
1
- # encoding: UTF-8
2
- require 'cases/helper_sqlserver'
3
- require 'models/ship'
4
- require 'models/developer'
1
+ # frozen_string_literal: true
5
2
 
6
- class TransactionTestSQLServer < ActiveRecord::TestCase
3
+ require "cases/helper_sqlserver"
4
+ require "models/ship"
5
+ require "models/developer"
7
6
 
7
+ class TransactionTestSQLServer < ActiveRecord::TestCase
8
8
  self.use_transactional_tests = false
9
9
 
10
10
  before { delete_ships }
11
11
 
12
- it 'allow ActiveRecord::Rollback to work in 1 transaction block' do
12
+ it "allow ActiveRecord::Rollback to work in 1 transaction block" do
13
13
  Ship.transaction do
14
- Ship.create! name: 'Black Pearl'
14
+ Ship.create! name: "Black Pearl"
15
15
  raise ActiveRecord::Rollback
16
16
  end
17
17
  assert_no_ships
18
18
  end
19
19
 
20
- it 'allow nested transactions to totally rollback' do
20
+ it "allow nested transactions to totally rollback" do
21
21
  begin
22
22
  Ship.transaction do
23
- Ship.create! name: 'Black Pearl'
23
+ Ship.create! name: "Black Pearl"
24
24
  Ship.transaction do
25
- Ship.create! name: 'Flying Dutchman'
26
- raise 'HELL'
25
+ Ship.create! name: "Flying Dutchman"
26
+ raise "HELL"
27
27
  end
28
28
  end
29
- rescue Exception => e
29
+ rescue Exception
30
30
  assert_no_ships
31
31
  end
32
32
  end
33
33
 
34
- it 'can use an isolation level and reverts back to starting isolation level' do
34
+ it "can use an isolation level and reverts back to starting isolation level" do
35
35
  in_level = nil
36
36
  begin_level = connection.user_options_isolation_level
37
- begin_level.must_match %r{read committed}i
37
+ _(begin_level).must_match %r{read committed}i
38
38
  Ship.transaction(isolation: :serializable) do
39
- Ship.create! name: 'Black Pearl'
39
+ Ship.create! name: "Black Pearl"
40
40
  in_level = connection.user_options_isolation_level
41
41
  end
42
42
  after_level = connection.user_options_isolation_level
43
- in_level.must_match %r{serializable}i
44
- after_level.must_match %r{read committed}i
43
+ _(in_level).must_match %r{serializable}i
44
+ _(after_level).must_match %r{read committed}i
45
45
  end
46
46
 
47
- it 'can use an isolation level and reverts back to starting isolation level under exceptions' do
48
- connection.user_options_isolation_level.must_match %r{read committed}i
49
- lambda {
47
+ it "can use an isolation level and reverts back to starting isolation level under exceptions" do
48
+ _(connection.user_options_isolation_level).must_match %r{read committed}i
49
+ _(lambda {
50
50
  Ship.transaction(isolation: :serializable) { Ship.create! }
51
- }.must_raise(ActiveRecord::RecordInvalid)
52
- connection.user_options_isolation_level.must_match %r{read committed}i
51
+ }).must_raise(ActiveRecord::RecordInvalid)
52
+ _(connection.user_options_isolation_level).must_match %r{read committed}i
53
53
  end
54
54
 
55
- describe 'when READ_COMMITTED_SNAPSHOT is set' do
55
+ describe "when READ_COMMITTED_SNAPSHOT is set" do
56
56
  before do
57
57
  connection.execute "ALTER DATABASE [#{connection.current_database}] SET ALLOW_SNAPSHOT_ISOLATION ON"
58
58
  connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE"
@@ -63,21 +63,20 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
63
63
  connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT OFF WITH ROLLBACK IMMEDIATE"
64
64
  end
65
65
 
66
- it 'should use READ COMMITTED as an isolation level' do
67
- connection.user_options_isolation_level.must_match "read committed snapshot"
66
+ it "should use READ COMMITTED as an isolation level" do
67
+ _(connection.user_options_isolation_level).must_match "read committed snapshot"
68
68
 
69
69
  Ship.transaction(isolation: :serializable) do
70
- Ship.create! name: 'Black Pearl'
70
+ Ship.create! name: "Black Pearl"
71
71
  end
72
72
 
73
73
  # We're actually testing that the isolation level was correctly reset to
74
74
  # "READ COMMITTED", and that no exception was raised (it's reported back
75
75
  # by SQL Server as "read committed snapshot").
76
- connection.user_options_isolation_level.must_match "read committed snapshot"
76
+ _(connection.user_options_isolation_level).must_match "read committed snapshot"
77
77
  end
78
78
  end
79
79
 
80
-
81
80
  protected
82
81
 
83
82
  def delete_ships
@@ -87,5 +86,4 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
87
86
  def assert_no_ships
88
87
  assert Ship.count.zero?, "Expected Ship to have no models but it did have:\n#{Ship.all.inspect}"
89
88
  end
90
-
91
89
  end