activerecord-sqlserver-adapter 5.2.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) 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 +38 -24
  8. data/{Dockerfile → Dockerfile.ci} +1 -1
  9. data/Gemfile +48 -41
  10. data/Guardfile +9 -8
  11. data/README.md +9 -30
  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 +5 -4
  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 +8 -7
  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 +6 -4
  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 +9 -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 +190 -164
  35. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +4 -2
  36. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +3 -1
  37. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +8 -8
  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/big_integer.rb +3 -3
  42. data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +5 -4
  43. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +3 -3
  44. data/lib/active_record/connection_adapters/sqlserver/type/char.rb +7 -4
  45. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +2 -2
  46. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +4 -3
  47. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +8 -8
  48. data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +2 -2
  49. data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +2 -2
  50. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +5 -4
  51. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +3 -3
  52. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +3 -3
  53. data/lib/active_record/connection_adapters/sqlserver/type/json.rb +2 -1
  54. data/lib/active_record/connection_adapters/sqlserver/type/money.rb +4 -4
  55. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +3 -3
  56. data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +3 -3
  57. data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +4 -4
  58. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +3 -3
  59. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +2 -2
  60. data/lib/active_record/connection_adapters/sqlserver/type/text.rb +3 -3
  61. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +6 -6
  62. data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +8 -9
  63. data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +3 -3
  64. data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +3 -3
  65. data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +5 -4
  66. data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +2 -2
  67. data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +3 -3
  68. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +6 -5
  69. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +4 -4
  70. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +4 -3
  71. data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +6 -5
  72. data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +4 -4
  73. data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +6 -5
  74. data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +4 -4
  75. data/lib/active_record/connection_adapters/sqlserver/type.rb +37 -35
  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 +128 -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 +214 -171
  87. data/test/cases/change_column_null_test_sqlserver.rb +14 -12
  88. data/test/cases/coerced_tests.rb +631 -356
  89. data/test/cases/column_test_sqlserver.rb +283 -284
  90. data/test/cases/connection_test_sqlserver.rb +17 -20
  91. data/test/cases/execute_procedure_test_sqlserver.rb +20 -20
  92. data/test/cases/fetch_test_sqlserver.rb +16 -22
  93. data/test/cases/fully_qualified_identifier_test_sqlserver.rb +15 -19
  94. data/test/cases/helper_sqlserver.rb +15 -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 +25 -29
  99. data/test/cases/order_test_sqlserver.rb +53 -54
  100. data/test/cases/pessimistic_locking_test_sqlserver.rb +27 -33
  101. data/test/cases/rake_test_sqlserver.rb +33 -45
  102. data/test/cases/schema_dumper_test_sqlserver.rb +107 -109
  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 +28 -35
  106. data/test/cases/specific_schema_test_sqlserver.rb +68 -65
  107. data/test/cases/transaction_test_sqlserver.rb +18 -20
  108. data/test/cases/trigger_test_sqlserver.rb +14 -13
  109. data/test/cases/utils_test_sqlserver.rb +70 -70
  110. data/test/cases/uuid_test_sqlserver.rb +13 -14
  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/sqlserver_specific_schema.rb +22 -22
  140. data/test/support/coerceable_test_sqlserver.rb +15 -9
  141. data/test/support/connection_reflection.rb +3 -2
  142. data/test/support/core_ext/query_cache.rb +4 -1
  143. data/test/support/load_schema_sqlserver.rb +5 -5
  144. data/test/support/minitest_sqlserver.rb +3 -1
  145. data/test/support/paths_sqlserver.rb +11 -11
  146. data/test/support/rake_helpers.rb +13 -10
  147. data/test/support/sql_counter_sqlserver.rb +3 -4
  148. data/test/support/test_in_memory_oltp.rb +9 -7
  149. metadata +17 -7
@@ -1,144 +1,144 @@
1
- require 'cases/helper_sqlserver'
1
+ # frozen_string_literal: true
2
2
 
3
- class SchemaDumperTestSQLServer < ActiveRecord::TestCase
3
+ require "cases/helper_sqlserver"
4
4
 
5
+ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
5
6
  before { all_tables }
6
7
 
7
8
  let(:all_tables) { ActiveRecord::Base.connection.tables }
8
9
  let(:schema) { @generated_schema }
9
10
 
10
- it 'sst_datatypes' do
11
- generate_schema_for_table 'sst_datatypes'
12
- assert_line :bigint, type: 'bigint', limit: nil, precision: nil, scale: nil, default: 42
13
- assert_line :int, type: 'integer', limit: nil, precision: nil, scale: nil, default: 42
14
- assert_line :smallint, type: 'integer', limit: 2, precision: nil, scale: nil, default: 42
15
- assert_line :tinyint, type: 'integer', limit: 1, precision: nil, scale: nil, default: 42
16
- assert_line :bit, type: 'boolean', limit: nil, precision: nil, scale: nil, default: true
17
- assert_line :decimal_9_2, type: 'decimal', limit: nil, precision: 9, scale: 2, default: 12345.01
18
- assert_line :numeric_18_0, type: 'decimal', limit: nil, precision: 18, scale: 0, default: 191.0
19
- assert_line :numeric_36_2, type: 'decimal', limit: nil, precision: 36, scale: 2, default: 12345678901234567890.01
20
- assert_line :money, type: 'money', limit: nil, precision: 19, scale: 4, default: 4.2
21
- assert_line :smallmoney, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: 4.2
11
+ it "sst_datatypes" do
12
+ generate_schema_for_table "sst_datatypes"
13
+ assert_line :bigint, type: "bigint", limit: nil, precision: nil, scale: nil, default: 42
14
+ assert_line :int, type: "integer", limit: nil, precision: nil, scale: nil, default: 42
15
+ assert_line :smallint, type: "integer", limit: 2, precision: nil, scale: nil, default: 42
16
+ assert_line :tinyint, type: "integer", limit: 1, precision: nil, scale: nil, default: 42
17
+ assert_line :bit, type: "boolean", limit: nil, precision: nil, scale: nil, default: true
18
+ assert_line :decimal_9_2, type: "decimal", limit: nil, precision: 9, scale: 2, default: 12345.01
19
+ assert_line :numeric_18_0, type: "decimal", limit: nil, precision: 18, scale: 0, default: 191.0
20
+ assert_line :numeric_36_2, type: "decimal", limit: nil, precision: 36, scale: 2, default: 12345678901234567890.01
21
+ assert_line :money, type: "money", limit: nil, precision: 19, scale: 4, default: 4.2
22
+ assert_line :smallmoney, type: "smallmoney", limit: nil, precision: 10, scale: 4, default: 4.2
22
23
  # Approximate Numerics
23
- assert_line :float, type: 'float', limit: nil, precision: nil, scale: nil, default: 123.00000001
24
- assert_line :real, type: 'real', limit: nil, precision: nil, scale: nil, default: 123.45
24
+ assert_line :float, type: "float", limit: nil, precision: nil, scale: nil, default: 123.00000001
25
+ assert_line :real, type: "real", limit: nil, precision: nil, scale: nil, default: 123.45
25
26
  # Date and Time
26
- assert_line :date, type: 'date', limit: nil, precision: nil, scale: nil, default: "01-01-0001"
27
- assert_line :datetime, type: 'datetime', limit: nil, precision: nil, scale: nil, default: "01-01-1753 00:00:00.123"
27
+ assert_line :date, type: "date", limit: nil, precision: nil, scale: nil, default: "01-01-0001"
28
+ assert_line :datetime, type: "datetime", limit: nil, precision: nil, scale: nil, default: "01-01-1753 00:00:00.123"
28
29
  if connection_dblib_73?
29
- assert_line :datetime2_7, type: 'datetime', limit: nil, precision: 7, scale: nil, default: "12-31-9999 23:59:59.9999999"
30
- assert_line :datetime2_3, type: 'datetime', limit: nil, precision: 3, scale: nil, default: nil
31
- assert_line :datetime2_1, type: 'datetime', limit: nil, precision: 1, scale: nil, default: nil
30
+ assert_line :datetime2_7, type: "datetime", limit: nil, precision: 7, scale: nil, default: "12-31-9999 23:59:59.9999999"
31
+ assert_line :datetime2_3, type: "datetime", limit: nil, precision: 3, scale: nil, default: nil
32
+ assert_line :datetime2_1, type: "datetime", limit: nil, precision: 1, scale: nil, default: nil
32
33
  end
33
- assert_line :smalldatetime, type: 'smalldatetime',limit: nil, precision: nil, scale: nil, default: "01-01-1901 15:45:00.0"
34
+ assert_line :smalldatetime, type: "smalldatetime", limit: nil, precision: nil, scale: nil, default: "01-01-1901 15:45:00.0"
34
35
  if connection_dblib_73?
35
- assert_line :time_7, type: 'time', limit: nil, precision: 7, scale: nil, default: "04:20:00.2883215"
36
- assert_line :time_2, type: 'time', limit: nil, precision: 2, scale: nil, default: nil
37
- assert_line :time_default, type: 'time', limit: nil, precision: 7, scale: nil, default: "15:03:42.0621978"
36
+ assert_line :time_7, type: "time", limit: nil, precision: 7, scale: nil, default: "04:20:00.2883215"
37
+ assert_line :time_2, type: "time", limit: nil, precision: 2, scale: nil, default: nil
38
+ assert_line :time_default, type: "time", limit: nil, precision: 7, scale: nil, default: "15:03:42.0621978"
38
39
  end
39
40
  # Character Strings
40
- assert_line :char_10, type: 'char', limit: 10, precision: nil, scale: nil, default: "1234567890", collation: nil
41
- assert_line :varchar_50, type: 'varchar', limit: 50, precision: nil, scale: nil, default: "test varchar_50", collation: nil
42
- assert_line :varchar_max, type: 'varchar_max', limit: nil, precision: nil, scale: nil, default: "test varchar_max", collation: nil
43
- assert_line :text, type: 'text_basic', limit: nil, precision: nil, scale: nil, default: "test text", collation: nil
41
+ assert_line :char_10, type: "char", limit: 10, precision: nil, scale: nil, default: "1234567890", collation: nil
42
+ assert_line :varchar_50, type: "varchar", limit: 50, precision: nil, scale: nil, default: "test varchar_50", collation: nil
43
+ assert_line :varchar_max, type: "varchar_max", limit: nil, precision: nil, scale: nil, default: "test varchar_max", collation: nil
44
+ assert_line :text, type: "text_basic", limit: nil, precision: nil, scale: nil, default: "test text", collation: nil
44
45
  # Unicode Character Strings
45
- assert_line :nchar_10, type: 'nchar', limit: 10, precision: nil, scale: nil, default: "12345678åå", collation: nil
46
- assert_line :nvarchar_50, type: 'string', limit: 50, precision: nil, scale: nil, default: "test nvarchar_50 åå", collation: nil
47
- assert_line :nvarchar_max, type: 'text', limit: nil, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
48
- assert_line :ntext, type: 'ntext', limit: nil, precision: nil, scale: nil, default: "test ntext åå", collation: nil
46
+ assert_line :nchar_10, type: "nchar", limit: 10, precision: nil, scale: nil, default: "12345678åå", collation: nil
47
+ assert_line :nvarchar_50, type: "string", limit: 50, precision: nil, scale: nil, default: "test nvarchar_50 åå", collation: nil
48
+ assert_line :nvarchar_max, type: "text", limit: nil, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
49
+ assert_line :ntext, type: "ntext", limit: nil, precision: nil, scale: nil, default: "test ntext åå", collation: nil
49
50
  # Binary Strings
50
- assert_line :binary_49, type: 'binary_basic', limit: 49, precision: nil, scale: nil, default: nil
51
- assert_line :varbinary_49, type: 'varbinary', limit: 49, precision: nil, scale: nil, default: nil
52
- assert_line :varbinary_max, type: 'binary', limit: nil, precision: nil, scale: nil, default: nil
51
+ assert_line :binary_49, type: "binary_basic", limit: 49, precision: nil, scale: nil, default: nil
52
+ assert_line :varbinary_49, type: "varbinary", limit: 49, precision: nil, scale: nil, default: nil
53
+ assert_line :varbinary_max, type: "binary", limit: nil, precision: nil, scale: nil, default: nil
53
54
  # Other Data Types
54
- assert_line :uniqueidentifier, type: 'uuid', limit: nil, precision: nil, scale: nil, default: -> { "newid()" }
55
- assert_line :timestamp, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
55
+ assert_line :uniqueidentifier, type: "uuid", limit: nil, precision: nil, scale: nil, default: -> { "newid()" }
56
+ assert_line :timestamp, type: "ss_timestamp", limit: nil, precision: nil, scale: nil, default: nil
56
57
  end
57
58
 
58
- it 'sst_datatypes_migration' do
59
+ it "sst_datatypes_migration" do
59
60
  columns = SSTestDatatypeMigration.columns_hash
60
- generate_schema_for_table 'sst_datatypes_migration'
61
+ generate_schema_for_table "sst_datatypes_migration"
61
62
  # Simple Rails conventions
62
- _(columns['integer_col'].sql_type).must_equal 'int(4)'
63
- _(columns['bigint_col'].sql_type).must_equal 'bigint(8)'
64
- _(columns['boolean_col'].sql_type).must_equal 'bit'
65
- _(columns['decimal_col'].sql_type).must_equal 'decimal(18,0)'
66
- _(columns['float_col'].sql_type).must_equal 'float'
67
- _(columns['string_col'].sql_type).must_equal 'nvarchar(4000)'
68
- _(columns['text_col'].sql_type).must_equal 'nvarchar(max)'
69
- _(columns['datetime_col'].sql_type).must_equal 'datetime'
70
- _(columns['timestamp_col'].sql_type).must_equal 'datetime'
71
- _(columns['time_col'].sql_type).must_equal 'time(7)'
72
- _(columns['date_col'].sql_type).must_equal 'date'
73
- _(columns['binary_col'].sql_type).must_equal 'varbinary(max)'
74
- assert_line :integer_col, type: 'integer', limit: nil, precision: nil, scale: nil, default: nil
75
- assert_line :bigint_col, type: 'bigint', limit: nil, precision: nil, scale: nil, default: nil
76
- assert_line :boolean_col, type: 'boolean', limit: nil, precision: nil, scale: nil, default: nil
77
- assert_line :decimal_col, type: 'decimal', limit: nil, precision: 18, scale: 0, default: nil
78
- assert_line :float_col, type: 'float', limit: nil, precision: nil, scale: nil, default: nil
79
- assert_line :string_col, type: 'string', limit: nil, precision: nil, scale: nil, default: nil
80
- assert_line :text_col, type: 'text', limit: nil, precision: nil, scale: nil, default: nil
81
- assert_line :datetime_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
82
- assert_line :timestamp_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
83
- assert_line :time_col, type: 'time', limit: nil, precision: 7, scale: nil, default: nil
84
- assert_line :date_col, type: 'date', limit: nil, precision: nil, scale: nil, default: nil
85
- assert_line :binary_col, type: 'binary', limit: nil, precision: nil, scale: nil, default: nil
63
+ _(columns["integer_col"].sql_type).must_equal "int(4)"
64
+ _(columns["bigint_col"].sql_type).must_equal "bigint(8)"
65
+ _(columns["boolean_col"].sql_type).must_equal "bit"
66
+ _(columns["decimal_col"].sql_type).must_equal "decimal(18,0)"
67
+ _(columns["float_col"].sql_type).must_equal "float"
68
+ _(columns["string_col"].sql_type).must_equal "nvarchar(4000)"
69
+ _(columns["text_col"].sql_type).must_equal "nvarchar(max)"
70
+ _(columns["datetime_col"].sql_type).must_equal "datetime"
71
+ _(columns["timestamp_col"].sql_type).must_equal "datetime"
72
+ _(columns["time_col"].sql_type).must_equal "time(7)"
73
+ _(columns["date_col"].sql_type).must_equal "date"
74
+ _(columns["binary_col"].sql_type).must_equal "varbinary(max)"
75
+ assert_line :integer_col, type: "integer", limit: nil, precision: nil, scale: nil, default: nil
76
+ assert_line :bigint_col, type: "bigint", limit: nil, precision: nil, scale: nil, default: nil
77
+ assert_line :boolean_col, type: "boolean", limit: nil, precision: nil, scale: nil, default: nil
78
+ assert_line :decimal_col, type: "decimal", limit: nil, precision: 18, scale: 0, default: nil
79
+ assert_line :float_col, type: "float", limit: nil, precision: nil, scale: nil, default: nil
80
+ assert_line :string_col, type: "string", limit: nil, precision: nil, scale: nil, default: nil
81
+ assert_line :text_col, type: "text", limit: nil, precision: nil, scale: nil, default: nil
82
+ assert_line :datetime_col, type: "datetime", limit: nil, precision: nil, scale: nil, default: nil
83
+ assert_line :timestamp_col, type: "datetime", limit: nil, precision: nil, scale: nil, default: nil
84
+ assert_line :time_col, type: "time", limit: nil, precision: 7, scale: nil, default: nil
85
+ assert_line :date_col, type: "date", limit: nil, precision: nil, scale: nil, default: nil
86
+ assert_line :binary_col, type: "binary", limit: nil, precision: nil, scale: nil, default: nil
86
87
  # Our type methods.
87
- _(columns['real_col'].sql_type).must_equal 'real'
88
- _(columns['money_col'].sql_type).must_equal 'money'
89
- _(columns['smalldatetime_col'].sql_type).must_equal 'smalldatetime'
90
- _(columns['datetime2_col'].sql_type).must_equal 'datetime2(7)'
91
- _(columns['datetimeoffset'].sql_type).must_equal 'datetimeoffset(7)'
92
- _(columns['smallmoney_col'].sql_type).must_equal 'smallmoney'
93
- _(columns['char_col'].sql_type).must_equal 'char(1)'
94
- _(columns['varchar_col'].sql_type).must_equal 'varchar(8000)'
95
- _(columns['text_basic_col'].sql_type).must_equal 'text'
96
- _(columns['nchar_col'].sql_type).must_equal 'nchar(1)'
97
- _(columns['ntext_col'].sql_type).must_equal 'ntext'
98
- _(columns['binary_basic_col'].sql_type).must_equal 'binary(1)'
99
- _(columns['varbinary_col'].sql_type).must_equal 'varbinary(8000)'
100
- _(columns['uuid_col'].sql_type).must_equal 'uniqueidentifier'
101
- _(columns['sstimestamp_col'].sql_type).must_equal 'timestamp'
102
- _(columns['json_col'].sql_type).must_equal 'nvarchar(max)'
103
- assert_line :real_col, type: 'real', limit: nil, precision: nil, scale: nil, default: nil
104
- assert_line :money_col, type: 'money', limit: nil, precision: 19, scale: 4, default: nil
105
- assert_line :smalldatetime_col, type: 'smalldatetime', limit: nil, precision: nil, scale: nil, default: nil
106
- assert_line :datetime2_col, type: 'datetime', limit: nil, precision: 7, scale: nil, default: nil
107
- assert_line :datetimeoffset, type: 'datetimeoffset', limit: nil, precision: 7, scale: nil, default: nil
108
- assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil
109
- assert_line :char_col, type: 'char', limit: 1, precision: nil, scale: nil, default: nil
110
- assert_line :varchar_col, type: 'varchar', limit: nil, precision: nil, scale: nil, default: nil
111
- assert_line :text_basic_col, type: 'text_basic', limit: nil, precision: nil, scale: nil, default: nil
112
- assert_line :nchar_col, type: 'nchar', limit: 1, precision: nil, scale: nil, default: nil
113
- assert_line :ntext_col, type: 'ntext', limit: nil, precision: nil, scale: nil, default: nil
114
- assert_line :binary_basic_col, type: 'binary_basic', limit: 1, precision: nil, scale: nil, default: nil
115
- assert_line :varbinary_col, type: 'varbinary', limit: nil, precision: nil, scale: nil, default: nil
116
- assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
117
- assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
118
- assert_line :json_col, type: 'text', limit: nil, precision: nil, scale: nil, default: nil
88
+ _(columns["real_col"].sql_type).must_equal "real"
89
+ _(columns["money_col"].sql_type).must_equal "money"
90
+ _(columns["smalldatetime_col"].sql_type).must_equal "smalldatetime"
91
+ _(columns["datetime2_col"].sql_type).must_equal "datetime2(7)"
92
+ _(columns["datetimeoffset"].sql_type).must_equal "datetimeoffset(7)"
93
+ _(columns["smallmoney_col"].sql_type).must_equal "smallmoney"
94
+ _(columns["char_col"].sql_type).must_equal "char(1)"
95
+ _(columns["varchar_col"].sql_type).must_equal "varchar(8000)"
96
+ _(columns["text_basic_col"].sql_type).must_equal "text"
97
+ _(columns["nchar_col"].sql_type).must_equal "nchar(1)"
98
+ _(columns["ntext_col"].sql_type).must_equal "ntext"
99
+ _(columns["binary_basic_col"].sql_type).must_equal "binary(1)"
100
+ _(columns["varbinary_col"].sql_type).must_equal "varbinary(8000)"
101
+ _(columns["uuid_col"].sql_type).must_equal "uniqueidentifier"
102
+ _(columns["sstimestamp_col"].sql_type).must_equal "timestamp"
103
+ _(columns["json_col"].sql_type).must_equal "nvarchar(max)"
104
+ assert_line :real_col, type: "real", limit: nil, precision: nil, scale: nil, default: nil
105
+ assert_line :money_col, type: "money", limit: nil, precision: 19, scale: 4, default: nil
106
+ assert_line :smalldatetime_col, type: "smalldatetime", limit: nil, precision: nil, scale: nil, default: nil
107
+ assert_line :datetime2_col, type: "datetime", limit: nil, precision: 7, scale: nil, default: nil
108
+ assert_line :datetimeoffset, type: "datetimeoffset", limit: nil, precision: 7, scale: nil, default: nil
109
+ assert_line :smallmoney_col, type: "smallmoney", limit: nil, precision: 10, scale: 4, default: nil
110
+ assert_line :char_col, type: "char", limit: 1, precision: nil, scale: nil, default: nil
111
+ assert_line :varchar_col, type: "varchar", limit: nil, precision: nil, scale: nil, default: nil
112
+ assert_line :text_basic_col, type: "text_basic", limit: nil, precision: nil, scale: nil, default: nil
113
+ assert_line :nchar_col, type: "nchar", limit: 1, precision: nil, scale: nil, default: nil
114
+ assert_line :ntext_col, type: "ntext", limit: nil, precision: nil, scale: nil, default: nil
115
+ assert_line :binary_basic_col, type: "binary_basic", limit: 1, precision: nil, scale: nil, default: nil
116
+ assert_line :varbinary_col, type: "varbinary", limit: nil, precision: nil, scale: nil, default: nil
117
+ assert_line :uuid_col, type: "uuid", limit: nil, precision: nil, scale: nil, default: nil
118
+ assert_line :sstimestamp_col, type: "ss_timestamp", limit: nil, precision: nil, scale: nil, default: nil
119
+ assert_line :json_col, type: "text", limit: nil, precision: nil, scale: nil, default: nil
119
120
  end
120
121
 
121
122
  # Special Cases
122
123
 
123
- it 'honor nonstandard primary keys' do
124
- generate_schema_for_table('movies') do |output|
124
+ it "honor nonstandard primary keys" do
125
+ generate_schema_for_table("movies") do |output|
125
126
  match = output.match(%r{create_table "movies"(.*)do})
126
127
  assert_not_nil(match, "nonstandardpk table not found")
127
128
  assert_match %r(primary_key: "movieid"), match[1], "non-standard primary key not preserved"
128
129
  end
129
130
  end
130
131
 
131
- it 'no id with model driven primary key' do
132
- output = generate_schema_for_table 'sst_no_pk_data'
132
+ it "no id with model driven primary key" do
133
+ output = generate_schema_for_table "sst_no_pk_data"
133
134
  _(output).must_match %r{create_table "sst_no_pk_data".*id:\sfalse.*do}
134
- assert_line :name, type: 'string', limit: nil, default: nil, collation: nil
135
+ assert_line :name, type: "string", limit: nil, default: nil, collation: nil
135
136
  end
136
137
 
137
-
138
138
  private
139
139
 
140
140
  def generate_schema_for_table(*table_names)
141
- require 'stringio'
141
+ require "stringio"
142
142
  stream = StringIO.new
143
143
  ActiveRecord::SchemaDumper.ignore_tables = all_tables - table_names
144
144
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
@@ -148,6 +148,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
148
148
  type_matcher = /\A\s+t\.\w+\s+"(.*?)"[,\n]/
149
149
  @generated_schema.each_line do |line|
150
150
  next unless line =~ type_matcher
151
+
151
152
  @schema_lines[Regexp.last_match[1]] = SchemaLine.new(line)
152
153
  end
153
154
  @generated_schema
@@ -157,18 +158,19 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
157
158
  @schema_lines[column_name.to_s]
158
159
  end
159
160
 
160
- def assert_line(column_name, options={})
161
+ def assert_line(column_name, options = {})
161
162
  line = line(column_name)
162
163
  assert line, "Count not find line with column name: #{column_name.inspect} in schema:\n#{schema}"
163
164
  [:type, :limit, :precision, :scale, :collation, :default].each do |key|
164
165
  next unless options.key?(key)
166
+
165
167
  actual = key == :type ? line.send(:type_method) : line.send(key)
166
168
  expected = options[key]
167
169
  message = "#{key.to_s.titleize} of #{expected.inspect} not found in:\n#{line}"
168
170
  if expected.nil?
169
171
  _(actual).must_be_nil message
170
172
  elsif expected.is_a?(Array)
171
- actual.must_include expected, message
173
+ _(actual).must_include expected, message
172
174
  elsif expected.is_a?(Float)
173
175
  _(actual).must_be_close_to expected, 0.001
174
176
  elsif expected.is_a?(Proc)
@@ -180,7 +182,6 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
180
182
  end
181
183
 
182
184
  class SchemaLine
183
-
184
185
  LINE_PARSER = %r{t\.(\w+)\s+"(.*?)"[,\s+](.*)}
185
186
 
186
187
  attr_reader :line,
@@ -228,8 +229,5 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
228
229
  rescue SyntaxError
229
230
  {}
230
231
  end
231
-
232
232
  end
233
-
234
233
  end
235
-
@@ -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
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'
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
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'
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
35
+ it "from array condition" do
36
+ plan = Car.where(name: ["honda", "zyke"]).explain
37
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'
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
46
  _(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'
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