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