activerecord-sqlserver-adapter 8.0.10 → 8.1.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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +1 -1
  3. data/.github/workflows/ci.yml +34 -3
  4. data/CHANGELOG.md +14 -68
  5. data/Dockerfile.ci +1 -1
  6. data/Gemfile +7 -9
  7. data/Guardfile +2 -2
  8. data/README.md +33 -13
  9. data/Rakefile +1 -1
  10. data/VERSION +1 -1
  11. data/activerecord-sqlserver-adapter.gemspec +15 -16
  12. data/compose.ci.yaml +8 -1
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -1
  14. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -2
  15. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +1 -1
  16. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +4 -4
  17. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +118 -83
  18. data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +3 -4
  19. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +7 -7
  20. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +24 -12
  21. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +17 -8
  22. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +162 -156
  23. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
  24. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +5 -5
  25. data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +2 -7
  26. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +3 -1
  27. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +3 -3
  28. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +3 -3
  29. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +3 -4
  30. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +1 -1
  31. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +4 -6
  32. data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +1 -1
  33. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +0 -2
  34. data/lib/active_record/connection_adapters/sqlserver/utils.rb +10 -12
  35. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +118 -66
  36. data/lib/active_record/connection_adapters/sqlserver_column.rb +17 -9
  37. data/lib/active_record/tasks/sqlserver_database_tasks.rb +5 -5
  38. data/lib/arel/visitors/sqlserver.rb +55 -26
  39. data/test/cases/active_schema_test_sqlserver.rb +45 -23
  40. data/test/cases/adapter_test_sqlserver.rb +72 -59
  41. data/test/cases/coerced_tests.rb +365 -161
  42. data/test/cases/column_test_sqlserver.rb +328 -316
  43. data/test/cases/connection_test_sqlserver.rb +15 -11
  44. data/test/cases/enum_test_sqlserver.rb +8 -9
  45. data/test/cases/execute_procedure_test_sqlserver.rb +1 -1
  46. data/test/cases/fetch_test_sqlserver.rb +1 -1
  47. data/test/cases/helper_sqlserver.rb +7 -3
  48. data/test/cases/index_test_sqlserver.rb +8 -6
  49. data/test/cases/insert_all_test_sqlserver.rb +3 -28
  50. data/test/cases/json_test_sqlserver.rb +8 -8
  51. data/test/cases/lateral_test_sqlserver.rb +2 -2
  52. data/test/cases/migration_test_sqlserver.rb +12 -12
  53. data/test/cases/pessimistic_locking_test_sqlserver.rb +6 -6
  54. data/test/cases/primary_keys_test_sqlserver.rb +4 -4
  55. data/test/cases/rake_test_sqlserver.rb +15 -7
  56. data/test/cases/schema_dumper_test_sqlserver.rb +109 -113
  57. data/test/cases/schema_test_sqlserver.rb +7 -7
  58. data/test/cases/transaction_test_sqlserver.rb +6 -8
  59. data/test/cases/trigger_test_sqlserver.rb +1 -1
  60. data/test/cases/utils_test_sqlserver.rb +3 -3
  61. data/test/cases/view_test_sqlserver.rb +12 -8
  62. data/test/cases/virtual_column_test_sqlserver.rb +113 -0
  63. data/test/migrations/create_clients_and_change_column_collation.rb +2 -2
  64. data/test/models/sqlserver/edge_schema.rb +2 -2
  65. data/test/schema/sqlserver_specific_schema.rb +49 -37
  66. data/test/support/coerceable_test_sqlserver.rb +10 -10
  67. data/test/support/connection_reflection.rb +0 -5
  68. data/test/support/core_ext/backtrace_cleaner.rb +36 -0
  69. data/test/support/query_assertions.rb +6 -6
  70. data/test/support/rake_helpers.rb +6 -10
  71. metadata +12 -107
@@ -11,11 +11,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
11
11
  describe "ActiveRecord::ConnectionAdapters::SQLServer::Type" do
12
12
  let(:obj) { SSTestDatatype.new }
13
13
 
14
- Type = ActiveRecord::ConnectionAdapters::SQLServer::Type
15
-
16
- def new_obj; SSTestDatatype.new; end
14
+ def new_obj
15
+ SSTestDatatype.new
16
+ end
17
17
 
18
- def column(name); SSTestDatatype.columns_hash[name]; end
18
+ def column(name)
19
+ SSTestDatatype.columns_hash[name]
20
+ end
19
21
 
20
22
  def assert_obj_set_and_save(attribute, value)
21
23
  obj.send :"#{attribute}=", value
@@ -30,80 +32,80 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
30
32
 
31
33
  it "int(4) PRIMARY KEY" do
32
34
  col = column("id")
33
- _(col.sql_type).must_equal "int(4)"
34
- _(col.null).must_equal false
35
+ _(col.sql_type).must_equal "int(4)"
36
+ _(col.null).must_equal false
35
37
  end
36
38
 
37
39
  it "bigint(8)" do
38
40
  col = column("bigint")
39
- _(col.sql_type).must_equal "bigint(8)"
40
- _(col.type).must_equal :integer
41
- _(col.null).must_equal true
42
- _(col.default).must_equal 42
43
- _(obj.bigint).must_equal 42
44
- _(col.default_function).must_be_nil
45
- type = connection.lookup_cast_type_from_column(col)
46
- _(type).must_be_instance_of Type::BigInteger
47
- _(type.limit).must_equal 8
41
+ _(col.sql_type).must_equal "bigint(8)"
42
+ _(col.type).must_equal :integer
43
+ _(col.null).must_equal true
44
+ _(col.default).must_equal 42
45
+ _(obj.bigint).must_equal 42
46
+ _(col.default_function).must_be_nil
47
+ type = col.fetch_cast_type(connection)
48
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::BigInteger
49
+ _(type.limit).must_equal 8
48
50
  assert_obj_set_and_save :bigint, -9_223_372_036_854_775_808
49
51
  assert_obj_set_and_save :bigint, 9_223_372_036_854_775_807
50
52
  end
51
53
 
52
54
  it "int(4)" do
53
55
  col = column("int")
54
- _(col.sql_type).must_equal "int(4)"
55
- _(col.type).must_equal :integer
56
- _(col.null).must_equal true
57
- _(col.default).must_equal 42
58
- _(obj.int).must_equal 42
59
- _(col.default_function).must_be_nil
60
- type = connection.lookup_cast_type_from_column(col)
61
- _(type).must_be_instance_of Type::Integer
62
- _(type.limit).must_equal 4
56
+ _(col.sql_type).must_equal "int(4)"
57
+ _(col.type).must_equal :integer
58
+ _(col.null).must_equal true
59
+ _(col.default).must_equal 42
60
+ _(obj.int).must_equal 42
61
+ _(col.default_function).must_be_nil
62
+ type = col.fetch_cast_type(connection)
63
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Integer
64
+ _(type.limit).must_equal 4
63
65
  assert_obj_set_and_save :int, -2_147_483_648
64
66
  assert_obj_set_and_save :int, 2_147_483_647
65
67
  end
66
68
 
67
69
  it "smallint(2)" do
68
70
  col = column("smallint")
69
- _(col.sql_type).must_equal "smallint(2)"
70
- _(col.type).must_equal :integer
71
- _(col.null).must_equal true
72
- _(col.default).must_equal 42
73
- _(obj.smallint).must_equal 42
74
- _(col.default_function).must_be_nil
75
- type = connection.lookup_cast_type_from_column(col)
76
- _(type).must_be_instance_of Type::SmallInteger
77
- _(type.limit).must_equal 2
71
+ _(col.sql_type).must_equal "smallint(2)"
72
+ _(col.type).must_equal :integer
73
+ _(col.null).must_equal true
74
+ _(col.default).must_equal 42
75
+ _(obj.smallint).must_equal 42
76
+ _(col.default_function).must_be_nil
77
+ type = col.fetch_cast_type(connection)
78
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::SmallInteger
79
+ _(type.limit).must_equal 2
78
80
  assert_obj_set_and_save :smallint, -32_768
79
81
  assert_obj_set_and_save :smallint, 32_767
80
82
  end
81
83
 
82
84
  it "tinyint(1)" do
83
85
  col = column("tinyint")
84
- _(col.sql_type).must_equal "tinyint(1)"
85
- _(col.type).must_equal :integer
86
- _(col.null).must_equal true
87
- _(col.default).must_equal 42
88
- _(obj.tinyint).must_equal 42
89
- _(col.default_function).must_be_nil
90
- type = connection.lookup_cast_type_from_column(col)
91
- _(type).must_be_instance_of Type::TinyInteger
92
- _(type.limit).must_equal 1
86
+ _(col.sql_type).must_equal "tinyint(1)"
87
+ _(col.type).must_equal :integer
88
+ _(col.null).must_equal true
89
+ _(col.default).must_equal 42
90
+ _(obj.tinyint).must_equal 42
91
+ _(col.default_function).must_be_nil
92
+ type = col.fetch_cast_type(connection)
93
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::TinyInteger
94
+ _(type.limit).must_equal 1
93
95
  assert_obj_set_and_save :tinyint, 0
94
96
  assert_obj_set_and_save :tinyint, 255
95
97
  end
96
98
 
97
99
  it "bit" do
98
100
  col = column("bit")
99
- _(col.sql_type).must_equal "bit"
100
- _(col.type).must_equal :boolean
101
- _(col.null).must_equal true
102
- _(col.default).must_equal true
103
- _(obj.bit).must_equal true
104
- _(col.default_function).must_be_nil
105
- type = connection.lookup_cast_type_from_column(col)
106
- _(type).must_be_instance_of Type::Boolean
101
+ _(col.sql_type).must_equal "bit"
102
+ _(col.type).must_equal :boolean
103
+ _(col.null).must_equal true
104
+ _(col.default).must_equal true
105
+ _(obj.bit).must_equal true
106
+ _(col.default_function).must_be_nil
107
+ type = col.fetch_cast_type(connection)
108
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Boolean
107
109
  _(type.limit).must_be_nil
108
110
  obj.bit = 0
109
111
  _(obj.bit).must_equal false
@@ -117,17 +119,17 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
117
119
 
118
120
  it "decimal(9,2)" do
119
121
  col = column("decimal_9_2")
120
- _(col.sql_type).must_equal "decimal(9,2)"
121
- _(col.type).must_equal :decimal
122
- _(col.null).must_equal true
123
- _(col.default).must_equal BigDecimal("12345.01")
124
- _(obj.decimal_9_2).must_equal BigDecimal("12345.01")
125
- _(col.default_function).must_be_nil
126
- type = connection.lookup_cast_type_from_column(col)
127
- _(type).must_be_instance_of Type::Decimal
122
+ _(col.sql_type).must_equal "decimal(9,2)"
123
+ _(col.type).must_equal :decimal
124
+ _(col.null).must_equal true
125
+ _(col.default).must_equal BigDecimal("12345.01")
126
+ _(obj.decimal_9_2).must_equal BigDecimal("12345.01")
127
+ _(col.default_function).must_be_nil
128
+ type = col.fetch_cast_type(connection)
129
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Decimal
128
130
  _(type.limit).must_be_nil
129
- _(type.precision).must_equal 9
130
- _(type.scale).must_equal 2
131
+ _(type.precision).must_equal 9
132
+ _(type.scale).must_equal 2
131
133
  obj.decimal_9_2 = "1234567.8901"
132
134
  _(obj.decimal_9_2).must_equal BigDecimal("1234567.89")
133
135
  obj.save!
@@ -136,13 +138,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
136
138
 
137
139
  it "decimal(16,4)" do
138
140
  col = column("decimal_16_4")
139
- _(col.sql_type).must_equal "decimal(16,4)"
140
- _(col.default).must_equal BigDecimal("1234567.89")
141
- _(obj.decimal_16_4).must_equal BigDecimal("1234567.89")
141
+ _(col.sql_type).must_equal "decimal(16,4)"
142
+ _(col.default).must_equal BigDecimal("1234567.89")
143
+ _(obj.decimal_16_4).must_equal BigDecimal("1234567.89")
142
144
  _(col.default_function).must_be_nil
143
- type = connection.lookup_cast_type_from_column(col)
144
- _(type.precision).must_equal 16
145
- _(type.scale).must_equal 4
145
+ type = col.fetch_cast_type(connection)
146
+ _(type.precision).must_equal 16
147
+ _(type.scale).must_equal 4
146
148
  obj.decimal_16_4 = "1234567.8901001"
147
149
  _(obj.decimal_16_4).must_equal BigDecimal("1234567.8901")
148
150
  obj.save!
@@ -151,39 +153,39 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
151
153
 
152
154
  it "numeric(18,0)" do
153
155
  col = column("numeric_18_0")
154
- _(col.sql_type).must_equal "numeric(18,0)"
155
- _(col.type).must_equal :decimal
156
- _(col.null).must_equal true
157
- _(col.default).must_equal BigDecimal("191")
158
- _(obj.numeric_18_0).must_equal BigDecimal("191")
156
+ _(col.sql_type).must_equal "numeric(18,0)"
157
+ _(col.type).must_equal :decimal
158
+ _(col.null).must_equal true
159
+ _(col.default).must_equal BigDecimal(191)
160
+ _(obj.numeric_18_0).must_equal BigDecimal(191)
159
161
  _(col.default_function).must_be_nil
160
162
 
161
- type = connection.lookup_cast_type_from_column(col)
162
- _(type).must_be_instance_of Type::DecimalWithoutScale
163
+ type = col.fetch_cast_type(connection)
164
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::DecimalWithoutScale
163
165
  _(type.limit).must_be_nil
164
- _(type.precision).must_equal 18
166
+ _(type.precision).must_equal 18
165
167
  _(type.scale).must_be_nil
166
168
 
167
169
  obj.numeric_18_0 = "192.1"
168
- _(obj.numeric_18_0).must_equal BigDecimal("192")
170
+ _(obj.numeric_18_0).must_equal BigDecimal(192)
169
171
 
170
172
  obj.save!
171
- _(obj.reload.numeric_18_0).must_equal BigDecimal("192")
173
+ _(obj.reload.numeric_18_0).must_equal BigDecimal(192)
172
174
  end
173
175
 
174
176
  it "numeric(36,2)" do
175
177
  col = column("numeric_36_2")
176
- _(col.sql_type).must_equal "numeric(36,2)"
177
- _(col.type).must_equal :decimal
178
- _(col.null).must_equal true
179
- _(col.default).must_equal BigDecimal("12345678901234567890.01")
180
- _(obj.numeric_36_2).must_equal BigDecimal("12345678901234567890.01")
181
- _(col.default_function).must_be_nil
182
- type = connection.lookup_cast_type_from_column(col)
183
- _(type).must_be_instance_of Type::Decimal
178
+ _(col.sql_type).must_equal "numeric(36,2)"
179
+ _(col.type).must_equal :decimal
180
+ _(col.null).must_equal true
181
+ _(col.default).must_equal BigDecimal("12345678901234567890.01")
182
+ _(obj.numeric_36_2).must_equal BigDecimal("12345678901234567890.01")
183
+ _(col.default_function).must_be_nil
184
+ type = col.fetch_cast_type(connection)
185
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Decimal
184
186
  _(type.limit).must_be_nil
185
- _(type.precision).must_equal 36
186
- _(type.scale).must_equal 2
187
+ _(type.precision).must_equal 36
188
+ _(type.scale).must_equal 2
187
189
  obj.numeric_36_2 = "192.123"
188
190
  _(obj.numeric_36_2).must_equal BigDecimal("192.12")
189
191
  obj.save!
@@ -192,17 +194,17 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
192
194
 
193
195
  it "money" do
194
196
  col = column("money")
195
- _(col.sql_type).must_equal "money"
196
- _(col.type).must_equal :money
197
- _(col.null).must_equal true
198
- _(col.default).must_equal BigDecimal("4.20")
199
- _(obj.money).must_equal BigDecimal("4.20")
200
- _(col.default_function).must_be_nil
201
- type = connection.lookup_cast_type_from_column(col)
202
- _(type).must_be_instance_of Type::Money
197
+ _(col.sql_type).must_equal "money"
198
+ _(col.type).must_equal :money
199
+ _(col.null).must_equal true
200
+ _(col.default).must_equal BigDecimal("4.20")
201
+ _(obj.money).must_equal BigDecimal("4.20")
202
+ _(col.default_function).must_be_nil
203
+ type = col.fetch_cast_type(connection)
204
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Money
203
205
  _(type.limit).must_be_nil
204
- _(type.precision).must_equal 19
205
- _(type.scale).must_equal 4
206
+ _(type.precision).must_equal 19
207
+ _(type.scale).must_equal 4
206
208
  obj.money = "922337203685477.58061"
207
209
  _(obj.money).must_equal BigDecimal("922337203685477.5806")
208
210
  obj.save!
@@ -211,17 +213,17 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
211
213
 
212
214
  it "smallmoney" do
213
215
  col = column("smallmoney")
214
- _(col.sql_type).must_equal "smallmoney"
215
- _(col.type).must_equal :smallmoney
216
- _(col.null).must_equal true
217
- _(col.default).must_equal BigDecimal("4.20")
218
- _(obj.smallmoney).must_equal BigDecimal("4.20")
219
- _(col.default_function).must_be_nil
220
- type = connection.lookup_cast_type_from_column(col)
221
- _(type).must_be_instance_of Type::SmallMoney
216
+ _(col.sql_type).must_equal "smallmoney"
217
+ _(col.type).must_equal :smallmoney
218
+ _(col.null).must_equal true
219
+ _(col.default).must_equal BigDecimal("4.20")
220
+ _(obj.smallmoney).must_equal BigDecimal("4.20")
221
+ _(col.default_function).must_be_nil
222
+ type = col.fetch_cast_type(connection)
223
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::SmallMoney
222
224
  _(type.limit).must_be_nil
223
- _(type.precision).must_equal 10
224
- _(type.scale).must_equal 4
225
+ _(type.precision).must_equal 10
226
+ _(type.scale).must_equal 4
225
227
  obj.smallmoney = "214748.36461"
226
228
  _(obj.smallmoney).must_equal BigDecimal("214748.3646")
227
229
  obj.save!
@@ -234,14 +236,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
234
236
 
235
237
  it "float" do
236
238
  col = column("float")
237
- _(col.sql_type).must_equal "float"
238
- _(col.type).must_equal :float
239
- _(col.null).must_equal true
240
- _(col.default).must_equal 123.00000001
241
- _(obj.float).must_equal 123.00000001
242
- _(col.default_function).must_be_nil
243
- type = connection.lookup_cast_type_from_column(col)
244
- _(type).must_be_instance_of Type::Float
239
+ _(col.sql_type).must_equal "float"
240
+ _(col.type).must_equal :float
241
+ _(col.null).must_equal true
242
+ _(col.default).must_equal 123.00000001
243
+ _(obj.float).must_equal 123.00000001
244
+ _(col.default_function).must_be_nil
245
+ type = col.fetch_cast_type(connection)
246
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Float
245
247
  _(type.limit).must_be_nil
246
248
  _(type.precision).must_be_nil
247
249
  _(type.scale).must_be_nil
@@ -253,14 +255,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
253
255
 
254
256
  it "real" do
255
257
  col = column("real")
256
- _(col.sql_type).must_equal "real"
257
- _(col.type).must_equal :real
258
- _(col.null).must_equal true
259
- _(col.default).must_be_close_to 123.45, 0.01
260
- _(obj.real).must_be_close_to 123.45, 0.01
261
- _(col.default_function).must_be_nil
262
- type = connection.lookup_cast_type_from_column(col)
263
- _(type).must_be_instance_of Type::Real
258
+ _(col.sql_type).must_equal "real"
259
+ _(col.type).must_equal :real
260
+ _(col.null).must_equal true
261
+ _(col.default).must_be_close_to 123.45, 0.01
262
+ _(obj.real).must_be_close_to 123.45, 0.01
263
+ _(col.default_function).must_be_nil
264
+ type = col.fetch_cast_type(connection)
265
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Real
264
266
  _(type.limit).must_be_nil
265
267
  _(type.precision).must_be_nil
266
268
  _(type.scale).must_be_nil
@@ -274,14 +276,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
274
276
 
275
277
  it "date" do
276
278
  col = column("date")
277
- _(col.sql_type).must_equal "date"
278
- _(col.type).must_equal :date
279
- _(col.null).must_equal true
280
- _(col.default).must_equal connection_tds_73 ? Date.civil(1, 1, 1) : "0001-01-01"
281
- _(obj.date).must_equal Date.civil(1, 1, 1)
282
- _(col.default_function).must_be_nil
283
- type = connection.lookup_cast_type_from_column(col)
284
- _(type).must_be_instance_of Type::Date
279
+ _(col.sql_type).must_equal "date"
280
+ _(col.type).must_equal :date
281
+ _(col.null).must_equal true
282
+ _(col.default).must_equal Date.civil(1, 1, 1)
283
+ _(obj.date).must_equal Date.civil(1, 1, 1)
284
+ _(col.default_function).must_be_nil
285
+ type = col.fetch_cast_type(connection)
286
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Date
285
287
  _(type.limit).must_be_nil
286
288
  _(type.precision).must_be_nil
287
289
  _(type.scale).must_be_nil
@@ -305,22 +307,22 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
305
307
  assert_obj_set_and_save :date, Date.civil(1972, 4, 14)
306
308
  # Can accept and cast time objects.
307
309
  obj.date = Time.utc(2010, 4, 14, 12, 34, 56, 3000)
308
- _(obj.date).must_equal Date.civil(2010, 4, 14)
310
+ _(obj.date).must_equal Date.civil(2010, 4, 14)
309
311
  obj.save!
310
312
  _(obj.reload.date).must_equal Date.civil(2010, 4, 14)
311
313
  end
312
314
 
313
315
  it "datetime" do
314
316
  col = column("datetime")
315
- _(col.sql_type).must_equal "datetime"
316
- _(col.type).must_equal :datetime
317
- _(col.null).must_equal true
317
+ _(col.sql_type).must_equal "datetime"
318
+ _(col.type).must_equal :datetime
319
+ _(col.null).must_equal true
318
320
  time = Time.utc 1753, 1, 1, 0, 0, 0, 123000
319
- _(col.default).must_equal time, "Microseconds were <#{col.default.usec}> vs <123000>"
320
- _(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
321
+ _(col.default).must_equal time, "Microseconds were <#{col.default.usec}> vs <123000>"
322
+ _(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
321
323
  _(col.default_function).must_be_nil
322
- type = connection.lookup_cast_type_from_column(col)
323
- _(type).must_be_instance_of Type::DateTime
324
+ type = col.fetch_cast_type(connection)
325
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::DateTime
324
326
  _(type.limit).must_be_nil
325
327
  _(type.precision).must_be_nil
326
328
  _(type.scale).must_be_nil
@@ -357,23 +359,22 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
357
359
  end
358
360
 
359
361
  it "datetime2" do
360
- skip "datetime2 not supported in this protocol version" unless connection_tds_73
361
362
  col = column("datetime2_7")
362
- _(col.sql_type).must_equal "datetime2(7)"
363
- _(col.type).must_equal :datetime
364
- _(col.null).must_equal true
363
+ _(col.sql_type).must_equal "datetime2(7)"
364
+ _(col.type).must_equal :datetime
365
+ _(col.null).must_equal true
365
366
  time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(999999900, 1000)
366
- _(col.default).must_equal time, "Nanoseconds were <#{col.default.nsec}> vs <999999900>"
367
- _(obj.datetime2_7).must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
367
+ _(col.default).must_equal time, "Nanoseconds were <#{col.default.nsec}> vs <999999900>"
368
+ _(obj.datetime2_7).must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
368
369
  _(col.default_function).must_be_nil
369
- type = connection.lookup_cast_type_from_column(col)
370
- _(type).must_be_instance_of Type::DateTime2
370
+ type = col.fetch_cast_type(connection)
371
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::DateTime2
371
372
  _(type.limit).must_be_nil
372
373
  _(type.precision).must_equal 7
373
374
  _(type.scale).must_be_nil
374
375
  obj.save!
375
376
  _(obj).must_equal obj.class.where(datetime2_7: time).first
376
- # Can save 100 nanosecond precisoins and return again.
377
+ # Can save 100 nanosecond precisions and return again.
377
378
  time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456755, 1000)
378
379
  time2 = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456800, 1000)
379
380
  obj.datetime2_7 = time
@@ -384,7 +385,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
384
385
  _(obj.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456800>"
385
386
  _(obj).must_equal obj.class.where(datetime2_7: time).first
386
387
  _(obj).must_equal obj.class.where(datetime2_7: time2).first
387
- # Can save small fraction nanosecond precisoins and return again.
388
+ # Can save small fraction nanosecond precisions and return again.
388
389
  time = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15020, 1000)
389
390
  time2 = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15000, 1000)
390
391
  obj.datetime2_7 = time
@@ -396,42 +397,44 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
396
397
  # datetime2_3
397
398
  time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456789, 1000)
398
399
  col = column("datetime2_3")
399
- _(connection.lookup_cast_type_from_column(col).precision).must_equal 3
400
+ _(col.fetch_cast_type(connection).precision).must_equal 3
400
401
  obj.datetime2_3 = time
401
402
  _(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
402
- obj.save!; obj.reload
403
+ obj.save!
404
+ obj.reload
403
405
  _(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
404
406
  _(obj).must_equal obj.class.where(datetime2_3: time).first
405
407
  # datetime2_1
406
408
  col = column("datetime2_1")
407
- _(connection.lookup_cast_type_from_column(col).precision).must_equal 1
409
+ _(col.fetch_cast_type(connection).precision).must_equal 1
408
410
  obj.datetime2_1 = time
409
411
  _(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
410
- obj.save!; obj.reload
412
+ obj.save!
413
+ obj.reload
411
414
  _(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
412
415
  _(obj).must_equal obj.class.where(datetime2_1: time).first
413
416
  # datetime2_0
414
417
  col = column("datetime2_0")
415
- _(connection.lookup_cast_type_from_column(col).precision).must_equal 0
418
+ _(col.fetch_cast_type(connection).precision).must_equal 0
416
419
  time = Time.utc 2016, 4, 19, 16, 45, 40, 771036
417
420
  obj.datetime2_0 = time
418
421
  _(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
419
- obj.save!; obj.reload
422
+ obj.save!
423
+ obj.reload
420
424
  _(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
421
425
  _(obj).must_equal obj.class.where(datetime2_0: time).first
422
426
  end
423
427
 
424
428
  it "datetimeoffset" do
425
- skip "datetimeoffset not supported in this protocol version" unless connection_tds_73
426
429
  col = column("datetimeoffset_7")
427
- _(col.sql_type).must_equal "datetimeoffset(7)"
428
- _(col.type).must_equal :datetimeoffset
429
- _(col.null).must_equal true
430
- _(col.default).must_equal Time.new(1984, 1, 24, 4, 20, 0, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
431
- _(obj.datetimeoffset_7).must_equal Time.new(1984, 1, 24, 4, 20, 0, -28800).change(nsec: 123456700), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
432
- _(col.default_function).must_be_nil
433
- type = connection.lookup_cast_type_from_column(col)
434
- _(type).must_be_instance_of Type::DateTimeOffset
430
+ _(col.sql_type).must_equal "datetimeoffset(7)"
431
+ _(col.type).must_equal :datetimeoffset
432
+ _(col.null).must_equal true
433
+ _(col.default).must_equal Time.new(1984, 1, 24, 4, 20, 0, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
434
+ _(obj.datetimeoffset_7).must_equal Time.new(1984, 1, 24, 4, 20, 0, -28800).change(nsec: 123456700), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
435
+ _(col.default_function).must_be_nil
436
+ type = col.fetch_cast_type(connection)
437
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::DateTimeOffset
435
438
  _(type.limit).must_be_nil
436
439
  _(type.precision).must_equal 7
437
440
  _(type.scale).must_be_nil
@@ -455,13 +458,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
455
458
  # With other precisions.
456
459
  time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
457
460
  col = column("datetimeoffset_3")
458
- _(connection.lookup_cast_type_from_column(col).precision).must_equal 3
461
+ _(col.fetch_cast_type(connection).precision).must_equal 3
459
462
  obj.datetimeoffset_3 = time
460
463
  _(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
461
464
  obj.save!
462
465
  _(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
463
466
  col = column("datetime2_1")
464
- _(connection.lookup_cast_type_from_column(col).precision).must_equal 1
467
+ _(col.fetch_cast_type(connection).precision).must_equal 1
465
468
  obj.datetime2_1 = time
466
469
  _(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
467
470
  obj.save!
@@ -470,14 +473,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
470
473
 
471
474
  it "smalldatetime" do
472
475
  col = column("smalldatetime")
473
- _(col.sql_type).must_equal "smalldatetime"
474
- _(col.type).must_equal :smalldatetime
475
- _(col.null).must_equal true
476
- _(col.default).must_equal Time.utc(1901, 1, 1, 15, 45, 0, 0)
477
- _(obj.smalldatetime).must_equal Time.utc(1901, 1, 1, 15, 45, 0, 0)
478
- _(col.default_function).must_be_nil
479
- type = connection.lookup_cast_type_from_column(col)
480
- _(type).must_be_instance_of Type::SmallDateTime
476
+ _(col.sql_type).must_equal "smalldatetime"
477
+ _(col.type).must_equal :smalldatetime
478
+ _(col.null).must_equal true
479
+ _(col.default).must_equal Time.utc(1901, 1, 1, 15, 45, 0, 0)
480
+ _(obj.smalldatetime).must_equal Time.utc(1901, 1, 1, 15, 45, 0, 0)
481
+ _(col.default_function).must_be_nil
482
+ type = col.fetch_cast_type(connection)
483
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::SmallDateTime
481
484
  _(type.limit).must_be_nil
482
485
  _(type.precision).must_be_nil
483
486
  _(type.scale).must_be_nil
@@ -491,96 +494,102 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
491
494
  end
492
495
 
493
496
  it "time(7)" do
494
- skip "time() not supported in this protocol version" unless connection_tds_73
495
497
  col = column("time_7")
496
- _(col.sql_type).must_equal "time(7)"
497
- _(col.type).must_equal :time
498
- _(col.null).must_equal true
499
- _(col.default).must_equal Time.utc(1900, 1, 1, 4, 20, 0, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
498
+ _(col.sql_type).must_equal "time(7)"
499
+ _(col.type).must_equal :time
500
+ _(col.null).must_equal true
501
+ _(col.default).must_equal Time.utc(1900, 1, 1, 4, 20, 0, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
500
502
  _(col.default_function).must_be_nil
501
- type = connection.lookup_cast_type_from_column(col)
502
- _(type).must_be_instance_of Type::Time
503
+ type = col.fetch_cast_type(connection)
504
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Time
503
505
  _(type.limit).must_be_nil
504
506
  _(type.precision).must_equal 7
505
507
  _(type.scale).must_be_nil
506
508
  # Time's #usec precision (low micro)
507
509
  obj.time_7 = Time.utc(2000, 1, 1, 15, 45, 0, 300)
508
- _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
509
- _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
510
- obj.save!; obj.reload
511
- _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
512
- _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
510
+ _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
511
+ _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
512
+ obj.save!
513
+ obj.reload
514
+ _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
515
+ _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
513
516
  # Time's #usec precision (high micro)
514
517
  obj.time_7 = Time.utc(2000, 1, 1, 15, 45, 0, 234567)
515
518
  _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
516
- obj.save!; obj.reload
519
+ obj.save!
520
+ obj.reload
517
521
  _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
518
522
  # Time's #usec precision (high nano rounded)
519
523
  obj.time_7 = Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321545, 1000))
520
524
  _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
521
- obj.save!; obj.reload
525
+ obj.save!
526
+ obj.reload
522
527
  _(obj.time_7).must_equal Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
523
528
  end
524
529
 
525
530
  it "time(2)" do
526
- skip "time() not supported in this protocol version" unless connection_tds_73
527
531
  col = column("time_2")
528
- _(col.sql_type).must_equal "time(2)"
529
- _(col.type).must_equal :time
530
- _(col.null).must_equal true
532
+ _(col.sql_type).must_equal "time(2)"
533
+ _(col.type).must_equal :time
534
+ _(col.null).must_equal true
531
535
  _(col.default).must_be_nil
532
536
  _(col.default_function).must_be_nil
533
- type = connection.lookup_cast_type_from_column(col)
534
- _(type).must_be_instance_of Type::Time
537
+ type = col.fetch_cast_type(connection)
538
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Time
535
539
  _(type.limit).must_be_nil
536
540
  _(type.precision).must_equal 2
537
541
  _(type.scale).must_be_nil
538
542
  # Always uses TinyTDS/Windows 2000-01-01 convention too.
539
543
  obj.time_2 = Time.utc(2015, 1, 10, 15, 45, 0, 0)
540
544
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 0)
541
- obj.save!; obj.reload
545
+ obj.save!
546
+ obj.reload
542
547
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 0)
543
548
  # Time's #usec precision (barely in 2 precision equal to 0.03 seconds)
544
549
  obj.time_2 = Time.utc(2000, 1, 1, 15, 45, 0, 30000)
545
550
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
546
- obj.save!; obj.reload
551
+ obj.save!
552
+ obj.reload
547
553
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
548
554
  # Time's #usec precision (below 2 precision)
549
555
  obj.time_2 = Time.utc(2000, 1, 1, 15, 45, 0, 4000)
550
556
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
551
- obj.save!; obj.reload
557
+ obj.save!
558
+ obj.reload
552
559
  _(obj.time_2).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
553
560
  end
554
561
 
555
562
  it "time using default precision" do
556
- skip "time() not supported in this protocol version" unless connection_tds_73
557
563
  col = column("time_default")
558
- _(col.sql_type).must_equal "time(7)"
559
- _(col.type).must_equal :time
560
- _(col.null).must_equal true
561
- _(col.default).must_equal Time.utc(1900, 1, 1, 15, 3, 42, Rational(62197800, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <62197800>"
564
+ _(col.sql_type).must_equal "time(7)"
565
+ _(col.type).must_equal :time
566
+ _(col.null).must_equal true
567
+ _(col.default).must_equal Time.utc(1900, 1, 1, 15, 3, 42, Rational(62197800, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <62197800>"
562
568
  _(col.default_function).must_be_nil
563
- type = connection.lookup_cast_type_from_column(col)
564
- _(type).must_be_instance_of Type::Time
569
+ type = col.fetch_cast_type(connection)
570
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Time
565
571
  _(type.limit).must_be_nil
566
572
  _(type.precision).must_equal 7
567
573
  _(type.scale).must_be_nil
568
574
  # Time's #usec precision (low micro)
569
575
  obj.time_default = Time.utc(2000, 1, 1, 15, 45, 0, 300)
570
- _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
571
- _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
572
- obj.save!; obj.reload
573
- _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
574
- _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
576
+ _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
577
+ _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
578
+ obj.save!
579
+ obj.reload
580
+ _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
581
+ _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
575
582
  # Time's #usec precision (high micro)
576
583
  obj.time_default = Time.utc(2000, 1, 1, 15, 45, 0, 234567)
577
584
  _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 234567), "Microseconds were <#{obj.time_default.usec}> vs <234567>"
578
- obj.save!; obj.reload
585
+ obj.save!
586
+ obj.reload
579
587
  _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, 234567), "Microseconds were <#{obj.time_default.usec}> vs <234567>"
580
588
  # Time's #usec precision (high nano rounded)
581
589
  obj.time_default = Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321545, 1000))
582
590
  _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_default.nsec}> vs <288321500>"
583
- obj.save!; obj.reload
591
+ obj.save!
592
+ obj.reload
584
593
  _(obj.time_default).must_equal Time.utc(2000, 1, 1, 15, 45, 0, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_default.nsec}> vs <288321500>"
585
594
  end
586
595
 
@@ -588,15 +597,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
588
597
 
589
598
  it "char(10)" do
590
599
  col = column("char_10")
591
- _(col.sql_type).must_equal "char(10)"
592
- _(col.type).must_equal :char
593
- _(col.null).must_equal true
594
- _(col.default).must_equal "1234567890"
595
- _(obj.char_10).must_equal "1234567890"
596
- _(col.default_function).must_be_nil
597
- type = connection.lookup_cast_type_from_column(col)
598
- _(type).must_be_instance_of Type::Char
599
- _(type.limit).must_equal 10
600
+ _(col.sql_type).must_equal "char(10)"
601
+ _(col.type).must_equal :char
602
+ _(col.null).must_equal true
603
+ _(col.default).must_equal "1234567890"
604
+ _(obj.char_10).must_equal "1234567890"
605
+ _(col.default_function).must_be_nil
606
+ type = col.fetch_cast_type(connection)
607
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Char
608
+ _(type.limit).must_equal 10
600
609
  _(type.precision).must_be_nil
601
610
  _(type.scale).must_be_nil
602
611
  # Basic set and save.
@@ -608,15 +617,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
608
617
 
609
618
  it "varchar(50)" do
610
619
  col = column("varchar_50")
611
- _(col.sql_type).must_equal "varchar(50)"
612
- _(col.type).must_equal :varchar
613
- _(col.null).must_equal true
614
- _(col.default).must_equal "test varchar_50"
615
- _(obj.varchar_50).must_equal "test varchar_50"
616
- _(col.default_function).must_be_nil
617
- type = connection.lookup_cast_type_from_column(col)
618
- _(type).must_be_instance_of Type::Varchar
619
- _(type.limit).must_equal 50
620
+ _(col.sql_type).must_equal "varchar(50)"
621
+ _(col.type).must_equal :varchar
622
+ _(col.null).must_equal true
623
+ _(col.default).must_equal "test varchar_50"
624
+ _(obj.varchar_50).must_equal "test varchar_50"
625
+ _(col.default_function).must_be_nil
626
+ type = col.fetch_cast_type(connection)
627
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Varchar
628
+ _(type.limit).must_equal 50
620
629
  _(type.precision).must_be_nil
621
630
  _(type.scale).must_be_nil
622
631
  # Basic set and save.
@@ -625,15 +634,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
625
634
 
626
635
  it "varchar(max)" do
627
636
  col = column("varchar_max")
628
- _(col.sql_type).must_equal "varchar(max)"
629
- _(col.type).must_equal :varchar_max
630
- _(col.null).must_equal true
631
- _(col.default).must_equal "test varchar_max"
632
- _(obj.varchar_max).must_equal "test varchar_max"
633
- _(col.default_function).must_be_nil
634
- type = connection.lookup_cast_type_from_column(col)
635
- _(type).must_be_instance_of Type::VarcharMax
636
- _(type.limit).must_equal 2_147_483_647
637
+ _(col.sql_type).must_equal "varchar(max)"
638
+ _(col.type).must_equal :varchar_max
639
+ _(col.null).must_equal true
640
+ _(col.default).must_equal "test varchar_max"
641
+ _(obj.varchar_max).must_equal "test varchar_max"
642
+ _(col.default_function).must_be_nil
643
+ type = col.fetch_cast_type(connection)
644
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::VarcharMax
645
+ _(type.limit).must_equal 2_147_483_647
637
646
  _(type.precision).must_be_nil
638
647
  _(type.scale).must_be_nil
639
648
  # Basic set and save.
@@ -642,15 +651,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
642
651
 
643
652
  it "text" do
644
653
  col = column("text")
645
- _(col.sql_type).must_equal "text"
646
- _(col.type).must_equal :text_basic
647
- _(col.null).must_equal true
648
- _(col.default).must_equal "test text"
649
- _(obj.text).must_equal "test text"
650
- _(col.default_function).must_be_nil
651
- type = connection.lookup_cast_type_from_column(col)
652
- _(type).must_be_instance_of Type::Text
653
- _(type.limit).must_equal 2_147_483_647
654
+ _(col.sql_type).must_equal "text"
655
+ _(col.type).must_equal :text_basic
656
+ _(col.null).must_equal true
657
+ _(col.default).must_equal "test text"
658
+ _(obj.text).must_equal "test text"
659
+ _(col.default_function).must_be_nil
660
+ type = col.fetch_cast_type(connection)
661
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Text
662
+ _(type.limit).must_equal 2_147_483_647
654
663
  _(type.precision).must_be_nil
655
664
  _(type.scale).must_be_nil
656
665
  # Basic set and save.
@@ -661,15 +670,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
661
670
 
662
671
  it "nchar(10)" do
663
672
  col = column("nchar_10")
664
- _(col.sql_type).must_equal "nchar(10)"
665
- _(col.type).must_equal :nchar
666
- _(col.null).must_equal true
667
- _(col.default).must_equal "12345678åå"
668
- _(obj.nchar_10).must_equal "12345678åå"
669
- _(col.default_function).must_be_nil
670
- type = connection.lookup_cast_type_from_column(col)
671
- _(type).must_be_instance_of Type::UnicodeChar
672
- _(type.limit).must_equal 10
673
+ _(col.sql_type).must_equal "nchar(10)"
674
+ _(col.type).must_equal :nchar
675
+ _(col.null).must_equal true
676
+ _(col.default).must_equal "12345678åå"
677
+ _(obj.nchar_10).must_equal "12345678åå"
678
+ _(col.default_function).must_be_nil
679
+ type = col.fetch_cast_type(connection)
680
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::UnicodeChar
681
+ _(type.limit).must_equal 10
673
682
  _(type.precision).must_be_nil
674
683
  _(type.scale).must_be_nil
675
684
  # Basic set and save.
@@ -681,15 +690,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
681
690
 
682
691
  it "nvarchar(50)" do
683
692
  col = column("nvarchar_50")
684
- _(col.sql_type).must_equal "nvarchar(50)"
685
- _(col.type).must_equal :string
686
- _(col.null).must_equal true
687
- _(col.default).must_equal "test nvarchar_50 åå"
688
- _(obj.nvarchar_50).must_equal "test nvarchar_50 åå"
689
- _(col.default_function).must_be_nil
690
- type = connection.lookup_cast_type_from_column(col)
691
- _(type).must_be_instance_of Type::UnicodeVarchar
692
- _(type.limit).must_equal 50
693
+ _(col.sql_type).must_equal "nvarchar(50)"
694
+ _(col.type).must_equal :string
695
+ _(col.null).must_equal true
696
+ _(col.default).must_equal "test nvarchar_50 åå"
697
+ _(obj.nvarchar_50).must_equal "test nvarchar_50 åå"
698
+ _(col.default_function).must_be_nil
699
+ type = col.fetch_cast_type(connection)
700
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::UnicodeVarchar
701
+ _(type.limit).must_equal 50
693
702
  _(type.precision).must_be_nil
694
703
  _(type.scale).must_be_nil
695
704
  # Basic set and save.
@@ -698,15 +707,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
698
707
 
699
708
  it "nvarchar(max)" do
700
709
  col = column("nvarchar_max")
701
- _(col.sql_type).must_equal "nvarchar(max)"
702
- _(col.type).must_equal :text
703
- _(col.null).must_equal true
704
- _(col.default).must_equal "test nvarchar_max åå"
705
- _(obj.nvarchar_max).must_equal "test nvarchar_max åå"
706
- _(col.default_function).must_be_nil
707
- type = connection.lookup_cast_type_from_column(col)
708
- _(type).must_be_instance_of Type::UnicodeVarcharMax
709
- _(type.limit).must_equal 2_147_483_647
710
+ _(col.sql_type).must_equal "nvarchar(max)"
711
+ _(col.type).must_equal :text
712
+ _(col.null).must_equal true
713
+ _(col.default).must_equal "test nvarchar_max åå"
714
+ _(obj.nvarchar_max).must_equal "test nvarchar_max åå"
715
+ _(col.default_function).must_be_nil
716
+ type = col.fetch_cast_type(connection)
717
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::UnicodeVarcharMax
718
+ _(type.limit).must_equal 2_147_483_647
710
719
  _(type.precision).must_be_nil
711
720
  _(type.scale).must_be_nil
712
721
  # Basic set and save.
@@ -715,15 +724,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
715
724
 
716
725
  it "ntext" do
717
726
  col = column("ntext")
718
- _(col.sql_type).must_equal "ntext"
719
- _(col.type).must_equal :ntext
720
- _(col.null).must_equal true
721
- _(col.default).must_equal "test ntext åå"
722
- _(obj.ntext).must_equal "test ntext åå"
723
- _(col.default_function).must_be_nil
724
- type = connection.lookup_cast_type_from_column(col)
725
- _(type).must_be_instance_of Type::UnicodeText
726
- _(type.limit).must_equal 2_147_483_647
727
+ _(col.sql_type).must_equal "ntext"
728
+ _(col.type).must_equal :ntext
729
+ _(col.null).must_equal true
730
+ _(col.default).must_equal "test ntext åå"
731
+ _(obj.ntext).must_equal "test ntext åå"
732
+ _(col.default_function).must_be_nil
733
+ type = col.fetch_cast_type(connection)
734
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::UnicodeText
735
+ _(type.limit).must_equal 2_147_483_647
727
736
  _(type.precision).must_be_nil
728
737
  _(type.scale).must_be_nil
729
738
  # Basic set and save.
@@ -733,18 +742,18 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
733
742
  # Binary Strings
734
743
 
735
744
  let(:binary_file) { File.join ARTest::SQLServer.test_root_sqlserver, "fixtures", "1px.gif" }
736
- let(:binary_data) { File.open(binary_file, "rb") { |f| f.read } }
745
+ let(:binary_data) { File.binread(binary_file) }
737
746
 
738
747
  it "binary(49)" do
739
748
  col = column("binary_49")
740
- _(col.sql_type).must_equal "binary(49)"
741
- _(col.type).must_equal :binary_basic
742
- _(col.null).must_equal true
749
+ _(col.sql_type).must_equal "binary(49)"
750
+ _(col.type).must_equal :binary_basic
751
+ _(col.null).must_equal true
743
752
  _(col.default).must_be_nil
744
753
  _(col.default_function).must_be_nil
745
- type = connection.lookup_cast_type_from_column(col)
746
- _(type).must_be_instance_of Type::Binary
747
- _(type.limit).must_equal 49
754
+ type = col.fetch_cast_type(connection)
755
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Binary
756
+ _(type.limit).must_equal 49
748
757
  _(type.precision).must_be_nil
749
758
  _(type.scale).must_be_nil
750
759
  # Basic set and save.
@@ -758,14 +767,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
758
767
 
759
768
  it "varbinary(49)" do
760
769
  col = column("varbinary_49")
761
- _(col.sql_type).must_equal "varbinary(49)"
762
- _(col.type).must_equal :varbinary
763
- _(col.null).must_equal true
770
+ _(col.sql_type).must_equal "varbinary(49)"
771
+ _(col.type).must_equal :varbinary
772
+ _(col.null).must_equal true
764
773
  _(col.default).must_be_nil
765
774
  _(col.default_function).must_be_nil
766
- type = connection.lookup_cast_type_from_column(col)
767
- _(type).must_be_instance_of Type::Varbinary
768
- _(type.limit).must_equal 49
775
+ type = col.fetch_cast_type(connection)
776
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Varbinary
777
+ _(type.limit).must_equal 49
769
778
  _(type.precision).must_be_nil
770
779
  _(type.scale).must_be_nil
771
780
  # Basic set and save.
@@ -779,14 +788,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
779
788
 
780
789
  it "varbinary(max)" do
781
790
  col = column("varbinary_max")
782
- _(col.sql_type).must_equal "varbinary(max)"
783
- _(col.type).must_equal :binary
784
- _(col.null).must_equal true
791
+ _(col.sql_type).must_equal "varbinary(max)"
792
+ _(col.type).must_equal :binary
793
+ _(col.null).must_equal true
785
794
  _(col.default).must_be_nil
786
795
  _(col.default_function).must_be_nil
787
- type = connection.lookup_cast_type_from_column(col)
788
- _(type).must_be_instance_of Type::VarbinaryMax
789
- _(type.limit).must_equal 2_147_483_647
796
+ type = col.fetch_cast_type(connection)
797
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::VarbinaryMax
798
+ _(type.limit).must_equal 2_147_483_647
790
799
  _(type.precision).must_be_nil
791
800
  _(type.scale).must_be_nil
792
801
  # Basic set and save.
@@ -798,43 +807,46 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
798
807
 
799
808
  it "uniqueidentifier" do
800
809
  col = column("uniqueidentifier")
801
- _(col.sql_type).must_equal "uniqueidentifier"
802
- _(col.type).must_equal :uuid
803
- _(col.null).must_equal true
810
+ _(col.sql_type).must_equal "uniqueidentifier"
811
+ _(col.type).must_equal :uuid
812
+ _(col.null).must_equal true
804
813
  _(col.default).must_be_nil
805
814
  _(col.default_function).must_equal "newid()"
806
- type = connection.lookup_cast_type_from_column(col)
807
- _(type).must_be_instance_of Type::Uuid
815
+ type = col.fetch_cast_type(connection)
816
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Uuid
808
817
  _(type.limit).must_be_nil
809
818
  _(type.precision).must_be_nil
810
819
  _(type.scale).must_be_nil
811
820
  # Basic set and save.
812
821
  obj.uniqueidentifier = "this will not qualify as valid"
813
822
  _(obj.uniqueidentifier).must_be_nil
814
- obj.save!; obj.reload
815
- _(obj.uniqueidentifier).must_match Type::Uuid::ACCEPTABLE_UUID
823
+ obj.save!
824
+ obj.reload
825
+ _(obj.uniqueidentifier).must_match ActiveRecord::ConnectionAdapters::SQLServer::Type::Uuid::ACCEPTABLE_UUID
816
826
  obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
817
827
  _(obj.uniqueidentifier).must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
818
- obj.save!; obj.reload
828
+ obj.save!
829
+ obj.reload
819
830
  _(obj.uniqueidentifier).must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
820
831
  end
821
832
 
822
833
  it "timestamp" do
823
834
  col = column("timestamp")
824
- _(col.sql_type).must_equal "timestamp"
825
- _(col.type).must_equal :ss_timestamp
826
- _(col.null).must_equal true
835
+ _(col.sql_type).must_equal "timestamp"
836
+ _(col.type).must_equal :ss_timestamp
837
+ _(col.null).must_equal true
827
838
  _(col.default).must_be_nil
828
839
  _(col.default_function).must_be_nil
829
- type = connection.lookup_cast_type_from_column(col)
830
- _(type).must_be_instance_of Type::Timestamp
840
+ type = col.fetch_cast_type(connection)
841
+ _(type).must_be_instance_of ActiveRecord::ConnectionAdapters::SQLServer::Type::Timestamp
831
842
  _(type.limit).must_be_nil
832
843
  _(type.precision).must_be_nil
833
844
  _(type.scale).must_be_nil
834
845
  # Basic read.
835
846
  _(obj.timestamp).must_be_nil
836
- obj.save!; obj.reload
837
- _(obj.timestamp).must_match %r|\000|
847
+ obj.save!
848
+ obj.reload
849
+ _(obj.timestamp).must_match %r{\000}
838
850
  obj.timestamp
839
851
  # Can set another attribute
840
852
  obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"