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,20 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
3
+ require "cases/helper_sqlserver"
4
4
 
5
5
  class SQLServerRakeTest < ActiveRecord::TestCase
6
-
7
6
  self.use_transactional_tests = false
8
7
 
9
8
  cattr_accessor :azure_skip
10
9
  self.azure_skip = connection_sqlserver_azure?
11
10
 
12
11
  let(:db_tasks) { ActiveRecord::Tasks::DatabaseTasks }
13
- let(:new_database) { 'activerecord_unittest_tasks' }
14
- let(:default_configuration) { ARTest.connection_config['arunit'] }
15
- let(:configuration) { default_configuration.merge('database' => new_database) }
12
+ let(:new_database) { "activerecord_unittest_tasks" }
13
+ let(:default_configuration) { ARTest.connection_config["arunit"] }
14
+ let(:configuration) { default_configuration.merge("database" => new_database) }
16
15
 
17
- before { skip 'on azure' if azure_skip }
16
+ before { skip "on azure" if azure_skip }
18
17
  before { disconnect! unless azure_skip }
19
18
  after { reconnect unless azure_skip }
20
19
 
@@ -27,7 +26,7 @@ class SQLServerRakeTest < ActiveRecord::TestCase
27
26
  def reconnect
28
27
  config = default_configuration
29
28
  if connection_sqlserver_azure?
30
- ActiveRecord::Base.establish_connection(config.merge('database' => 'master'))
29
+ ActiveRecord::Base.establish_connection(config.merge("database" => "master"))
31
30
  connection.drop_database(new_database) rescue nil
32
31
  disconnect!
33
32
  ActiveRecord::Base.establish_connection(config)
@@ -36,57 +35,51 @@ class SQLServerRakeTest < ActiveRecord::TestCase
36
35
  connection.drop_database(new_database) rescue nil
37
36
  end
38
37
  end
39
-
40
38
  end
41
39
 
42
40
  class SQLServerRakeCreateTest < SQLServerRakeTest
43
-
44
41
  self.azure_skip = false
45
42
 
46
- it 'establishes connection to database after create ' do
43
+ it "establishes connection to database after create " do
47
44
  quietly { db_tasks.create configuration }
48
45
  _(connection.current_database).must_equal(new_database)
49
46
  end
50
47
 
51
- it 'creates database with default collation' do
48
+ it "creates database with default collation" do
52
49
  quietly { db_tasks.create configuration }
53
- _(connection.collation).must_equal 'SQL_Latin1_General_CP1_CI_AS'
50
+ _(connection.collation).must_equal "SQL_Latin1_General_CP1_CI_AS"
54
51
  end
55
52
 
56
- it 'creates database with given collation' do
57
- quietly { db_tasks.create configuration.merge('collation' => 'Latin1_General_CI_AS') }
58
- _(connection.collation).must_equal 'Latin1_General_CI_AS'
53
+ it "creates database with given collation" do
54
+ quietly { db_tasks.create configuration.merge("collation" => "Latin1_General_CI_AS") }
55
+ _(connection.collation).must_equal "Latin1_General_CI_AS"
59
56
  end
60
57
 
61
- it 'prints error message when database exists' do
58
+ it "prints error message when database exists" do
62
59
  quietly { db_tasks.create configuration }
63
60
  message = capture(:stderr) { db_tasks.create configuration }
64
61
  _(message).must_match %r{activerecord_unittest_tasks.*already exists}
65
62
  end
66
-
67
63
  end
68
64
 
69
65
  class SQLServerRakeDropTest < SQLServerRakeTest
70
-
71
66
  self.azure_skip = false
72
67
 
73
- it 'drops database and uses master' do
68
+ it "drops database and uses master" do
74
69
  quietly do
75
70
  db_tasks.create configuration
76
71
  db_tasks.drop configuration
77
72
  end
78
- _(connection.current_database).must_equal 'master'
73
+ _(connection.current_database).must_equal "master"
79
74
  end
80
75
 
81
- it 'prints error message when database does not exist' do
82
- message = capture(:stderr) { db_tasks.drop configuration.merge('database' => 'doesnotexist') }
76
+ it "prints error message when database does not exist" do
77
+ message = capture(:stderr) { db_tasks.drop configuration.merge("database" => "doesnotexist") }
83
78
  _(message).must_match %r{'doesnotexist' does not exist}
84
79
  end
85
-
86
80
  end
87
81
 
88
82
  class SQLServerRakePurgeTest < SQLServerRakeTest
89
-
90
83
  before do
91
84
  quietly { db_tasks.create(configuration) }
92
85
  connection.create_table :users, force: true do |t|
@@ -95,43 +88,37 @@ class SQLServerRakePurgeTest < SQLServerRakeTest
95
88
  end
96
89
  end
97
90
 
98
- it 'clears active connections, drops database, and recreates with established connection' do
91
+ it "clears active connections, drops database, and recreates with established connection" do
99
92
  _(connection.current_database).must_equal(new_database)
100
- _(connection.tables).must_include 'users'
93
+ _(connection.tables).must_include "users"
101
94
  quietly { db_tasks.purge(configuration) }
102
95
  _(connection.current_database).must_equal(new_database)
103
- _(connection.tables).wont_include 'users'
96
+ _(connection.tables).wont_include "users"
104
97
  end
105
-
106
98
  end
107
99
 
108
100
  class SQLServerRakeCharsetTest < SQLServerRakeTest
109
-
110
101
  before do
111
102
  quietly { db_tasks.create(configuration) }
112
103
  end
113
104
 
114
- it 'retrieves charset' do
115
- _(db_tasks.charset(configuration)).must_equal 'iso_1'
105
+ it "retrieves charset" do
106
+ _(db_tasks.charset(configuration)).must_equal "iso_1"
116
107
  end
117
-
118
108
  end
119
109
 
120
110
  class SQLServerRakeCollationTest < SQLServerRakeTest
121
-
122
111
  before do
123
112
  quietly { db_tasks.create(configuration) }
124
113
  end
125
114
 
126
- it 'retrieves collation' do
127
- _(db_tasks.collation(configuration)).must_equal 'SQL_Latin1_General_CP1_CI_AS'
115
+ it "retrieves collation" do
116
+ _(db_tasks.collation(configuration)).must_equal "SQL_Latin1_General_CP1_CI_AS"
128
117
  end
129
-
130
118
  end
131
119
 
132
120
  class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
133
-
134
- let(:filename) { File.join ARTest::SQLServer.migrations_root, 'structure.sql' }
121
+ let(:filename) { File.join ARTest::SQLServer.migrations_root, "structure.sql" }
135
122
  let(:filedata) { File.read(filename) }
136
123
 
137
124
  before do
@@ -148,8 +135,8 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
148
135
  FileUtils.rm_rf(filename)
149
136
  end
150
137
 
151
- it 'dumps structure and accounts for defncopy oddities' do
152
- skip 'debug defncopy on windows later' if host_windows?
138
+ it "dumps structure and accounts for defncopy oddities" do
139
+ skip "debug defncopy on windows later" if host_windows?
153
140
  quietly { db_tasks.structure_dump configuration, filename }
154
141
  _(filedata).wont_match %r{\AUSE.*\z}
155
142
  _(filedata).wont_match %r{\AGO.*\z}
@@ -158,14 +145,13 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
158
145
  _(filedata).must_match %r{background2\s+text\s+}
159
146
  end
160
147
 
161
- it 'can load dumped structure' do
162
- skip 'debug defncopy on windows later' if host_windows?
148
+ it "can load dumped structure" do
149
+ skip "debug defncopy on windows later" if host_windows?
163
150
  quietly { db_tasks.structure_dump configuration, filename }
164
151
  _(filedata).must_match %r{CREATE TABLE dbo\.users}
165
152
  db_tasks.purge(configuration)
166
- _(connection.tables).wont_include 'users'
153
+ _(connection.tables).wont_include "users"
167
154
  db_tasks.load_schema configuration, :sql, filename
168
- _(connection.tables).must_include 'users'
155
+ _(connection.tables).must_include "users"
169
156
  end
170
-
171
157
  end
@@ -1,146 +1,144 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cases/helper_sqlserver'
3
+ require "cases/helper_sqlserver"
4
4
 
5
5
  class SchemaDumperTestSQLServer < ActiveRecord::TestCase
6
-
7
6
  before { all_tables }
8
7
 
9
8
  let(:all_tables) { ActiveRecord::Base.connection.tables }
10
9
  let(:schema) { @generated_schema }
11
10
 
12
- it 'sst_datatypes' do
13
- generate_schema_for_table 'sst_datatypes'
14
- assert_line :bigint, type: 'bigint', limit: nil, precision: nil, scale: nil, default: 42
15
- assert_line :int, type: 'integer', limit: nil, precision: nil, scale: nil, default: 42
16
- assert_line :smallint, type: 'integer', limit: 2, precision: nil, scale: nil, default: 42
17
- assert_line :tinyint, type: 'integer', limit: 1, precision: nil, scale: nil, default: 42
18
- assert_line :bit, type: 'boolean', limit: nil, precision: nil, scale: nil, default: true
19
- assert_line :decimal_9_2, type: 'decimal', limit: nil, precision: 9, scale: 2, default: 12345.01
20
- assert_line :numeric_18_0, type: 'decimal', limit: nil, precision: 18, scale: 0, default: 191.0
21
- assert_line :numeric_36_2, type: 'decimal', limit: nil, precision: 36, scale: 2, default: 12345678901234567890.01
22
- assert_line :money, type: 'money', limit: nil, precision: 19, scale: 4, default: 4.2
23
- 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
24
23
  # Approximate Numerics
25
- assert_line :float, type: 'float', limit: nil, precision: nil, scale: nil, default: 123.00000001
26
- 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
27
26
  # Date and Time
28
- assert_line :date, type: 'date', limit: nil, precision: nil, scale: nil, default: "01-01-0001"
29
- 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"
30
29
  if connection_dblib_73?
31
- assert_line :datetime2_7, type: 'datetime', limit: nil, precision: 7, scale: nil, default: "12-31-9999 23:59:59.9999999"
32
- assert_line :datetime2_3, type: 'datetime', limit: nil, precision: 3, scale: nil, default: nil
33
- 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
34
33
  end
35
- 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"
36
35
  if connection_dblib_73?
37
- assert_line :time_7, type: 'time', limit: nil, precision: 7, scale: nil, default: "04:20:00.2883215"
38
- assert_line :time_2, type: 'time', limit: nil, precision: 2, scale: nil, default: nil
39
- 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"
40
39
  end
41
40
  # Character Strings
42
- assert_line :char_10, type: 'char', limit: 10, precision: nil, scale: nil, default: "1234567890", collation: nil
43
- assert_line :varchar_50, type: 'varchar', limit: 50, precision: nil, scale: nil, default: "test varchar_50", collation: nil
44
- assert_line :varchar_max, type: 'varchar_max', limit: nil, precision: nil, scale: nil, default: "test varchar_max", collation: nil
45
- 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
46
45
  # Unicode Character Strings
47
- assert_line :nchar_10, type: 'nchar', limit: 10, precision: nil, scale: nil, default: "12345678åå", collation: nil
48
- assert_line :nvarchar_50, type: 'string', limit: 50, precision: nil, scale: nil, default: "test nvarchar_50 åå", collation: nil
49
- assert_line :nvarchar_max, type: 'text', limit: nil, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
50
- 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
51
50
  # Binary Strings
52
- assert_line :binary_49, type: 'binary_basic', limit: 49, precision: nil, scale: nil, default: nil
53
- assert_line :varbinary_49, type: 'varbinary', limit: 49, precision: nil, scale: nil, default: nil
54
- 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
55
54
  # Other Data Types
56
- assert_line :uniqueidentifier, type: 'uuid', limit: nil, precision: nil, scale: nil, default: -> { "newid()" }
57
- 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
58
57
  end
59
58
 
60
- it 'sst_datatypes_migration' do
59
+ it "sst_datatypes_migration" do
61
60
  columns = SSTestDatatypeMigration.columns_hash
62
- generate_schema_for_table 'sst_datatypes_migration'
61
+ generate_schema_for_table "sst_datatypes_migration"
63
62
  # Simple Rails conventions
64
- _(columns['integer_col'].sql_type).must_equal 'int(4)'
65
- _(columns['bigint_col'].sql_type).must_equal 'bigint(8)'
66
- _(columns['boolean_col'].sql_type).must_equal 'bit'
67
- _(columns['decimal_col'].sql_type).must_equal 'decimal(18,0)'
68
- _(columns['float_col'].sql_type).must_equal 'float'
69
- _(columns['string_col'].sql_type).must_equal 'nvarchar(4000)'
70
- _(columns['text_col'].sql_type).must_equal 'nvarchar(max)'
71
- _(columns['datetime_col'].sql_type).must_equal 'datetime'
72
- _(columns['timestamp_col'].sql_type).must_equal 'datetime'
73
- _(columns['time_col'].sql_type).must_equal 'time(7)'
74
- _(columns['date_col'].sql_type).must_equal 'date'
75
- _(columns['binary_col'].sql_type).must_equal 'varbinary(max)'
76
- assert_line :integer_col, type: 'integer', limit: nil, precision: nil, scale: nil, default: nil
77
- assert_line :bigint_col, type: 'bigint', limit: nil, precision: nil, scale: nil, default: nil
78
- assert_line :boolean_col, type: 'boolean', limit: nil, precision: nil, scale: nil, default: nil
79
- assert_line :decimal_col, type: 'decimal', limit: nil, precision: 18, scale: 0, default: nil
80
- assert_line :float_col, type: 'float', limit: nil, precision: nil, scale: nil, default: nil
81
- assert_line :string_col, type: 'string', limit: nil, precision: nil, scale: nil, default: nil
82
- assert_line :text_col, type: 'text', limit: nil, precision: nil, scale: nil, default: nil
83
- assert_line :datetime_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
84
- assert_line :timestamp_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
85
- assert_line :time_col, type: 'time', limit: nil, precision: 7, scale: nil, default: nil
86
- assert_line :date_col, type: 'date', limit: nil, precision: nil, scale: nil, default: nil
87
- 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
88
87
  # Our type methods.
89
- _(columns['real_col'].sql_type).must_equal 'real'
90
- _(columns['money_col'].sql_type).must_equal 'money'
91
- _(columns['smalldatetime_col'].sql_type).must_equal 'smalldatetime'
92
- _(columns['datetime2_col'].sql_type).must_equal 'datetime2(7)'
93
- _(columns['datetimeoffset'].sql_type).must_equal 'datetimeoffset(7)'
94
- _(columns['smallmoney_col'].sql_type).must_equal 'smallmoney'
95
- _(columns['char_col'].sql_type).must_equal 'char(1)'
96
- _(columns['varchar_col'].sql_type).must_equal 'varchar(8000)'
97
- _(columns['text_basic_col'].sql_type).must_equal 'text'
98
- _(columns['nchar_col'].sql_type).must_equal 'nchar(1)'
99
- _(columns['ntext_col'].sql_type).must_equal 'ntext'
100
- _(columns['binary_basic_col'].sql_type).must_equal 'binary(1)'
101
- _(columns['varbinary_col'].sql_type).must_equal 'varbinary(8000)'
102
- _(columns['uuid_col'].sql_type).must_equal 'uniqueidentifier'
103
- _(columns['sstimestamp_col'].sql_type).must_equal 'timestamp'
104
- _(columns['json_col'].sql_type).must_equal 'nvarchar(max)'
105
- assert_line :real_col, type: 'real', limit: nil, precision: nil, scale: nil, default: nil
106
- assert_line :money_col, type: 'money', limit: nil, precision: 19, scale: 4, default: nil
107
- assert_line :smalldatetime_col, type: 'smalldatetime', limit: nil, precision: nil, scale: nil, default: nil
108
- assert_line :datetime2_col, type: 'datetime', limit: nil, precision: 7, scale: nil, default: nil
109
- assert_line :datetimeoffset, type: 'datetimeoffset', limit: nil, precision: 7, scale: nil, default: nil
110
- assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil
111
- assert_line :char_col, type: 'char', limit: 1, precision: nil, scale: nil, default: nil
112
- assert_line :varchar_col, type: 'varchar', limit: nil, precision: nil, scale: nil, default: nil
113
- assert_line :text_basic_col, type: 'text_basic', limit: nil, precision: nil, scale: nil, default: nil
114
- assert_line :nchar_col, type: 'nchar', limit: 1, precision: nil, scale: nil, default: nil
115
- assert_line :ntext_col, type: 'ntext', limit: nil, precision: nil, scale: nil, default: nil
116
- assert_line :binary_basic_col, type: 'binary_basic', limit: 1, precision: nil, scale: nil, default: nil
117
- assert_line :varbinary_col, type: 'varbinary', limit: nil, precision: nil, scale: nil, default: nil
118
- assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
119
- assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
120
- 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
121
120
  end
122
121
 
123
122
  # Special Cases
124
123
 
125
- it 'honor nonstandard primary keys' do
126
- generate_schema_for_table('movies') do |output|
124
+ it "honor nonstandard primary keys" do
125
+ generate_schema_for_table("movies") do |output|
127
126
  match = output.match(%r{create_table "movies"(.*)do})
128
127
  assert_not_nil(match, "nonstandardpk table not found")
129
128
  assert_match %r(primary_key: "movieid"), match[1], "non-standard primary key not preserved"
130
129
  end
131
130
  end
132
131
 
133
- it 'no id with model driven primary key' do
134
- 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"
135
134
  _(output).must_match %r{create_table "sst_no_pk_data".*id:\sfalse.*do}
136
- assert_line :name, type: 'string', limit: nil, default: nil, collation: nil
135
+ assert_line :name, type: "string", limit: nil, default: nil, collation: nil
137
136
  end
138
137
 
139
-
140
138
  private
141
139
 
142
140
  def generate_schema_for_table(*table_names)
143
- require 'stringio'
141
+ require "stringio"
144
142
  stream = StringIO.new
145
143
  ActiveRecord::SchemaDumper.ignore_tables = all_tables - table_names
146
144
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
@@ -150,6 +148,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
150
148
  type_matcher = /\A\s+t\.\w+\s+"(.*?)"[,\n]/
151
149
  @generated_schema.each_line do |line|
152
150
  next unless line =~ type_matcher
151
+
153
152
  @schema_lines[Regexp.last_match[1]] = SchemaLine.new(line)
154
153
  end
155
154
  @generated_schema
@@ -159,11 +158,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
159
158
  @schema_lines[column_name.to_s]
160
159
  end
161
160
 
162
- def assert_line(column_name, options={})
161
+ def assert_line(column_name, options = {})
163
162
  line = line(column_name)
164
163
  assert line, "Count not find line with column name: #{column_name.inspect} in schema:\n#{schema}"
165
164
  [:type, :limit, :precision, :scale, :collation, :default].each do |key|
166
165
  next unless options.key?(key)
166
+
167
167
  actual = key == :type ? line.send(:type_method) : line.send(key)
168
168
  expected = options[key]
169
169
  message = "#{key.to_s.titleize} of #{expected.inspect} not found in:\n#{line}"
@@ -182,7 +182,6 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
182
182
  end
183
183
 
184
184
  class SchemaLine
185
-
186
185
  LINE_PARSER = %r{t\.(\w+)\s+"(.*?)"[,\s+](.*)}
187
186
 
188
187
  attr_reader :line,
@@ -230,8 +229,5 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
230
229
  rescue SyntaxError
231
230
  {}
232
231
  end
233
-
234
232
  end
235
-
236
233
  end
237
-