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