activerecord-jdbcsqlserver-adapter 50.0.0 → 52.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +4 -5
- data/CHANGELOG.md +22 -101
- data/{Dockerfile → Dockerfile.ci} +0 -0
- data/Gemfile +1 -3
- data/README.md +5 -9
- data/VERSION +1 -1
- data/activerecord-jdbcsqlserver-adapter.gemspec +2 -2
- data/appveyor.yml +1 -1
- data/docker-compose.ci.yml +7 -5
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +3 -1
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +3 -1
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +51 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +18 -20
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +5 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +43 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +13 -2
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +94 -28
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb +5 -25
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +24 -1
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +23 -2
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +110 -74
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +15 -7
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +3 -4
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +0 -4
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +5 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +3 -6
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +7 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +47 -24
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +5 -3
- data/lib/activerecord-jdbcsqlserver-adapter.rb +4 -1
- data/lib/arel/visitors/sqlserver.rb +17 -4
- data/lib/arel_sqlserver.rb +0 -1
- data/lib/jdbc_mssql_driver_loader.rb +22 -0
- data/test/bin/install-freetds.sh +18 -0
- data/test/bin/setup.sh +19 -0
- data/test/cases/adapter_test_sqlserver.rb +43 -39
- data/test/cases/change_column_null_test_sqlserver.rb +42 -0
- data/test/cases/coerced_tests.rb +419 -39
- data/test/cases/column_test_sqlserver.rb +496 -462
- data/test/cases/connection_test_sqlserver.rb +2 -2
- data/test/cases/fetch_test_sqlserver.rb +5 -5
- data/test/cases/helper_sqlserver.rb +12 -1
- data/test/cases/json_test_sqlserver.rb +6 -6
- data/test/cases/migration_test_sqlserver.rb +13 -3
- data/test/cases/order_test_sqlserver.rb +19 -19
- data/test/cases/pessimistic_locking_test_sqlserver.rb +37 -20
- data/test/cases/rake_test_sqlserver.rb +20 -20
- data/test/cases/schema_dumper_test_sqlserver.rb +44 -43
- data/test/cases/schema_test_sqlserver.rb +2 -2
- data/test/cases/showplan_test_sqlserver.rb +25 -10
- data/test/cases/specific_schema_test_sqlserver.rb +11 -17
- data/test/cases/transaction_test_sqlserver.rb +9 -9
- data/test/cases/trigger_test_sqlserver.rb +31 -0
- data/test/cases/utils_test_sqlserver.rb +36 -36
- data/test/cases/uuid_test_sqlserver.rb +8 -8
- data/test/config.yml +2 -2
- data/test/migrations/create_clients_and_change_column_null.rb +23 -0
- data/test/models/sqlserver/trigger.rb +7 -0
- data/test/models/sqlserver/trigger_history.rb +3 -0
- data/test/schema/datatypes/2012.sql +1 -0
- data/test/schema/sqlserver_specific_schema.rb +47 -5
- data/test/support/core_ext/query_cache.rb +29 -0
- data/test/support/sql_counter_sqlserver.rb +1 -1
- metadata +32 -15
- data/RAILS5-TODO.md +0 -5
- data/test/models/sqlserver/dot_table_name.rb +0 -3
@@ -18,9 +18,9 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
18
18
|
def column(name) ; SSTestDatatype.columns_hash[name] ; end
|
19
19
|
def assert_obj_set_and_save(attribute, value)
|
20
20
|
obj.send :"#{attribute}=", value
|
21
|
-
obj.send(attribute).must_equal value
|
21
|
+
_(obj.send(attribute)).must_equal value
|
22
22
|
obj.save!
|
23
|
-
obj.reload.send(attribute).must_equal value
|
23
|
+
_(obj.reload.send(attribute)).must_equal value
|
24
24
|
end
|
25
25
|
|
26
26
|
# http://msdn.microsoft.com/en-us/library/ms187752.aspx
|
@@ -29,199 +29,199 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
29
29
|
|
30
30
|
it 'int(4) PRIMARY KEY' do
|
31
31
|
col = column('id')
|
32
|
-
col.sql_type.must_equal 'int(4)'
|
33
|
-
col.null.must_equal false
|
32
|
+
_(col.sql_type).must_equal 'int(4)'
|
33
|
+
_(col.null).must_equal false
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'bigint(8)' do
|
37
37
|
col = column('bigint')
|
38
|
-
col.sql_type.must_equal 'bigint(8)'
|
39
|
-
col.type.must_equal :
|
40
|
-
col.null.must_equal true
|
41
|
-
col.default.must_equal 42
|
42
|
-
obj.bigint.must_equal 42
|
43
|
-
col.default_function.must_be_nil
|
44
|
-
type = connection.lookup_cast_type_from_column(col)
|
45
|
-
type.must_be_instance_of Type::BigInteger
|
46
|
-
type.limit.must_equal 8
|
38
|
+
_(col.sql_type).must_equal 'bigint(8)'
|
39
|
+
_(col.type).must_equal :integer
|
40
|
+
_(col.null).must_equal true
|
41
|
+
_(col.default).must_equal 42
|
42
|
+
_(obj.bigint).must_equal 42
|
43
|
+
_(col.default_function).must_be_nil
|
44
|
+
type = connection.lookup_cast_type_from_column(col)
|
45
|
+
_(type).must_be_instance_of Type::BigInteger
|
46
|
+
_(type.limit).must_equal 8
|
47
47
|
assert_obj_set_and_save :bigint, -9_223_372_036_854_775_808
|
48
48
|
assert_obj_set_and_save :bigint, 9_223_372_036_854_775_807
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'int(4)' do
|
52
52
|
col = column('int')
|
53
|
-
col.sql_type.must_equal 'int(4)'
|
54
|
-
col.type.must_equal :integer
|
55
|
-
col.null.must_equal true
|
56
|
-
col.default.must_equal 42
|
57
|
-
obj.int.must_equal 42
|
58
|
-
col.default_function.must_be_nil
|
59
|
-
type = connection.lookup_cast_type_from_column(col)
|
60
|
-
type.must_be_instance_of Type::Integer
|
61
|
-
type.limit.must_equal 4
|
53
|
+
_(col.sql_type).must_equal 'int(4)'
|
54
|
+
_(col.type).must_equal :integer
|
55
|
+
_(col.null).must_equal true
|
56
|
+
_(col.default).must_equal 42
|
57
|
+
_(obj.int).must_equal 42
|
58
|
+
_(col.default_function).must_be_nil
|
59
|
+
type = connection.lookup_cast_type_from_column(col)
|
60
|
+
_(type).must_be_instance_of Type::Integer
|
61
|
+
_(type.limit).must_equal 4
|
62
62
|
assert_obj_set_and_save :int, -2_147_483_648
|
63
63
|
assert_obj_set_and_save :int, 2_147_483_647
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'smallint(2)' do
|
67
67
|
col = column('smallint')
|
68
|
-
col.sql_type.must_equal 'smallint(2)'
|
69
|
-
col.type.must_equal :integer
|
70
|
-
col.null.must_equal true
|
71
|
-
col.default.must_equal 42
|
72
|
-
obj.smallint.must_equal 42
|
73
|
-
col.default_function.must_be_nil
|
74
|
-
type = connection.lookup_cast_type_from_column(col)
|
75
|
-
type.must_be_instance_of Type::SmallInteger
|
76
|
-
type.limit.must_equal 2
|
68
|
+
_(col.sql_type).must_equal 'smallint(2)'
|
69
|
+
_(col.type).must_equal :integer
|
70
|
+
_(col.null).must_equal true
|
71
|
+
_(col.default).must_equal 42
|
72
|
+
_(obj.smallint).must_equal 42
|
73
|
+
_(col.default_function).must_be_nil
|
74
|
+
type = connection.lookup_cast_type_from_column(col)
|
75
|
+
_(type).must_be_instance_of Type::SmallInteger
|
76
|
+
_(type.limit).must_equal 2
|
77
77
|
assert_obj_set_and_save :smallint, -32_768
|
78
78
|
assert_obj_set_and_save :smallint, 32_767
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'tinyint(1)' do
|
82
82
|
col = column('tinyint')
|
83
|
-
col.sql_type.must_equal 'tinyint(1)'
|
84
|
-
col.type.must_equal :integer
|
85
|
-
col.null.must_equal true
|
86
|
-
col.default.must_equal 42
|
87
|
-
obj.tinyint.must_equal 42
|
88
|
-
col.default_function.must_be_nil
|
89
|
-
type = connection.lookup_cast_type_from_column(col)
|
90
|
-
type.must_be_instance_of Type::TinyInteger
|
91
|
-
type.limit.must_equal 1
|
83
|
+
_(col.sql_type).must_equal 'tinyint(1)'
|
84
|
+
_(col.type).must_equal :integer
|
85
|
+
_(col.null).must_equal true
|
86
|
+
_(col.default).must_equal 42
|
87
|
+
_(obj.tinyint).must_equal 42
|
88
|
+
_(col.default_function).must_be_nil
|
89
|
+
type = connection.lookup_cast_type_from_column(col)
|
90
|
+
_(type).must_be_instance_of Type::TinyInteger
|
91
|
+
_(type.limit).must_equal 1
|
92
92
|
assert_obj_set_and_save :tinyint, 0
|
93
93
|
assert_obj_set_and_save :tinyint, 255
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'bit' do
|
97
97
|
col = column('bit')
|
98
|
-
col.sql_type.must_equal 'bit'
|
99
|
-
col.type.must_equal :boolean
|
100
|
-
col.null.must_equal true
|
101
|
-
col.default.must_equal true
|
102
|
-
obj.bit.must_equal true
|
103
|
-
col.default_function.must_be_nil
|
104
|
-
type = connection.lookup_cast_type_from_column(col)
|
105
|
-
type.must_be_instance_of Type::Boolean
|
106
|
-
type.limit.must_be_nil
|
98
|
+
_(col.sql_type).must_equal 'bit'
|
99
|
+
_(col.type).must_equal :boolean
|
100
|
+
_(col.null).must_equal true
|
101
|
+
_(col.default).must_equal true
|
102
|
+
_(obj.bit).must_equal true
|
103
|
+
_(col.default_function).must_be_nil
|
104
|
+
type = connection.lookup_cast_type_from_column(col)
|
105
|
+
_(type).must_be_instance_of Type::Boolean
|
106
|
+
_(type.limit).must_be_nil
|
107
107
|
obj.bit = 0
|
108
|
-
obj.bit.must_equal false
|
108
|
+
_(obj.bit).must_equal false
|
109
109
|
obj.save!
|
110
|
-
obj.reload.bit.must_equal false
|
110
|
+
_(obj.reload.bit).must_equal false
|
111
111
|
obj.bit = '1'
|
112
|
-
obj.bit.must_equal true
|
112
|
+
_(obj.bit).must_equal true
|
113
113
|
obj.save!
|
114
|
-
obj.reload.bit.must_equal true
|
114
|
+
_(obj.reload.bit).must_equal true
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'decimal(9,2)' do
|
118
118
|
col = column('decimal_9_2')
|
119
|
-
col.sql_type.must_equal 'decimal(9,2)'
|
120
|
-
col.type.must_equal :decimal
|
121
|
-
col.null.must_equal true
|
122
|
-
col.default.must_equal BigDecimal('12345.01')
|
123
|
-
obj.decimal_9_2.must_equal BigDecimal('12345.01')
|
124
|
-
col.default_function.must_be_nil
|
125
|
-
type = connection.lookup_cast_type_from_column(col)
|
126
|
-
type.must_be_instance_of Type::Decimal
|
127
|
-
type.limit.must_be_nil
|
128
|
-
type.precision.must_equal 9
|
129
|
-
type.scale.must_equal 2
|
119
|
+
_(col.sql_type).must_equal 'decimal(9,2)'
|
120
|
+
_(col.type).must_equal :decimal
|
121
|
+
_(col.null).must_equal true
|
122
|
+
_(col.default).must_equal BigDecimal('12345.01')
|
123
|
+
_(obj.decimal_9_2).must_equal BigDecimal('12345.01')
|
124
|
+
_(col.default_function).must_be_nil
|
125
|
+
type = connection.lookup_cast_type_from_column(col)
|
126
|
+
_(type).must_be_instance_of Type::Decimal
|
127
|
+
_(type.limit).must_be_nil
|
128
|
+
_(type.precision).must_equal 9
|
129
|
+
_(type.scale).must_equal 2
|
130
130
|
obj.decimal_9_2 = '1234567.8901'
|
131
|
-
obj.decimal_9_2.must_equal BigDecimal('1234567.89')
|
131
|
+
_(obj.decimal_9_2).must_equal BigDecimal('1234567.89')
|
132
132
|
obj.save!
|
133
|
-
obj.reload.decimal_9_2.must_equal BigDecimal('1234567.89')
|
133
|
+
_(obj.reload.decimal_9_2).must_equal BigDecimal('1234567.89')
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'decimal(16,4)' do
|
137
137
|
col = column('decimal_16_4')
|
138
|
-
col.sql_type.must_equal 'decimal(16,4)'
|
139
|
-
col.default.must_equal BigDecimal('1234567.89')
|
140
|
-
obj.decimal_16_4.must_equal BigDecimal('1234567.89')
|
141
|
-
col.default_function.must_be_nil
|
138
|
+
_(col.sql_type).must_equal 'decimal(16,4)'
|
139
|
+
_(col.default).must_equal BigDecimal('1234567.89')
|
140
|
+
_(obj.decimal_16_4).must_equal BigDecimal('1234567.89')
|
141
|
+
_(col.default_function).must_be_nil
|
142
142
|
type = connection.lookup_cast_type_from_column(col)
|
143
|
-
type.precision.must_equal 16
|
144
|
-
type.scale.must_equal 4
|
143
|
+
_(type.precision).must_equal 16
|
144
|
+
_(type.scale).must_equal 4
|
145
145
|
obj.decimal_16_4 = '1234567.8901001'
|
146
|
-
obj.decimal_16_4.must_equal BigDecimal('1234567.8901')
|
146
|
+
_(obj.decimal_16_4).must_equal BigDecimal('1234567.8901')
|
147
147
|
obj.save!
|
148
|
-
obj.reload.decimal_16_4.must_equal BigDecimal('1234567.8901')
|
148
|
+
_(obj.reload.decimal_16_4).must_equal BigDecimal('1234567.8901')
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'numeric(18,0)' do
|
152
152
|
col = column('numeric_18_0')
|
153
|
-
col.sql_type.must_equal 'numeric(18,0)'
|
154
|
-
col.type.must_equal :decimal
|
155
|
-
col.null.must_equal true
|
156
|
-
col.default.must_equal BigDecimal('191')
|
157
|
-
obj.numeric_18_0.must_equal BigDecimal('191')
|
158
|
-
col.default_function.must_be_nil
|
159
|
-
type = connection.lookup_cast_type_from_column(col)
|
160
|
-
type.must_be_instance_of Type::Decimal
|
161
|
-
type.limit.must_be_nil
|
162
|
-
type.precision.must_equal 18
|
163
|
-
type.scale.must_equal 0
|
153
|
+
_(col.sql_type).must_equal 'numeric(18,0)'
|
154
|
+
_(col.type).must_equal :decimal
|
155
|
+
_(col.null).must_equal true
|
156
|
+
_(col.default).must_equal BigDecimal('191')
|
157
|
+
_(obj.numeric_18_0).must_equal BigDecimal('191')
|
158
|
+
_(col.default_function).must_be_nil
|
159
|
+
type = connection.lookup_cast_type_from_column(col)
|
160
|
+
_(type).must_be_instance_of Type::Decimal
|
161
|
+
_(type.limit).must_be_nil
|
162
|
+
_(type.precision).must_equal 18
|
163
|
+
_(type.scale).must_equal 0
|
164
164
|
obj.numeric_18_0 = '192.1'
|
165
|
-
obj.numeric_18_0.must_equal BigDecimal('192')
|
165
|
+
_(obj.numeric_18_0).must_equal BigDecimal('192')
|
166
166
|
obj.save!
|
167
|
-
obj.reload.numeric_18_0.must_equal BigDecimal('192')
|
167
|
+
_(obj.reload.numeric_18_0).must_equal BigDecimal('192')
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'numeric(36,2)' do
|
171
171
|
col = column('numeric_36_2')
|
172
|
-
col.sql_type.must_equal 'numeric(36,2)'
|
173
|
-
col.type.must_equal :decimal
|
174
|
-
col.null.must_equal true
|
175
|
-
col.default.must_equal BigDecimal('12345678901234567890.01')
|
176
|
-
obj.numeric_36_2.must_equal BigDecimal('12345678901234567890.01')
|
177
|
-
col.default_function.must_be_nil
|
178
|
-
type = connection.lookup_cast_type_from_column(col)
|
179
|
-
type.must_be_instance_of Type::Decimal
|
180
|
-
type.limit.must_be_nil
|
181
|
-
type.precision.must_equal 36
|
182
|
-
type.scale.must_equal 2
|
172
|
+
_(col.sql_type).must_equal 'numeric(36,2)'
|
173
|
+
_(col.type).must_equal :decimal
|
174
|
+
_(col.null).must_equal true
|
175
|
+
_(col.default).must_equal BigDecimal('12345678901234567890.01')
|
176
|
+
_(obj.numeric_36_2).must_equal BigDecimal('12345678901234567890.01')
|
177
|
+
_(col.default_function).must_be_nil
|
178
|
+
type = connection.lookup_cast_type_from_column(col)
|
179
|
+
_(type).must_be_instance_of Type::Decimal
|
180
|
+
_(type.limit).must_be_nil
|
181
|
+
_(type.precision).must_equal 36
|
182
|
+
_(type.scale).must_equal 2
|
183
183
|
obj.numeric_36_2 = '192.123'
|
184
|
-
obj.numeric_36_2.must_equal BigDecimal('192.12')
|
184
|
+
_(obj.numeric_36_2).must_equal BigDecimal('192.12')
|
185
185
|
obj.save!
|
186
|
-
obj.reload.numeric_36_2.must_equal BigDecimal('192.12')
|
186
|
+
_(obj.reload.numeric_36_2).must_equal BigDecimal('192.12')
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'money' do
|
190
190
|
col = column('money')
|
191
|
-
col.sql_type.must_equal 'money'
|
192
|
-
col.type.must_equal :money
|
193
|
-
col.null.must_equal true
|
194
|
-
col.default.must_equal BigDecimal('4.20')
|
195
|
-
obj.money.must_equal BigDecimal('4.20')
|
196
|
-
col.default_function.must_be_nil
|
197
|
-
type = connection.lookup_cast_type_from_column(col)
|
198
|
-
type.must_be_instance_of Type::Money
|
199
|
-
type.limit.must_be_nil
|
200
|
-
type.precision.must_equal 19
|
201
|
-
type.scale.must_equal 4
|
191
|
+
_(col.sql_type).must_equal 'money'
|
192
|
+
_(col.type).must_equal :money
|
193
|
+
_(col.null).must_equal true
|
194
|
+
_(col.default).must_equal BigDecimal('4.20')
|
195
|
+
_(obj.money).must_equal BigDecimal('4.20')
|
196
|
+
_(col.default_function).must_be_nil
|
197
|
+
type = connection.lookup_cast_type_from_column(col)
|
198
|
+
_(type).must_be_instance_of Type::Money
|
199
|
+
_(type.limit).must_be_nil
|
200
|
+
_(type.precision).must_equal 19
|
201
|
+
_(type.scale).must_equal 4
|
202
202
|
obj.money = '922337203685477.58061'
|
203
|
-
obj.money.must_equal BigDecimal('922337203685477.5806')
|
203
|
+
_(obj.money).must_equal BigDecimal('922337203685477.5806')
|
204
204
|
obj.save!
|
205
|
-
obj.reload.money.must_equal BigDecimal('922337203685477.5806')
|
205
|
+
_(obj.reload.money).must_equal BigDecimal('922337203685477.5806')
|
206
206
|
end
|
207
207
|
|
208
208
|
it 'smallmoney' do
|
209
209
|
col = column('smallmoney')
|
210
|
-
col.sql_type.must_equal 'smallmoney'
|
211
|
-
col.type.must_equal :smallmoney
|
212
|
-
col.null.must_equal true
|
213
|
-
col.default.must_equal BigDecimal('4.20')
|
214
|
-
obj.smallmoney.must_equal BigDecimal('4.20')
|
215
|
-
col.default_function.must_be_nil
|
216
|
-
type = connection.lookup_cast_type_from_column(col)
|
217
|
-
type.must_be_instance_of Type::SmallMoney
|
218
|
-
type.limit.must_be_nil
|
219
|
-
type.precision.must_equal 10
|
220
|
-
type.scale.must_equal 4
|
210
|
+
_(col.sql_type).must_equal 'smallmoney'
|
211
|
+
_(col.type).must_equal :smallmoney
|
212
|
+
_(col.null).must_equal true
|
213
|
+
_(col.default).must_equal BigDecimal('4.20')
|
214
|
+
_(obj.smallmoney).must_equal BigDecimal('4.20')
|
215
|
+
_(col.default_function).must_be_nil
|
216
|
+
type = connection.lookup_cast_type_from_column(col)
|
217
|
+
_(type).must_be_instance_of Type::SmallMoney
|
218
|
+
_(type.limit).must_be_nil
|
219
|
+
_(type.precision).must_equal 10
|
220
|
+
_(type.scale).must_equal 4
|
221
221
|
obj.smallmoney = '214748.36461'
|
222
|
-
obj.smallmoney.must_equal BigDecimal('214748.3646')
|
222
|
+
_(obj.smallmoney).must_equal BigDecimal('214748.3646')
|
223
223
|
obj.save!
|
224
|
-
obj.reload.smallmoney.must_equal BigDecimal('214748.3646')
|
224
|
+
_(obj.reload.smallmoney).must_equal BigDecimal('214748.3646')
|
225
225
|
end
|
226
226
|
|
227
227
|
# Approximate Numerics
|
@@ -230,395 +230,423 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
230
230
|
|
231
231
|
it 'float' do
|
232
232
|
col = column('float')
|
233
|
-
col.sql_type.must_equal 'float'
|
234
|
-
col.type.must_equal :float
|
235
|
-
col.null.must_equal true
|
236
|
-
col.default.must_equal 123.00000001
|
237
|
-
obj.float.must_equal 123.00000001
|
238
|
-
col.default_function.must_be_nil
|
239
|
-
type = connection.lookup_cast_type_from_column(col)
|
240
|
-
type.must_be_instance_of Type::Float
|
241
|
-
type.limit.must_be_nil
|
242
|
-
type.precision.must_be_nil
|
243
|
-
type.scale.must_be_nil
|
233
|
+
_(col.sql_type).must_equal 'float'
|
234
|
+
_(col.type).must_equal :float
|
235
|
+
_(col.null).must_equal true
|
236
|
+
_(col.default).must_equal 123.00000001
|
237
|
+
_(obj.float).must_equal 123.00000001
|
238
|
+
_(col.default_function).must_be_nil
|
239
|
+
type = connection.lookup_cast_type_from_column(col)
|
240
|
+
_(type).must_be_instance_of Type::Float
|
241
|
+
_(type.limit).must_be_nil
|
242
|
+
_(type.precision).must_be_nil
|
243
|
+
_(type.scale).must_be_nil
|
244
244
|
obj.float = '214748.36461'
|
245
|
-
obj.float.must_equal 214748.36461
|
245
|
+
_(obj.float).must_equal 214748.36461
|
246
246
|
obj.save!
|
247
|
-
obj.reload.float.must_equal 214748.36461
|
247
|
+
_(obj.reload.float).must_equal 214748.36461
|
248
248
|
end
|
249
249
|
|
250
250
|
it 'real' do
|
251
251
|
col = column('real')
|
252
|
-
col.sql_type.must_equal 'real'
|
253
|
-
col.type.must_equal :real
|
254
|
-
col.null.must_equal true
|
255
|
-
col.default.must_be_close_to 123.45, 0.01
|
256
|
-
obj.real.must_be_close_to 123.45, 0.01
|
257
|
-
col.default_function.must_be_nil
|
258
|
-
type = connection.lookup_cast_type_from_column(col)
|
259
|
-
type.must_be_instance_of Type::Real
|
260
|
-
type.limit.must_be_nil
|
261
|
-
type.precision.must_be_nil
|
262
|
-
type.scale.must_be_nil
|
252
|
+
_(col.sql_type).must_equal 'real'
|
253
|
+
_(col.type).must_equal :real
|
254
|
+
_(col.null).must_equal true
|
255
|
+
_(col.default).must_be_close_to 123.45, 0.01
|
256
|
+
_(obj.real).must_be_close_to 123.45, 0.01
|
257
|
+
_(col.default_function).must_be_nil
|
258
|
+
type = connection.lookup_cast_type_from_column(col)
|
259
|
+
_(type).must_be_instance_of Type::Real
|
260
|
+
_(type.limit).must_be_nil
|
261
|
+
_(type.precision).must_be_nil
|
262
|
+
_(type.scale).must_be_nil
|
263
263
|
obj.real = '214748.36461'
|
264
|
-
obj.real.must_be_close_to 214748.36461, 0.01
|
264
|
+
_(obj.real).must_be_close_to 214748.36461, 0.01
|
265
265
|
obj.save!
|
266
|
-
obj.reload.real.must_be_close_to 214748.36461, 0.01
|
266
|
+
_(obj.reload.real).must_be_close_to 214748.36461, 0.01
|
267
267
|
end
|
268
268
|
|
269
269
|
# Date and Time
|
270
270
|
|
271
271
|
it 'date' do
|
272
272
|
col = column('date')
|
273
|
-
col.sql_type.must_equal 'date'
|
274
|
-
col.type.must_equal :date
|
275
|
-
col.null.must_equal true
|
276
|
-
col.default.must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) : '0001-01-01'
|
277
|
-
obj.date.must_equal Date.civil(0001, 1, 1)
|
278
|
-
col.default_function.must_be_nil
|
279
|
-
type = connection.lookup_cast_type_from_column(col)
|
280
|
-
type.must_be_instance_of Type::Date
|
281
|
-
type.limit.must_be_nil
|
282
|
-
type.precision.must_be_nil
|
283
|
-
type.scale.must_be_nil
|
273
|
+
_(col.sql_type).must_equal 'date'
|
274
|
+
_(col.type).must_equal :date
|
275
|
+
_(col.null).must_equal true
|
276
|
+
_(col.default).must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) : '0001-01-01'
|
277
|
+
_(obj.date).must_equal Date.civil(0001, 1, 1)
|
278
|
+
_(col.default_function).must_be_nil
|
279
|
+
type = connection.lookup_cast_type_from_column(col)
|
280
|
+
_(type).must_be_instance_of Type::Date
|
281
|
+
_(type.limit).must_be_nil
|
282
|
+
_(type.precision).must_be_nil
|
283
|
+
_(type.scale).must_be_nil
|
284
284
|
# Can cast strings. SQL Server format.
|
285
285
|
obj.date = '04-01-0001'
|
286
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
286
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
287
287
|
obj.save!
|
288
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
288
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
289
289
|
obj.reload
|
290
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
290
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
291
291
|
# Can cast strings. ISO format.
|
292
292
|
obj.date = '0001-04-01'
|
293
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
293
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
294
294
|
obj.save!
|
295
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
295
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
296
296
|
obj.reload
|
297
|
-
obj.date.must_equal Date.civil(0001, 4, 1)
|
297
|
+
_(obj.date).must_equal Date.civil(0001, 4, 1)
|
298
298
|
# Can keep and return assigned date.
|
299
299
|
assert_obj_set_and_save :date, Date.civil(1972, 04, 14)
|
300
300
|
# Can accept and cast time objects.
|
301
301
|
obj.date = Time.utc(2010, 4, 14, 12, 34, 56, 3000)
|
302
|
-
obj.date.must_equal Date.civil(2010, 4, 14)
|
302
|
+
_(obj.date).must_equal Date.civil(2010, 4, 14)
|
303
303
|
obj.save!
|
304
|
-
obj.reload.date.must_equal Date.civil(2010, 4, 14)
|
304
|
+
_(obj.reload.date).must_equal Date.civil(2010, 4, 14)
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'datetime' do
|
308
308
|
col = column('datetime')
|
309
|
-
col.sql_type.must_equal 'datetime'
|
310
|
-
col.type.must_equal :datetime
|
311
|
-
col.null.must_equal true
|
309
|
+
_(col.sql_type).must_equal 'datetime'
|
310
|
+
_(col.type).must_equal :datetime
|
311
|
+
_(col.null).must_equal true
|
312
312
|
time = Time.utc 1753, 01, 01, 00, 00, 00, 123000
|
313
|
-
col.default.must_equal time, "Microseconds were <#{col.default.usec}> vs <123000>"
|
314
|
-
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
|
315
|
-
col.default_function.must_be_nil
|
313
|
+
_(col.default).must_equal time, "Microseconds were <#{col.default.usec}> vs <123000>"
|
314
|
+
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
|
315
|
+
_(col.default_function).must_be_nil
|
316
316
|
type = connection.lookup_cast_type_from_column(col)
|
317
|
-
type.must_be_instance_of Type::DateTime
|
318
|
-
type.limit.must_be_nil
|
319
|
-
type.precision.must_be_nil
|
320
|
-
type.scale.must_be_nil
|
317
|
+
_(type).must_be_instance_of Type::DateTime
|
318
|
+
_(type.limit).must_be_nil
|
319
|
+
_(type.precision).must_be_nil
|
320
|
+
_(type.scale).must_be_nil
|
321
321
|
obj.save!
|
322
|
-
#obj.must_equal obj.class.where(datetime: time).first <-------------------------------------------- All versions of this break, maybe an issue with prepared statements setting it correctly?
|
322
|
+
#_(obj).must_equal obj.class.where(datetime: time).first <-------------------------------------------- All versions of this break, maybe an issue with prepared statements setting it correctly?
|
323
323
|
# Can save to proper accuracy and return again.
|
324
324
|
time = Time.utc 2010, 04, 01, 12, 34, 56, 3000
|
325
325
|
obj.datetime = time
|
326
|
-
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
326
|
+
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
327
327
|
obj.save!
|
328
|
-
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
328
|
+
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
329
329
|
obj.reload
|
330
|
-
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
331
|
-
#obj.must_equal obj.class.where(datetime: time).first
|
330
|
+
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
331
|
+
#_(obj).must_equal obj.class.where(datetime: time).first
|
332
332
|
# Will cast to true DB value on attribute write, save and return again.
|
333
333
|
time = Time.utc 2010, 04, 01, 12, 34, 56, 234567
|
334
334
|
time2 = Time.utc 2010, 04, 01, 12, 34, 56, 233000
|
335
335
|
obj.datetime = time
|
336
|
-
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
336
|
+
_(obj.datetime).must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
337
337
|
obj.save!
|
338
|
-
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
338
|
+
_(obj.datetime).must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
339
339
|
obj.reload
|
340
|
-
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
341
|
-
#obj.must_equal obj.class.where(datetime: time).first
|
342
|
-
#obj.must_equal obj.class.where(datetime: time2).first
|
340
|
+
_(obj.datetime).must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
341
|
+
#_(obj).must_equal obj.class.where(datetime: time).first
|
342
|
+
#_(obj).must_equal obj.class.where(datetime: time2).first
|
343
343
|
# Set and find nil.
|
344
344
|
obj.datetime = nil
|
345
|
-
obj.datetime.must_be_nil
|
345
|
+
_(obj.datetime).must_be_nil
|
346
346
|
obj.save!
|
347
|
-
obj.datetime.must_be_nil
|
348
|
-
#obj.must_equal obj.class.where(datetime: nil).first
|
347
|
+
_(obj.datetime).must_be_nil
|
348
|
+
#_(obj).must_equal obj.class.where(datetime: nil).first
|
349
349
|
end
|
350
350
|
|
351
351
|
it 'datetime2' do
|
352
|
-
skip 'datetime2 not supported in this
|
352
|
+
skip 'datetime2 not supported in this protocol version' unless connection_dblib_73?
|
353
353
|
col = column('datetime2_7')
|
354
|
-
col.sql_type.must_equal 'datetime2(7)'
|
355
|
-
col.type.must_equal :datetime
|
356
|
-
col.null.must_equal true
|
354
|
+
_(col.sql_type).must_equal 'datetime2(7)'
|
355
|
+
_(col.type).must_equal :datetime
|
356
|
+
_(col.null).must_equal true
|
357
357
|
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(999999900, 1000)
|
358
|
-
col.default.must_equal time, "Nanoseconds were <#{col.default.nsec}> vs <999999900>"
|
359
|
-
obj.datetime2_7.must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
|
360
|
-
col.default_function.must_be_nil
|
358
|
+
_(col.default).must_equal time, "Nanoseconds were <#{col.default.nsec}> vs <999999900>"
|
359
|
+
_(obj.datetime2_7).must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
|
360
|
+
_(col.default_function).must_be_nil
|
361
361
|
type = connection.lookup_cast_type_from_column(col)
|
362
|
-
type.must_be_instance_of Type::DateTime2
|
363
|
-
type.limit.must_be_nil
|
364
|
-
type.precision.must_equal 7
|
365
|
-
type.scale.must_be_nil
|
362
|
+
_(type).must_be_instance_of Type::DateTime2
|
363
|
+
_(type.limit).must_be_nil
|
364
|
+
_(type.precision).must_equal 7
|
365
|
+
_(type.scale).must_be_nil
|
366
366
|
obj.save!
|
367
|
-
obj.must_equal obj.class.where(datetime2_7: time).first
|
367
|
+
_(obj).must_equal obj.class.where(datetime2_7: time).first
|
368
368
|
# Can save 100 nanosecond precisoins and return again.
|
369
369
|
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
370
370
|
time2 = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456700, 1000) # This test is actually wrong because rails specifies that it should truncate and this test tests that it rounds
|
371
371
|
obj.datetime2_7 = time
|
372
|
-
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
372
|
+
_(obj.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
373
373
|
obj.save!
|
374
|
-
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
374
|
+
_(obj.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
375
375
|
obj.reload
|
376
|
-
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
377
|
-
obj.must_equal obj.class.where(datetime2_7: time).first
|
378
|
-
obj.must_equal obj.class.where(datetime2_7: time2).first
|
376
|
+
_(obj.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456700>"
|
377
|
+
_(obj).must_equal obj.class.where(datetime2_7: time).first
|
378
|
+
_(obj).must_equal obj.class.where(datetime2_7: time2).first
|
379
379
|
# Can save small fraction nanosecond precisoins and return again.
|
380
380
|
time = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15020, 1000)
|
381
381
|
time2 = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15000, 1000)
|
382
382
|
obj.datetime2_7 = time
|
383
|
-
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
383
|
+
_(obj.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
384
384
|
obj.save!
|
385
|
-
obj.reload.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
386
|
-
obj.must_equal obj.class.where(datetime2_7: time).first
|
387
|
-
obj.must_equal obj.class.where(datetime2_7: time2).first
|
385
|
+
_(obj.reload.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
386
|
+
_(obj).must_equal obj.class.where(datetime2_7: time).first
|
387
|
+
_(obj).must_equal obj.class.where(datetime2_7: time2).first
|
388
388
|
# datetime2_3
|
389
389
|
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456789, 1000)
|
390
390
|
col = column('datetime2_3')
|
391
|
-
connection.lookup_cast_type_from_column(col).precision.must_equal 3
|
391
|
+
_(connection.lookup_cast_type_from_column(col).precision).must_equal 3
|
392
392
|
obj.datetime2_3 = time
|
393
|
-
obj.datetime2_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
393
|
+
_(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
394
394
|
obj.save! ; obj.reload
|
395
|
-
obj.datetime2_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
396
|
-
obj.must_equal obj.class.where(datetime2_3: time).first
|
395
|
+
_(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
396
|
+
_(obj).must_equal obj.class.where(datetime2_3: time).first
|
397
397
|
# datetime2_1
|
398
398
|
col = column('datetime2_1')
|
399
|
-
connection.lookup_cast_type_from_column(col).precision.must_equal 1
|
399
|
+
_(connection.lookup_cast_type_from_column(col).precision).must_equal 1
|
400
400
|
obj.datetime2_1 = time
|
401
|
-
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
401
|
+
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
402
402
|
obj.save! ; obj.reload
|
403
|
-
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
404
|
-
obj.must_equal obj.class.where(datetime2_1: time).first
|
403
|
+
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
404
|
+
_(obj).must_equal obj.class.where(datetime2_1: time).first
|
405
405
|
# datetime2_0
|
406
406
|
col = column('datetime2_0')
|
407
|
-
connection.lookup_cast_type_from_column(col).precision.must_equal 0
|
407
|
+
_(connection.lookup_cast_type_from_column(col).precision).must_equal 0
|
408
408
|
time = Time.utc 2016, 4, 19, 16, 45, 40, 771036
|
409
409
|
obj.datetime2_0 = time
|
410
|
-
obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
410
|
+
_(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
411
411
|
obj.save! ; obj.reload
|
412
|
-
obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
413
|
-
obj.must_equal obj.class.where(datetime2_0: time).first
|
412
|
+
_(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
413
|
+
_(obj).must_equal obj.class.where(datetime2_0: time).first
|
414
414
|
end
|
415
415
|
|
416
416
|
it 'datetimeoffset' do
|
417
|
-
skip 'datetimeoffset not supported in this
|
417
|
+
skip 'datetimeoffset not supported in this protocol version' unless connection_dblib_73?
|
418
418
|
col = column('datetimeoffset_7')
|
419
|
-
col.sql_type.must_equal 'datetimeoffset(7)'
|
420
|
-
col.type.must_equal :datetimeoffset
|
421
|
-
col.null.must_equal true
|
419
|
+
_(col.sql_type).must_equal 'datetimeoffset(7)'
|
420
|
+
_(col.type).must_equal :datetimeoffset
|
421
|
+
_(col.null).must_equal true
|
422
422
|
time = Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700)
|
423
|
-
col.default.must_equal time, "Nanoseconds <#{col.default.nsec}> vs <123456700>"
|
424
|
-
obj.datetimeoffset_7.must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
|
425
|
-
col.default_function.must_be_nil
|
423
|
+
_(col.default).must_equal time, "Nanoseconds <#{col.default.nsec}> vs <123456700>"
|
424
|
+
_(obj.datetimeoffset_7).must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
|
425
|
+
_(col.default_function).must_be_nil
|
426
426
|
type = connection.lookup_cast_type_from_column(col)
|
427
|
-
type.must_be_instance_of Type::DateTimeOffset
|
428
|
-
type.limit.must_be_nil
|
429
|
-
type.precision.must_equal 7
|
430
|
-
type.scale.must_be_nil
|
431
|
-
|
432
|
-
obj.must_equal obj.class.where(datetimeoffset_7: time).first
|
427
|
+
_(type).must_be_instance_of Type::DateTimeOffset
|
428
|
+
_(type.limit).must_be_nil
|
429
|
+
_(type.precision).must_equal 7
|
430
|
+
_(type.scale).must_be_nil
|
431
|
+
|
433
432
|
# Can save 100 nanosecond precisoins and return again.
|
434
433
|
time = Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456700)
|
435
434
|
obj.datetimeoffset_7 = Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456755)
|
436
|
-
obj.datetimeoffset_7.must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>" # Was rounding instead of truncating
|
435
|
+
_(obj.datetimeoffset_7).must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>" # Was rounding instead of truncating
|
437
436
|
obj.save!
|
438
|
-
obj.datetimeoffset_7.must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>"
|
437
|
+
_(obj.datetimeoffset_7).must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>"
|
439
438
|
obj.reload
|
440
|
-
obj.datetimeoffset_7.must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>"
|
441
|
-
obj.must_equal obj.class.where(datetimeoffset_7: time).first
|
439
|
+
_(obj.datetimeoffset_7).must_equal time, "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456700>"
|
440
|
+
_(obj).must_equal obj.class.where(datetimeoffset_7: time).first
|
442
441
|
# Maintains the timezone
|
443
442
|
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456700, 1000)
|
444
443
|
obj.datetimeoffset_7 = time
|
445
|
-
obj.datetimeoffset_7.must_equal time
|
444
|
+
_(obj.datetimeoffset_7).must_equal time
|
446
445
|
obj.save!
|
447
|
-
obj.datetimeoffset_7.must_equal time
|
448
|
-
obj.reload.datetimeoffset_7.must_equal time
|
449
|
-
obj.must_equal obj.class.where(datetimeoffset_7: time).first
|
446
|
+
_(obj.datetimeoffset_7).must_equal time
|
447
|
+
_(obj.reload.datetimeoffset_7).must_equal time
|
450
448
|
# With other precisions.
|
451
449
|
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
452
450
|
col = column('datetimeoffset_3')
|
453
|
-
connection.lookup_cast_type_from_column(col).precision.must_equal 3
|
451
|
+
_(connection.lookup_cast_type_from_column(col).precision).must_equal 3
|
454
452
|
obj.datetimeoffset_3 = time
|
455
|
-
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
453
|
+
_(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
456
454
|
obj.save!
|
457
|
-
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
455
|
+
_(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
458
456
|
col = column('datetime2_1')
|
459
|
-
connection.lookup_cast_type_from_column(col).precision.must_equal 1
|
457
|
+
_(connection.lookup_cast_type_from_column(col).precision).must_equal 1
|
460
458
|
obj.datetime2_1 = time
|
461
|
-
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
459
|
+
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
462
460
|
obj.save!
|
463
|
-
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
461
|
+
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
464
462
|
end
|
465
463
|
|
466
464
|
it 'smalldatetime' do
|
467
465
|
col = column('smalldatetime')
|
468
|
-
col.sql_type.must_equal 'smalldatetime'
|
469
|
-
col.type.must_equal :smalldatetime
|
470
|
-
col.null.must_equal true
|
466
|
+
_(col.sql_type).must_equal 'smalldatetime'
|
467
|
+
_(col.type).must_equal :smalldatetime
|
468
|
+
_(col.null).must_equal true
|
471
469
|
time = Time.utc(1901, 01, 01, 15, 45, 00, 000)
|
472
|
-
col.default.must_equal time
|
473
|
-
obj.smalldatetime.must_equal time
|
474
|
-
col.default_function.must_be_nil
|
475
|
-
type = connection.lookup_cast_type_from_column(col)
|
476
|
-
type.must_be_instance_of Type::SmallDateTime
|
477
|
-
type.limit.must_be_nil
|
478
|
-
type.precision.must_be_nil
|
479
|
-
type.scale.must_be_nil
|
480
|
-
obj.save!
|
481
|
-
obj.must_equal obj.class.where(smalldatetime: time).first
|
470
|
+
_(col.default).must_equal time
|
471
|
+
_(obj.smalldatetime).must_equal time
|
472
|
+
_(col.default_function).must_be_nil
|
473
|
+
type = connection.lookup_cast_type_from_column(col)
|
474
|
+
_(type).must_be_instance_of Type::SmallDateTime
|
475
|
+
_(type.limit).must_be_nil
|
476
|
+
_(type.precision).must_be_nil
|
477
|
+
_(type.scale).must_be_nil
|
482
478
|
# Will remove fractional seconds and return again.
|
483
479
|
obj.smalldatetime = Time.utc(2078, 06, 05, 4, 20, 00, 3000)
|
484
|
-
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.smalldatetime.usec}> vs <0>"
|
480
|
+
_(obj.smalldatetime).must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.smalldatetime.usec}> vs <0>"
|
485
481
|
obj.save!
|
486
|
-
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
482
|
+
_(obj.smalldatetime).must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
487
483
|
obj.reload
|
488
|
-
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
484
|
+
_(obj.smalldatetime).must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
489
485
|
end
|
490
486
|
|
491
487
|
it 'time(7)' do
|
492
|
-
skip 'time() not supported in this
|
488
|
+
skip 'time() not supported in this protocol version' unless connection_dblib_73?
|
493
489
|
col = column('time_7')
|
494
|
-
col.sql_type.must_equal 'time(7)'
|
495
|
-
col.type.must_equal :time
|
496
|
-
col.null.must_equal true
|
497
|
-
col.default.must_equal Time.utc(1900, 01, 01, 04, 20, 00, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
|
498
|
-
col.default_function.must_be_nil
|
499
|
-
type = connection.lookup_cast_type_from_column(col)
|
500
|
-
type.must_be_instance_of Type::Time
|
501
|
-
type.limit.must_be_nil
|
502
|
-
type.precision.must_equal 7
|
503
|
-
type.scale.must_be_nil
|
490
|
+
_(col.sql_type).must_equal 'time(7)'
|
491
|
+
_(col.type).must_equal :time
|
492
|
+
_(col.null).must_equal true
|
493
|
+
_(col.default).must_equal Time.utc(1900, 01, 01, 04, 20, 00, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
|
494
|
+
_(col.default_function).must_be_nil
|
495
|
+
type = connection.lookup_cast_type_from_column(col)
|
496
|
+
_(type).must_be_instance_of Type::Time
|
497
|
+
_(type.limit).must_be_nil
|
498
|
+
_(type.precision).must_equal 7
|
499
|
+
_(type.scale).must_be_nil
|
504
500
|
# Time's #usec precision (low micro)
|
505
501
|
obj.time_7 = Time.utc(2000, 01, 01, 15, 45, 00, 300)
|
506
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
507
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
|
502
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
503
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
|
508
504
|
obj.save! ; obj.reload
|
509
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
510
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
|
505
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
506
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_7.nsec}> vs <300>"
|
511
507
|
# Time's #usec precision (high micro)
|
512
508
|
obj.time_7 = Time.utc(2000, 01, 01, 15, 45, 00, 234567)
|
513
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
|
509
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
|
514
510
|
obj.save! ; obj.reload
|
515
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
|
511
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_7.usec}> vs <234567>"
|
516
512
|
# Time's #usec precision (high nano rounded)
|
517
513
|
obj.time_7 = Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321545, 1000))
|
518
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
|
514
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
|
519
515
|
obj.save! ; obj.reload
|
520
|
-
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
|
516
|
+
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_7.nsec}> vs <288321500>"
|
521
517
|
end
|
522
518
|
|
523
519
|
it 'time(2)' do
|
524
|
-
skip 'time() not supported in this
|
520
|
+
skip 'time() not supported in this protocol version' unless connection_dblib_73?
|
525
521
|
col = column('time_2')
|
526
|
-
col.sql_type.must_equal 'time(2)'
|
527
|
-
col.type.must_equal :time
|
528
|
-
col.null.must_equal true
|
529
|
-
col.default.must_be_nil
|
530
|
-
col.default_function.must_be_nil
|
531
|
-
type = connection.lookup_cast_type_from_column(col)
|
532
|
-
type.must_be_instance_of Type::Time
|
533
|
-
type.limit.must_be_nil
|
534
|
-
type.precision.must_equal 2
|
535
|
-
type.scale.must_be_nil
|
522
|
+
_(col.sql_type).must_equal 'time(2)'
|
523
|
+
_(col.type).must_equal :time
|
524
|
+
_(col.null).must_equal true
|
525
|
+
_(col.default).must_be_nil
|
526
|
+
_(col.default_function).must_be_nil
|
527
|
+
type = connection.lookup_cast_type_from_column(col)
|
528
|
+
_(type).must_be_instance_of Type::Time
|
529
|
+
_(type.limit).must_be_nil
|
530
|
+
_(type.precision).must_equal 2
|
531
|
+
_(type.scale).must_be_nil
|
536
532
|
# Always uses TinyTDS/Windows 2000-01-01 convention too.
|
537
533
|
obj.time_2 = Time.utc(2015, 01, 10, 15, 45, 00, 0)
|
538
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0)
|
534
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0)
|
539
535
|
obj.save! ; obj.reload
|
540
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0)
|
536
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0)
|
541
537
|
# Time's #usec precision (barely in 2 precision equal to 0.03 seconds)
|
542
538
|
obj.time_2 = Time.utc(2000, 01, 01, 15, 45, 00, 30000)
|
543
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
|
539
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
|
544
540
|
obj.save! ; obj.reload
|
545
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
|
541
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 30000), "Microseconds were <#{obj.time_2.usec}> vs <30000>"
|
546
542
|
# Time's #usec precision (below 2 precision)
|
547
543
|
obj.time_2 = Time.utc(2000, 01, 01, 15, 45, 00, 4000)
|
548
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
|
544
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
|
549
545
|
obj.save! ; obj.reload
|
550
|
-
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
|
546
|
+
_(obj.time_2).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0), "Microseconds were <#{obj.time_2.usec}> vs <0>"
|
547
|
+
end
|
548
|
+
|
549
|
+
it 'time using default precision' do
|
550
|
+
skip 'time() not supported in this protocol version' unless connection_dblib_73?
|
551
|
+
col = column('time_default')
|
552
|
+
_(col.sql_type).must_equal 'time(7)'
|
553
|
+
_(col.type).must_equal :time
|
554
|
+
_(col.null).must_equal true
|
555
|
+
_(col.default).must_equal Time.utc(1900, 01, 01, 15, 03, 42, Rational(62197800, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <62197800>"
|
556
|
+
_(col.default_function).must_be_nil
|
557
|
+
type = connection.lookup_cast_type_from_column(col)
|
558
|
+
_(type).must_be_instance_of Type::Time
|
559
|
+
_(type.limit).must_be_nil
|
560
|
+
_(type.precision).must_equal 7
|
561
|
+
_(type.scale).must_be_nil
|
562
|
+
# Time's #usec precision (low micro)
|
563
|
+
obj.time_default = Time.utc(2000, 01, 01, 15, 45, 00, 300)
|
564
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
|
565
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
|
566
|
+
obj.save! ; obj.reload
|
567
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
|
568
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
|
569
|
+
# Time's #usec precision (high micro)
|
570
|
+
obj.time_default = Time.utc(2000, 01, 01, 15, 45, 00, 234567)
|
571
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_default.usec}> vs <234567>"
|
572
|
+
obj.save! ; obj.reload
|
573
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 234567), "Microseconds were <#{obj.time_default.usec}> vs <234567>"
|
574
|
+
# Time's #usec precision (high nano rounded)
|
575
|
+
obj.time_default = Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321545, 1000))
|
576
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_default.nsec}> vs <288321500>"
|
577
|
+
obj.save! ; obj.reload
|
578
|
+
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, Rational(288321500, 1000)), "Nanoseconds were <#{obj.time_default.nsec}> vs <288321500>"
|
551
579
|
end
|
552
580
|
|
553
581
|
# Character Strings
|
554
582
|
|
555
583
|
it 'char(10)' do
|
556
584
|
col = column('char_10')
|
557
|
-
col.sql_type.must_equal 'char(10)'
|
558
|
-
col.type.must_equal :char
|
559
|
-
col.null.must_equal true
|
560
|
-
col.default.must_equal '1234567890'
|
561
|
-
obj.char_10.must_equal '1234567890'
|
562
|
-
col.default_function.must_be_nil
|
563
|
-
type = connection.lookup_cast_type_from_column(col)
|
564
|
-
type.must_be_instance_of Type::Char
|
565
|
-
type.limit.must_equal 10
|
566
|
-
type.precision.must_be_nil
|
567
|
-
type.scale.must_be_nil
|
585
|
+
_(col.sql_type).must_equal 'char(10)'
|
586
|
+
_(col.type).must_equal :char
|
587
|
+
_(col.null).must_equal true
|
588
|
+
_(col.default).must_equal '1234567890'
|
589
|
+
_(obj.char_10).must_equal '1234567890'
|
590
|
+
_(col.default_function).must_be_nil
|
591
|
+
type = connection.lookup_cast_type_from_column(col)
|
592
|
+
_(type).must_be_instance_of Type::Char
|
593
|
+
_(type.limit).must_equal 10
|
594
|
+
_(type.precision).must_be_nil
|
595
|
+
_(type.scale).must_be_nil
|
568
596
|
# Basic set and save.
|
569
597
|
obj.char_10 = '012345'
|
570
|
-
obj.char_10.strip.must_equal '012345'
|
598
|
+
_(obj.char_10.strip).must_equal '012345'
|
571
599
|
obj.save!
|
572
|
-
obj.reload.char_10.strip.must_equal '012345'
|
600
|
+
_(obj.reload.char_10.strip).must_equal '012345'
|
573
601
|
end
|
574
602
|
|
575
603
|
it 'varchar(50)' do
|
576
604
|
col = column('varchar_50')
|
577
|
-
col.sql_type.must_equal 'varchar(50)'
|
578
|
-
col.type.must_equal :varchar
|
579
|
-
col.null.must_equal true
|
580
|
-
col.default.must_equal 'test varchar_50'
|
581
|
-
obj.varchar_50.must_equal 'test varchar_50'
|
582
|
-
col.default_function.must_be_nil
|
583
|
-
type = connection.lookup_cast_type_from_column(col)
|
584
|
-
type.must_be_instance_of Type::Varchar
|
585
|
-
type.limit.must_equal 50
|
586
|
-
type.precision.must_be_nil
|
587
|
-
type.scale.must_be_nil
|
605
|
+
_(col.sql_type).must_equal 'varchar(50)'
|
606
|
+
_(col.type).must_equal :varchar
|
607
|
+
_(col.null).must_equal true
|
608
|
+
_(col.default).must_equal 'test varchar_50'
|
609
|
+
_(obj.varchar_50).must_equal 'test varchar_50'
|
610
|
+
_(col.default_function).must_be_nil
|
611
|
+
type = connection.lookup_cast_type_from_column(col)
|
612
|
+
_(type).must_be_instance_of Type::Varchar
|
613
|
+
_(type.limit).must_equal 50
|
614
|
+
_(type.precision).must_be_nil
|
615
|
+
_(type.scale).must_be_nil
|
588
616
|
# Basic set and save.
|
589
617
|
assert_obj_set_and_save :varchar_50, 'Hello World'
|
590
618
|
end
|
591
619
|
|
592
620
|
it 'varchar(max)' do
|
593
621
|
col = column('varchar_max')
|
594
|
-
col.sql_type.must_equal 'varchar(max)'
|
595
|
-
col.type.must_equal :varchar_max
|
596
|
-
col.null.must_equal true
|
597
|
-
col.default.must_equal 'test varchar_max'
|
598
|
-
obj.varchar_max.must_equal 'test varchar_max'
|
599
|
-
col.default_function.must_be_nil
|
600
|
-
type = connection.lookup_cast_type_from_column(col)
|
601
|
-
type.must_be_instance_of Type::VarcharMax
|
602
|
-
type.limit.must_equal 2_147_483_647
|
603
|
-
type.precision.must_be_nil
|
604
|
-
type.scale.must_be_nil
|
622
|
+
_(col.sql_type).must_equal 'varchar(max)'
|
623
|
+
_(col.type).must_equal :varchar_max
|
624
|
+
_(col.null).must_equal true
|
625
|
+
_(col.default).must_equal 'test varchar_max'
|
626
|
+
_(obj.varchar_max).must_equal 'test varchar_max'
|
627
|
+
_(col.default_function).must_be_nil
|
628
|
+
type = connection.lookup_cast_type_from_column(col)
|
629
|
+
_(type).must_be_instance_of Type::VarcharMax
|
630
|
+
_(type.limit).must_equal 2_147_483_647
|
631
|
+
_(type.precision).must_be_nil
|
632
|
+
_(type.scale).must_be_nil
|
605
633
|
# Basic set and save.
|
606
634
|
assert_obj_set_and_save :varchar_max, 'Hello World'
|
607
635
|
end
|
608
636
|
|
609
637
|
it 'text' do
|
610
638
|
col = column('text')
|
611
|
-
col.sql_type.must_equal 'text'
|
612
|
-
col.type.must_equal :text_basic
|
613
|
-
col.null.must_equal true
|
614
|
-
col.default.must_equal 'test text'
|
615
|
-
obj.text.must_equal 'test text'
|
616
|
-
col.default_function.must_be_nil
|
617
|
-
type = connection.lookup_cast_type_from_column(col)
|
618
|
-
type.must_be_instance_of Type::Text
|
619
|
-
type.limit.must_equal 2_147_483_647
|
620
|
-
type.precision.must_be_nil
|
621
|
-
type.scale.must_be_nil
|
639
|
+
_(col.sql_type).must_equal 'text'
|
640
|
+
_(col.type).must_equal :text_basic
|
641
|
+
_(col.null).must_equal true
|
642
|
+
_(col.default).must_equal 'test text'
|
643
|
+
_(obj.text).must_equal 'test text'
|
644
|
+
_(col.default_function).must_be_nil
|
645
|
+
type = connection.lookup_cast_type_from_column(col)
|
646
|
+
_(type).must_be_instance_of Type::Text
|
647
|
+
_(type.limit).must_equal 2_147_483_647
|
648
|
+
_(type.precision).must_be_nil
|
649
|
+
_(type.scale).must_be_nil
|
622
650
|
# Basic set and save.
|
623
651
|
assert_obj_set_and_save :text, 'Hello World'
|
624
652
|
end
|
@@ -627,71 +655,71 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
627
655
|
|
628
656
|
it 'nchar(10)' do
|
629
657
|
col = column('nchar_10')
|
630
|
-
col.sql_type.must_equal 'nchar(10)'
|
631
|
-
col.type.must_equal :nchar
|
632
|
-
col.null.must_equal true
|
633
|
-
col.default.must_equal '12345678åå'
|
634
|
-
obj.nchar_10.must_equal '12345678åå'
|
635
|
-
col.default_function.must_be_nil
|
636
|
-
type = connection.lookup_cast_type_from_column(col)
|
637
|
-
type.must_be_instance_of Type::UnicodeChar
|
638
|
-
type.limit.must_equal 10
|
639
|
-
type.precision.must_be_nil
|
640
|
-
type.scale.must_be_nil
|
658
|
+
_(col.sql_type).must_equal 'nchar(10)'
|
659
|
+
_(col.type).must_equal :nchar
|
660
|
+
_(col.null).must_equal true
|
661
|
+
_(col.default).must_equal '12345678åå'
|
662
|
+
_(obj.nchar_10).must_equal '12345678åå'
|
663
|
+
_(col.default_function).must_be_nil
|
664
|
+
type = connection.lookup_cast_type_from_column(col)
|
665
|
+
_(type).must_be_instance_of Type::UnicodeChar
|
666
|
+
_(type.limit).must_equal 10
|
667
|
+
_(type.precision).must_be_nil
|
668
|
+
_(type.scale).must_be_nil
|
641
669
|
# Basic set and save.
|
642
670
|
obj.nchar_10 = "五六"
|
643
|
-
obj.nchar_10.strip.must_equal "五六"
|
671
|
+
_(obj.nchar_10.strip).must_equal "五六"
|
644
672
|
obj.save!
|
645
|
-
obj.reload.nchar_10.strip.must_equal "五六"
|
673
|
+
_(obj.reload.nchar_10.strip).must_equal "五六"
|
646
674
|
end
|
647
675
|
|
648
676
|
it 'nvarchar(50)' do
|
649
677
|
col = column('nvarchar_50')
|
650
|
-
col.sql_type.must_equal 'nvarchar(50)'
|
651
|
-
col.type.must_equal :string
|
652
|
-
col.null.must_equal true
|
653
|
-
col.default.must_equal 'test nvarchar_50 åå'
|
654
|
-
obj.nvarchar_50.must_equal 'test nvarchar_50 åå'
|
655
|
-
col.default_function.must_be_nil
|
656
|
-
type = connection.lookup_cast_type_from_column(col)
|
657
|
-
type.must_be_instance_of Type::UnicodeVarchar
|
658
|
-
type.limit.must_equal 50
|
659
|
-
type.precision.must_be_nil
|
660
|
-
type.scale.must_be_nil
|
678
|
+
_(col.sql_type).must_equal 'nvarchar(50)'
|
679
|
+
_(col.type).must_equal :string
|
680
|
+
_(col.null).must_equal true
|
681
|
+
_(col.default).must_equal 'test nvarchar_50 åå'
|
682
|
+
_(obj.nvarchar_50).must_equal 'test nvarchar_50 åå'
|
683
|
+
_(col.default_function).must_be_nil
|
684
|
+
type = connection.lookup_cast_type_from_column(col)
|
685
|
+
_(type).must_be_instance_of Type::UnicodeVarchar
|
686
|
+
_(type.limit).must_equal 50
|
687
|
+
_(type.precision).must_be_nil
|
688
|
+
_(type.scale).must_be_nil
|
661
689
|
# Basic set and save.
|
662
690
|
assert_obj_set_and_save :nvarchar_50, "一二34五六"
|
663
691
|
end
|
664
692
|
|
665
693
|
it 'nvarchar(max)' do
|
666
694
|
col = column('nvarchar_max')
|
667
|
-
col.sql_type.must_equal 'nvarchar(max)'
|
668
|
-
col.type.must_equal :text
|
669
|
-
col.null.must_equal true
|
670
|
-
col.default.must_equal 'test nvarchar_max åå'
|
671
|
-
obj.nvarchar_max.must_equal 'test nvarchar_max åå'
|
672
|
-
col.default_function.must_be_nil
|
673
|
-
type = connection.lookup_cast_type_from_column(col)
|
674
|
-
type.must_be_instance_of Type::UnicodeVarcharMax
|
675
|
-
type.limit.must_equal 2_147_483_647
|
676
|
-
type.precision.must_be_nil
|
677
|
-
type.scale.must_be_nil
|
695
|
+
_(col.sql_type).must_equal 'nvarchar(max)'
|
696
|
+
_(col.type).must_equal :text
|
697
|
+
_(col.null).must_equal true
|
698
|
+
_(col.default).must_equal 'test nvarchar_max åå'
|
699
|
+
_(obj.nvarchar_max).must_equal 'test nvarchar_max åå'
|
700
|
+
_(col.default_function).must_be_nil
|
701
|
+
type = connection.lookup_cast_type_from_column(col)
|
702
|
+
_(type).must_be_instance_of Type::UnicodeVarcharMax
|
703
|
+
_(type.limit).must_equal 2_147_483_647
|
704
|
+
_(type.precision).must_be_nil
|
705
|
+
_(type.scale).must_be_nil
|
678
706
|
# Basic set and save.
|
679
707
|
assert_obj_set_and_save :nvarchar_max, "一二34五六"
|
680
708
|
end
|
681
709
|
|
682
710
|
it 'ntext' do
|
683
711
|
col = column('ntext')
|
684
|
-
col.sql_type.must_equal 'ntext'
|
685
|
-
col.type.must_equal :ntext
|
686
|
-
col.null.must_equal true
|
687
|
-
col.default.must_equal 'test ntext åå'
|
688
|
-
obj.ntext.must_equal 'test ntext åå'
|
689
|
-
col.default_function.must_be_nil
|
690
|
-
type = connection.lookup_cast_type_from_column(col)
|
691
|
-
type.must_be_instance_of Type::UnicodeText
|
692
|
-
type.limit.must_equal 2_147_483_647
|
693
|
-
type.precision.must_be_nil
|
694
|
-
type.scale.must_be_nil
|
712
|
+
_(col.sql_type).must_equal 'ntext'
|
713
|
+
_(col.type).must_equal :ntext
|
714
|
+
_(col.null).must_equal true
|
715
|
+
_(col.default).must_equal 'test ntext åå'
|
716
|
+
_(obj.ntext).must_equal 'test ntext åå'
|
717
|
+
_(col.default_function).must_be_nil
|
718
|
+
type = connection.lookup_cast_type_from_column(col)
|
719
|
+
_(type).must_be_instance_of Type::UnicodeText
|
720
|
+
_(type.limit).must_equal 2_147_483_647
|
721
|
+
_(type.precision).must_be_nil
|
722
|
+
_(type.scale).must_be_nil
|
695
723
|
# Basic set and save.
|
696
724
|
assert_obj_set_and_save :ntext, "一二34五六"
|
697
725
|
end
|
@@ -703,60 +731,60 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
703
731
|
|
704
732
|
it 'binary(49)' do
|
705
733
|
col = column('binary_49')
|
706
|
-
col.sql_type.must_equal 'binary(49)'
|
707
|
-
col.type.must_equal :binary_basic
|
708
|
-
col.null.must_equal true
|
709
|
-
col.default.must_be_nil
|
710
|
-
col.default_function.must_be_nil
|
711
|
-
type = connection.lookup_cast_type_from_column(col)
|
712
|
-
type.must_be_instance_of Type::Binary
|
713
|
-
type.limit.must_equal 49
|
714
|
-
type.precision.must_be_nil
|
715
|
-
type.scale.must_be_nil
|
734
|
+
_(col.sql_type).must_equal 'binary(49)'
|
735
|
+
_(col.type).must_equal :binary_basic
|
736
|
+
_(col.null).must_equal true
|
737
|
+
_(col.default).must_be_nil
|
738
|
+
_(col.default_function).must_be_nil
|
739
|
+
type = connection.lookup_cast_type_from_column(col)
|
740
|
+
_(type).must_be_instance_of Type::Binary
|
741
|
+
_(type.limit).must_equal 49
|
742
|
+
_(type.precision).must_be_nil
|
743
|
+
_(type.scale).must_be_nil
|
716
744
|
# Basic set and save.
|
717
|
-
binary_data.encoding.must_equal Encoding::BINARY
|
718
|
-
binary_data.length.must_equal 49
|
745
|
+
_(binary_data.encoding).must_equal Encoding::BINARY
|
746
|
+
_(binary_data.length).must_equal 49
|
719
747
|
obj.binary_49 = binary_data
|
720
|
-
obj.binary_49.must_equal binary_data
|
748
|
+
_(obj.binary_49).must_equal binary_data
|
721
749
|
obj.save!
|
722
|
-
obj.reload.binary_49.must_equal binary_data
|
750
|
+
_(obj.reload.binary_49).must_equal binary_data
|
723
751
|
end
|
724
752
|
|
725
753
|
it 'varbinary(49)' do
|
726
754
|
col = column('varbinary_49')
|
727
|
-
col.sql_type.must_equal 'varbinary(49)'
|
728
|
-
col.type.must_equal :varbinary
|
729
|
-
col.null.must_equal true
|
730
|
-
col.default.must_be_nil
|
731
|
-
col.default_function.must_be_nil
|
732
|
-
type = connection.lookup_cast_type_from_column(col)
|
733
|
-
type.must_be_instance_of Type::Varbinary
|
734
|
-
type.limit.must_equal 49
|
735
|
-
type.precision.must_be_nil
|
736
|
-
type.scale.must_be_nil
|
755
|
+
_(col.sql_type).must_equal 'varbinary(49)'
|
756
|
+
_(col.type).must_equal :varbinary
|
757
|
+
_(col.null).must_equal true
|
758
|
+
_(col.default).must_be_nil
|
759
|
+
_(col.default_function).must_be_nil
|
760
|
+
type = connection.lookup_cast_type_from_column(col)
|
761
|
+
_(type).must_be_instance_of Type::Varbinary
|
762
|
+
_(type.limit).must_equal 49
|
763
|
+
_(type.precision).must_be_nil
|
764
|
+
_(type.scale).must_be_nil
|
737
765
|
# Basic set and save.
|
738
766
|
binary_data_20 = binary_data.to(20)
|
739
|
-
binary_data_20.encoding.must_equal Encoding::BINARY
|
767
|
+
_(binary_data_20.encoding).must_equal Encoding::BINARY
|
740
768
|
obj.varbinary_49 = binary_data_20
|
741
|
-
obj.varbinary_49.must_equal binary_data_20
|
769
|
+
_(obj.varbinary_49).must_equal binary_data_20
|
742
770
|
obj.save!
|
743
|
-
obj.reload.varbinary_49.must_equal binary_data_20
|
771
|
+
_(obj.reload.varbinary_49).must_equal binary_data_20
|
744
772
|
end
|
745
773
|
|
746
774
|
it 'varbinary(max)' do
|
747
775
|
col = column('varbinary_max')
|
748
|
-
col.sql_type.must_equal 'varbinary(max)'
|
749
|
-
col.type.must_equal :binary
|
750
|
-
col.null.must_equal true
|
751
|
-
col.default.must_be_nil
|
752
|
-
col.default_function.must_be_nil
|
753
|
-
type = connection.lookup_cast_type_from_column(col)
|
754
|
-
type.must_be_instance_of Type::VarbinaryMax
|
755
|
-
type.limit.must_equal 2_147_483_647
|
756
|
-
type.precision.must_be_nil
|
757
|
-
type.scale.must_be_nil
|
776
|
+
_(col.sql_type).must_equal 'varbinary(max)'
|
777
|
+
_(col.type).must_equal :binary
|
778
|
+
_(col.null).must_equal true
|
779
|
+
_(col.default).must_be_nil
|
780
|
+
_(col.default_function).must_be_nil
|
781
|
+
type = connection.lookup_cast_type_from_column(col)
|
782
|
+
_(type).must_be_instance_of Type::VarbinaryMax
|
783
|
+
_(type.limit).must_equal 2_147_483_647
|
784
|
+
_(type.precision).must_be_nil
|
785
|
+
_(type.scale).must_be_nil
|
758
786
|
# Basic set and save.
|
759
|
-
binary_data.encoding.must_equal Encoding::BINARY
|
787
|
+
_(binary_data.encoding).must_equal Encoding::BINARY
|
760
788
|
assert_obj_set_and_save :varbinary_max, binary_data
|
761
789
|
end
|
762
790
|
|
@@ -764,49 +792,55 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
764
792
|
|
765
793
|
it 'uniqueidentifier' do
|
766
794
|
col = column('uniqueidentifier')
|
767
|
-
col.sql_type.must_equal 'uniqueidentifier'
|
768
|
-
col.type.must_equal :uuid
|
769
|
-
col.null.must_equal true
|
770
|
-
col.default.must_be_nil
|
771
|
-
col.default_function.must_equal 'newid()'
|
772
|
-
type = connection.lookup_cast_type_from_column(col)
|
773
|
-
type.must_be_instance_of Type::Uuid
|
774
|
-
type.limit.must_be_nil
|
775
|
-
type.precision.must_be_nil
|
776
|
-
type.scale.must_be_nil
|
795
|
+
_(col.sql_type).must_equal 'uniqueidentifier'
|
796
|
+
_(col.type).must_equal :uuid
|
797
|
+
_(col.null).must_equal true
|
798
|
+
_(col.default).must_be_nil
|
799
|
+
_(col.default_function).must_equal 'newid()'
|
800
|
+
type = connection.lookup_cast_type_from_column(col)
|
801
|
+
_(type).must_be_instance_of Type::Uuid
|
802
|
+
_(type.limit).must_be_nil
|
803
|
+
_(type.precision).must_be_nil
|
804
|
+
_(type.scale).must_be_nil
|
777
805
|
# Basic set and save.
|
778
806
|
obj.uniqueidentifier = "this will not qualify as valid"
|
779
|
-
obj.uniqueidentifier.must_be_nil
|
807
|
+
_(obj.uniqueidentifier).must_be_nil
|
780
808
|
obj.save! ; obj.reload
|
781
|
-
obj.uniqueidentifier.must_match Type::Uuid::ACCEPTABLE_UUID
|
809
|
+
_(obj.uniqueidentifier).must_match Type::Uuid::ACCEPTABLE_UUID
|
782
810
|
obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
783
|
-
obj.uniqueidentifier.must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
811
|
+
_(obj.uniqueidentifier).must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
784
812
|
obj.save! ; obj.reload
|
785
|
-
obj.uniqueidentifier.must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
813
|
+
_(obj.uniqueidentifier).must_equal "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
786
814
|
end
|
787
815
|
|
788
816
|
it 'timestamp' do
|
789
817
|
col = column('timestamp')
|
790
|
-
col.sql_type.must_equal 'timestamp'
|
791
|
-
col.type.must_equal :ss_timestamp
|
792
|
-
col.null.must_equal true
|
793
|
-
col.default.must_be_nil
|
794
|
-
col.default_function.must_be_nil
|
795
|
-
type = connection.lookup_cast_type_from_column(col)
|
796
|
-
type.must_be_instance_of Type::Timestamp
|
797
|
-
type.limit.must_be_nil
|
798
|
-
type.precision.must_be_nil
|
799
|
-
type.scale.must_be_nil
|
818
|
+
_(col.sql_type).must_equal 'timestamp'
|
819
|
+
_(col.type).must_equal :ss_timestamp
|
820
|
+
_(col.null).must_equal true
|
821
|
+
_(col.default).must_be_nil
|
822
|
+
_(col.default_function).must_be_nil
|
823
|
+
type = connection.lookup_cast_type_from_column(col)
|
824
|
+
_(type).must_be_instance_of Type::Timestamp
|
825
|
+
_(type.limit).must_be_nil
|
826
|
+
_(type.precision).must_be_nil
|
827
|
+
_(type.scale).must_be_nil
|
800
828
|
# Basic read.
|
801
|
-
obj.timestamp.must_be_nil
|
829
|
+
_(obj.timestamp).must_be_nil
|
802
830
|
obj.save! ; obj.reload
|
803
|
-
obj.timestamp.must_match %r|\000|
|
831
|
+
_(obj.timestamp).must_match %r|\000|
|
804
832
|
obj.timestamp
|
805
833
|
# Can set another attribute
|
806
834
|
obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
807
835
|
obj.save!
|
808
836
|
end
|
809
837
|
|
838
|
+
it 'does not mark object as changed after save' do
|
839
|
+
obj.save!
|
840
|
+
obj.attributes
|
841
|
+
_(obj.changed?).must_equal false
|
842
|
+
end
|
843
|
+
|
810
844
|
end
|
811
845
|
|
812
846
|
end
|