activerecord-sqlserver-adapter 5.2.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +38 -24
- data/{Dockerfile → Dockerfile.ci} +1 -1
- data/Gemfile +48 -41
- data/Guardfile +9 -8
- data/README.md +9 -30
- 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 +190 -164
- 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/showplan.rb +8 -8
- 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/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/type.rb +37 -35
- 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 +128 -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 +214 -171
- data/test/cases/change_column_null_test_sqlserver.rb +14 -12
- data/test/cases/coerced_tests.rb +631 -356
- data/test/cases/column_test_sqlserver.rb +283 -284
- 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/migration_test_sqlserver.rb +25 -29
- 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 +107 -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 +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 +17 -7
|
@@ -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,220 @@ 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
|
|
159
160
|
type = connection.lookup_cast_type_from_column(col)
|
|
160
|
-
_(type).must_be_instance_of
|
|
161
|
+
_(type).must_be_instance_of Type::Decimal
|
|
161
162
|
_(type.limit).must_be_nil
|
|
162
163
|
_(type.precision).must_equal 18
|
|
163
164
|
_(type.scale).must_equal 0
|
|
164
|
-
obj.numeric_18_0 =
|
|
165
|
-
_(obj.numeric_18_0).must_equal
|
|
165
|
+
obj.numeric_18_0 = "192.1"
|
|
166
|
+
_(obj.numeric_18_0).must_equal BigDecimal("192")
|
|
166
167
|
obj.save!
|
|
167
|
-
_(obj.reload.numeric_18_0).must_equal BigDecimal(
|
|
168
|
+
_(obj.reload.numeric_18_0).must_equal BigDecimal("192")
|
|
168
169
|
end
|
|
169
170
|
|
|
170
|
-
it
|
|
171
|
-
col = column(
|
|
172
|
-
_(col.sql_type).must_equal
|
|
171
|
+
it "numeric(36,2)" do
|
|
172
|
+
col = column("numeric_36_2")
|
|
173
|
+
_(col.sql_type).must_equal "numeric(36,2)"
|
|
173
174
|
_(col.type).must_equal :decimal
|
|
174
175
|
_(col.null).must_equal true
|
|
175
|
-
_(col.default).must_equal BigDecimal(
|
|
176
|
-
_(obj.numeric_36_2).must_equal BigDecimal(
|
|
176
|
+
_(col.default).must_equal BigDecimal("12345678901234567890.01")
|
|
177
|
+
_(obj.numeric_36_2).must_equal BigDecimal("12345678901234567890.01")
|
|
177
178
|
_(col.default_function).must_be_nil
|
|
178
179
|
type = connection.lookup_cast_type_from_column(col)
|
|
179
|
-
_(type).must_be_instance_of
|
|
180
|
+
_(type).must_be_instance_of Type::Decimal
|
|
180
181
|
_(type.limit).must_be_nil
|
|
181
182
|
_(type.precision).must_equal 36
|
|
182
183
|
_(type.scale).must_equal 2
|
|
183
|
-
obj.numeric_36_2 =
|
|
184
|
-
_(obj.numeric_36_2).must_equal
|
|
184
|
+
obj.numeric_36_2 = "192.123"
|
|
185
|
+
_(obj.numeric_36_2).must_equal BigDecimal("192.12")
|
|
185
186
|
obj.save!
|
|
186
|
-
_(obj.reload.numeric_36_2).must_equal BigDecimal(
|
|
187
|
+
_(obj.reload.numeric_36_2).must_equal BigDecimal("192.12")
|
|
187
188
|
end
|
|
188
189
|
|
|
189
|
-
it
|
|
190
|
-
col = column(
|
|
191
|
-
_(col.sql_type).must_equal
|
|
190
|
+
it "money" do
|
|
191
|
+
col = column("money")
|
|
192
|
+
_(col.sql_type).must_equal "money"
|
|
192
193
|
_(col.type).must_equal :money
|
|
193
194
|
_(col.null).must_equal true
|
|
194
|
-
_(col.default).must_equal BigDecimal(
|
|
195
|
-
_(obj.money).must_equal BigDecimal(
|
|
195
|
+
_(col.default).must_equal BigDecimal("4.20")
|
|
196
|
+
_(obj.money).must_equal BigDecimal("4.20")
|
|
196
197
|
_(col.default_function).must_be_nil
|
|
197
198
|
type = connection.lookup_cast_type_from_column(col)
|
|
198
|
-
_(type).must_be_instance_of
|
|
199
|
+
_(type).must_be_instance_of Type::Money
|
|
199
200
|
_(type.limit).must_be_nil
|
|
200
201
|
_(type.precision).must_equal 19
|
|
201
202
|
_(type.scale).must_equal 4
|
|
202
|
-
obj.money =
|
|
203
|
-
_(obj.money).must_equal
|
|
203
|
+
obj.money = "922337203685477.58061"
|
|
204
|
+
_(obj.money).must_equal BigDecimal("922337203685477.5806")
|
|
204
205
|
obj.save!
|
|
205
|
-
_(obj.reload.money).must_equal
|
|
206
|
+
_(obj.reload.money).must_equal BigDecimal("922337203685477.5806")
|
|
206
207
|
end
|
|
207
208
|
|
|
208
|
-
it
|
|
209
|
-
col = column(
|
|
210
|
-
_(col.sql_type).must_equal
|
|
209
|
+
it "smallmoney" do
|
|
210
|
+
col = column("smallmoney")
|
|
211
|
+
_(col.sql_type).must_equal "smallmoney"
|
|
211
212
|
_(col.type).must_equal :smallmoney
|
|
212
213
|
_(col.null).must_equal true
|
|
213
|
-
_(col.default).must_equal BigDecimal(
|
|
214
|
-
_(obj.smallmoney).must_equal BigDecimal(
|
|
214
|
+
_(col.default).must_equal BigDecimal("4.20")
|
|
215
|
+
_(obj.smallmoney).must_equal BigDecimal("4.20")
|
|
215
216
|
_(col.default_function).must_be_nil
|
|
216
217
|
type = connection.lookup_cast_type_from_column(col)
|
|
217
|
-
_(type).must_be_instance_of
|
|
218
|
+
_(type).must_be_instance_of Type::SmallMoney
|
|
218
219
|
_(type.limit).must_be_nil
|
|
219
220
|
_(type.precision).must_equal 10
|
|
220
221
|
_(type.scale).must_equal 4
|
|
221
|
-
obj.smallmoney =
|
|
222
|
-
_(obj.smallmoney).must_equal
|
|
222
|
+
obj.smallmoney = "214748.36461"
|
|
223
|
+
_(obj.smallmoney).must_equal BigDecimal("214748.3646")
|
|
223
224
|
obj.save!
|
|
224
|
-
_(obj.reload.smallmoney).must_equal BigDecimal(
|
|
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
|
|
232
|
+
it "float" do
|
|
233
|
+
col = column("float")
|
|
234
|
+
_(col.sql_type).must_equal "float"
|
|
234
235
|
_(col.type).must_equal :float
|
|
235
236
|
_(col.null).must_equal true
|
|
236
237
|
_(col.default).must_equal 123.00000001
|
|
237
238
|
_(obj.float).must_equal 123.00000001
|
|
238
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).must_be_instance_of Type::Float
|
|
241
242
|
_(type.limit).must_be_nil
|
|
242
243
|
_(type.precision).must_be_nil
|
|
243
244
|
_(type.scale).must_be_nil
|
|
244
|
-
obj.float =
|
|
245
|
-
_(obj.float).must_equal
|
|
245
|
+
obj.float = "214748.36461"
|
|
246
|
+
_(obj.float).must_equal 214748.36461
|
|
246
247
|
obj.save!
|
|
247
248
|
_(obj.reload.float).must_equal 214748.36461
|
|
248
249
|
end
|
|
249
250
|
|
|
250
|
-
it
|
|
251
|
-
col = column(
|
|
252
|
-
_(col.sql_type).must_equal
|
|
251
|
+
it "real" do
|
|
252
|
+
col = column("real")
|
|
253
|
+
_(col.sql_type).must_equal "real"
|
|
253
254
|
_(col.type).must_equal :real
|
|
254
255
|
_(col.null).must_equal true
|
|
255
256
|
_(col.default).must_be_close_to 123.45, 0.01
|
|
256
257
|
_(obj.real).must_be_close_to 123.45, 0.01
|
|
257
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).must_be_instance_of Type::Real
|
|
260
261
|
_(type.limit).must_be_nil
|
|
261
262
|
_(type.precision).must_be_nil
|
|
262
263
|
_(type.scale).must_be_nil
|
|
263
|
-
obj.real =
|
|
264
|
-
_(obj.real).must_be_close_to
|
|
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
|
|
272
|
+
it "date" do
|
|
273
|
+
col = column("date")
|
|
274
|
+
_(col.sql_type).must_equal "date"
|
|
274
275
|
_(col.type).must_equal :date
|
|
275
276
|
_(col.null).must_equal true
|
|
276
|
-
_(col.default).must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) :
|
|
277
|
+
_(col.default).must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) : "0001-01-01"
|
|
277
278
|
_(obj.date).must_equal Date.civil(0001, 1, 1)
|
|
278
279
|
_(col.default_function).must_be_nil
|
|
279
280
|
type = connection.lookup_cast_type_from_column(col)
|
|
280
|
-
_(type).must_be_instance_of
|
|
281
|
+
_(type).must_be_instance_of Type::Date
|
|
281
282
|
_(type.limit).must_be_nil
|
|
282
283
|
_(type.precision).must_be_nil
|
|
283
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
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
|
|
308
|
+
it "datetime" do
|
|
309
|
+
col = column("datetime")
|
|
310
|
+
_(col.sql_type).must_equal "datetime"
|
|
310
311
|
_(col.type).must_equal :datetime
|
|
311
312
|
_(col.null).must_equal true
|
|
312
313
|
time = Time.utc 1753, 01, 01, 00, 00, 00, 123000
|
|
@@ -314,7 +315,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
314
315
|
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
|
|
315
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).must_be_instance_of Type::DateTime
|
|
318
319
|
_(type.limit).must_be_nil
|
|
319
320
|
_(type.precision).must_be_nil
|
|
320
321
|
_(type.scale).must_be_nil
|
|
@@ -323,21 +324,21 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
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.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
|
331
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.datetime).must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
|
341
342
|
_(obj).must_equal obj.class.where(datetime: time).first
|
|
342
343
|
_(obj).must_equal obj.class.where(datetime: time2).first
|
|
343
344
|
# Set and find nil.
|
|
@@ -348,10 +349,10 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
348
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
|
|
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)"
|
|
355
356
|
_(col.type).must_equal :datetime
|
|
356
357
|
_(col.null).must_equal true
|
|
357
358
|
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(999999900, 1000)
|
|
@@ -359,97 +360,97 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
359
360
|
_(obj.datetime2_7).must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
|
|
360
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).must_be_instance_of Type::DateTime2
|
|
363
364
|
_(type.limit).must_be_nil
|
|
364
|
-
_(type.precision).must_equal
|
|
365
|
+
_(type.precision).must_equal 7
|
|
365
366
|
_(type.scale).must_be_nil
|
|
366
367
|
obj.save!
|
|
367
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.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456800>"
|
|
377
378
|
_(obj).must_equal obj.class.where(datetime2_7: time).first
|
|
378
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.reload.datetime2_7).must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
|
386
387
|
_(obj).must_equal obj.class.where(datetime2_7: time).first
|
|
387
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
|
+
col = column("datetime2_3")
|
|
391
392
|
_(connection.lookup_cast_type_from_column(col).precision).must_equal 3
|
|
392
393
|
obj.datetime2_3 = time
|
|
393
394
|
_(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
|
394
|
-
obj.save
|
|
395
|
+
obj.save!; obj.reload
|
|
395
396
|
_(obj.datetime2_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
|
396
397
|
_(obj).must_equal obj.class.where(datetime2_3: time).first
|
|
397
398
|
# datetime2_1
|
|
398
|
-
col = column(
|
|
399
|
+
col = column("datetime2_1")
|
|
399
400
|
_(connection.lookup_cast_type_from_column(col).precision).must_equal 1
|
|
400
401
|
obj.datetime2_1 = time
|
|
401
402
|
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
|
402
|
-
obj.save
|
|
403
|
+
obj.save!; obj.reload
|
|
403
404
|
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
|
404
405
|
_(obj).must_equal obj.class.where(datetime2_1: time).first
|
|
405
406
|
# datetime2_0
|
|
406
|
-
col = column(
|
|
407
|
+
col = column("datetime2_0")
|
|
407
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
411
|
_(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
|
411
|
-
obj.save
|
|
412
|
+
obj.save!; obj.reload
|
|
412
413
|
_(obj.datetime2_0).must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
|
413
414
|
_(obj).must_equal obj.class.where(datetime2_0: time).first
|
|
414
415
|
end
|
|
415
416
|
|
|
416
|
-
it
|
|
417
|
-
skip
|
|
418
|
-
col = column(
|
|
419
|
-
_(col.sql_type).must_equal
|
|
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)"
|
|
420
421
|
_(col.type).must_equal :datetimeoffset
|
|
421
422
|
_(col.null).must_equal true
|
|
422
423
|
_(col.default).must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
|
|
423
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>"
|
|
424
425
|
_(col.default_function).must_be_nil
|
|
425
426
|
type = connection.lookup_cast_type_from_column(col)
|
|
426
|
-
_(type).must_be_instance_of
|
|
427
|
+
_(type).must_be_instance_of Type::DateTimeOffset
|
|
427
428
|
_(type.limit).must_be_nil
|
|
428
|
-
_(type.precision).must_equal
|
|
429
|
+
_(type.precision).must_equal 7
|
|
429
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
441
|
_(obj.datetimeoffset_7).must_equal time
|
|
441
442
|
obj.save!
|
|
442
443
|
_(obj.datetimeoffset_7).must_equal time
|
|
443
444
|
_(obj.reload.datetimeoffset_7).must_equal time
|
|
444
445
|
# With other precisions.
|
|
445
|
-
time = ActiveSupport::TimeZone[
|
|
446
|
-
col = column(
|
|
446
|
+
time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
|
447
|
+
col = column("datetimeoffset_3")
|
|
447
448
|
_(connection.lookup_cast_type_from_column(col).precision).must_equal 3
|
|
448
449
|
obj.datetimeoffset_3 = time
|
|
449
450
|
_(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
|
450
451
|
obj.save!
|
|
451
452
|
_(obj.datetimeoffset_3).must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
|
452
|
-
col = column(
|
|
453
|
+
col = column("datetime2_1")
|
|
453
454
|
_(connection.lookup_cast_type_from_column(col).precision).must_equal 1
|
|
454
455
|
obj.datetime2_1 = time
|
|
455
456
|
_(obj.datetime2_1).must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
|
@@ -457,131 +458,131 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
457
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
|
|
461
|
+
it "smalldatetime" do
|
|
462
|
+
col = column("smalldatetime")
|
|
463
|
+
_(col.sql_type).must_equal "smalldatetime"
|
|
463
464
|
_(col.type).must_equal :smalldatetime
|
|
464
465
|
_(col.null).must_equal true
|
|
465
466
|
_(col.default).must_equal Time.utc(1901, 01, 01, 15, 45, 00, 000)
|
|
466
467
|
_(obj.smalldatetime).must_equal Time.utc(1901, 01, 01, 15, 45, 00, 000)
|
|
467
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).must_be_instance_of Type::SmallDateTime
|
|
470
471
|
_(type.limit).must_be_nil
|
|
471
472
|
_(type.precision).must_be_nil
|
|
472
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
|
+
_(obj.smalldatetime).must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
|
480
481
|
end
|
|
481
482
|
|
|
482
|
-
it
|
|
483
|
-
skip
|
|
484
|
-
col = column(
|
|
485
|
-
_(col.sql_type).must_equal
|
|
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)"
|
|
486
487
|
_(col.type).must_equal :time
|
|
487
488
|
_(col.null).must_equal true
|
|
488
489
|
_(col.default).must_equal Time.utc(1900, 01, 01, 04, 20, 00, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
|
|
489
490
|
_(col.default_function).must_be_nil
|
|
490
491
|
type = connection.lookup_cast_type_from_column(col)
|
|
491
|
-
_(type).must_be_instance_of
|
|
492
|
+
_(type).must_be_instance_of Type::Time
|
|
492
493
|
_(type.limit).must_be_nil
|
|
493
|
-
_(type.precision).must_equal
|
|
494
|
+
_(type.precision).must_equal 7
|
|
494
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
498
|
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
|
498
499
|
_(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.save!; obj.reload
|
|
500
501
|
_(obj.time_7).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
|
501
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
|
|
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>"
|
|
512
513
|
end
|
|
513
514
|
|
|
514
|
-
it
|
|
515
|
-
skip
|
|
516
|
-
col = column(
|
|
517
|
-
_(col.sql_type).must_equal
|
|
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)"
|
|
518
519
|
_(col.type).must_equal :time
|
|
519
520
|
_(col.null).must_equal true
|
|
520
521
|
_(col.default).must_be_nil
|
|
521
522
|
_(col.default_function).must_be_nil
|
|
522
523
|
type = connection.lookup_cast_type_from_column(col)
|
|
523
|
-
_(type).must_be_instance_of
|
|
524
|
+
_(type).must_be_instance_of Type::Time
|
|
524
525
|
_(type.limit).must_be_nil
|
|
525
|
-
_(type.precision).must_equal
|
|
526
|
+
_(type.precision).must_equal 2
|
|
526
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>"
|
|
542
543
|
end
|
|
543
544
|
|
|
544
|
-
it
|
|
545
|
-
skip
|
|
546
|
-
col = column(
|
|
547
|
-
_(col.sql_type).must_equal
|
|
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)"
|
|
548
549
|
_(col.type).must_equal :time
|
|
549
550
|
_(col.null).must_equal true
|
|
550
551
|
_(col.default).must_equal Time.utc(1900, 01, 01, 15, 03, 42, Rational(62197800, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <62197800>"
|
|
551
552
|
_(col.default_function).must_be_nil
|
|
552
553
|
type = connection.lookup_cast_type_from_column(col)
|
|
553
|
-
_(type).must_be_instance_of
|
|
554
|
+
_(type).must_be_instance_of Type::Time
|
|
554
555
|
_(type.limit).must_be_nil
|
|
555
|
-
_(type.precision).must_equal
|
|
556
|
+
_(type.precision).must_equal 7
|
|
556
557
|
_(type.scale).must_be_nil
|
|
557
558
|
# Time's #usec precision (low micro)
|
|
558
559
|
obj.time_default = Time.utc(2000, 01, 01, 15, 45, 00, 300)
|
|
559
560
|
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
|
|
560
561
|
_(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
|
|
562
|
+
obj.save!; obj.reload
|
|
562
563
|
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_default.usec}> vs <0>"
|
|
563
564
|
_(obj.time_default).must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Nanoseconds were <#{obj.time_default.nsec}> vs <300>"
|
|
564
565
|
# Time's #usec precision (high micro)
|
|
565
566
|
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
|
|
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>"
|
|
569
570
|
# Time's #usec precision (high nano rounded)
|
|
570
571
|
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
|
|
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>"
|
|
574
575
|
end
|
|
575
576
|
|
|
576
577
|
# Character Strings
|
|
577
578
|
|
|
578
|
-
it
|
|
579
|
-
col = column(
|
|
580
|
-
_(col.sql_type).must_equal
|
|
579
|
+
it "char(10)" do
|
|
580
|
+
col = column("char_10")
|
|
581
|
+
_(col.sql_type).must_equal "char(10)"
|
|
581
582
|
_(col.type).must_equal :char
|
|
582
583
|
_(col.null).must_equal true
|
|
583
|
-
_(col.default).must_equal
|
|
584
|
-
_(obj.char_10).must_equal
|
|
584
|
+
_(col.default).must_equal "1234567890"
|
|
585
|
+
_(obj.char_10).must_equal "1234567890"
|
|
585
586
|
_(col.default_function).must_be_nil
|
|
586
587
|
type = connection.lookup_cast_type_from_column(col)
|
|
587
588
|
_(type).must_be_instance_of Type::Char
|
|
@@ -589,19 +590,19 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
589
590
|
_(type.precision).must_be_nil
|
|
590
591
|
_(type.scale).must_be_nil
|
|
591
592
|
# Basic set and save.
|
|
592
|
-
obj.char_10 =
|
|
593
|
-
_(obj.char_10.strip).must_equal
|
|
593
|
+
obj.char_10 = "012345"
|
|
594
|
+
_(obj.char_10.strip).must_equal "012345"
|
|
594
595
|
obj.save!
|
|
595
|
-
_(obj.reload.char_10.strip).must_equal
|
|
596
|
+
_(obj.reload.char_10.strip).must_equal "012345"
|
|
596
597
|
end
|
|
597
598
|
|
|
598
|
-
it
|
|
599
|
-
col = column(
|
|
600
|
-
_(col.sql_type).must_equal
|
|
599
|
+
it "varchar(50)" do
|
|
600
|
+
col = column("varchar_50")
|
|
601
|
+
_(col.sql_type).must_equal "varchar(50)"
|
|
601
602
|
_(col.type).must_equal :varchar
|
|
602
603
|
_(col.null).must_equal true
|
|
603
|
-
_(col.default).must_equal
|
|
604
|
-
_(obj.varchar_50).must_equal
|
|
604
|
+
_(col.default).must_equal "test varchar_50"
|
|
605
|
+
_(obj.varchar_50).must_equal "test varchar_50"
|
|
605
606
|
_(col.default_function).must_be_nil
|
|
606
607
|
type = connection.lookup_cast_type_from_column(col)
|
|
607
608
|
_(type).must_be_instance_of Type::Varchar
|
|
@@ -609,16 +610,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
609
610
|
_(type.precision).must_be_nil
|
|
610
611
|
_(type.scale).must_be_nil
|
|
611
612
|
# Basic set and save.
|
|
612
|
-
assert_obj_set_and_save :varchar_50,
|
|
613
|
+
assert_obj_set_and_save :varchar_50, "Hello World"
|
|
613
614
|
end
|
|
614
615
|
|
|
615
|
-
it
|
|
616
|
-
col = column(
|
|
617
|
-
_(col.sql_type).must_equal
|
|
616
|
+
it "varchar(max)" do
|
|
617
|
+
col = column("varchar_max")
|
|
618
|
+
_(col.sql_type).must_equal "varchar(max)"
|
|
618
619
|
_(col.type).must_equal :varchar_max
|
|
619
620
|
_(col.null).must_equal true
|
|
620
|
-
_(col.default).must_equal
|
|
621
|
-
_(obj.varchar_max).must_equal
|
|
621
|
+
_(col.default).must_equal "test varchar_max"
|
|
622
|
+
_(obj.varchar_max).must_equal "test varchar_max"
|
|
622
623
|
_(col.default_function).must_be_nil
|
|
623
624
|
type = connection.lookup_cast_type_from_column(col)
|
|
624
625
|
_(type).must_be_instance_of Type::VarcharMax
|
|
@@ -626,16 +627,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
626
627
|
_(type.precision).must_be_nil
|
|
627
628
|
_(type.scale).must_be_nil
|
|
628
629
|
# Basic set and save.
|
|
629
|
-
assert_obj_set_and_save :varchar_max,
|
|
630
|
+
assert_obj_set_and_save :varchar_max, "Hello World"
|
|
630
631
|
end
|
|
631
632
|
|
|
632
|
-
it
|
|
633
|
-
col = column(
|
|
634
|
-
_(col.sql_type).must_equal
|
|
633
|
+
it "text" do
|
|
634
|
+
col = column("text")
|
|
635
|
+
_(col.sql_type).must_equal "text"
|
|
635
636
|
_(col.type).must_equal :text_basic
|
|
636
637
|
_(col.null).must_equal true
|
|
637
|
-
_(col.default).must_equal
|
|
638
|
-
_(obj.text).must_equal
|
|
638
|
+
_(col.default).must_equal "test text"
|
|
639
|
+
_(obj.text).must_equal "test text"
|
|
639
640
|
_(col.default_function).must_be_nil
|
|
640
641
|
type = connection.lookup_cast_type_from_column(col)
|
|
641
642
|
_(type).must_be_instance_of Type::Text
|
|
@@ -643,18 +644,18 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
643
644
|
_(type.precision).must_be_nil
|
|
644
645
|
_(type.scale).must_be_nil
|
|
645
646
|
# Basic set and save.
|
|
646
|
-
assert_obj_set_and_save :text,
|
|
647
|
+
assert_obj_set_and_save :text, "Hello World"
|
|
647
648
|
end
|
|
648
649
|
|
|
649
650
|
# Unicode Character Strings
|
|
650
651
|
|
|
651
|
-
it
|
|
652
|
-
col = column(
|
|
653
|
-
_(col.sql_type).must_equal
|
|
652
|
+
it "nchar(10)" do
|
|
653
|
+
col = column("nchar_10")
|
|
654
|
+
_(col.sql_type).must_equal "nchar(10)"
|
|
654
655
|
_(col.type).must_equal :nchar
|
|
655
656
|
_(col.null).must_equal true
|
|
656
|
-
_(col.default).must_equal
|
|
657
|
-
_(obj.nchar_10).must_equal
|
|
657
|
+
_(col.default).must_equal "12345678åå"
|
|
658
|
+
_(obj.nchar_10).must_equal "12345678åå"
|
|
658
659
|
_(col.default_function).must_be_nil
|
|
659
660
|
type = connection.lookup_cast_type_from_column(col)
|
|
660
661
|
_(type).must_be_instance_of Type::UnicodeChar
|
|
@@ -663,18 +664,18 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
663
664
|
_(type.scale).must_be_nil
|
|
664
665
|
# Basic set and save.
|
|
665
666
|
obj.nchar_10 = "五六"
|
|
666
|
-
_(obj.nchar_10.strip).must_equal
|
|
667
|
+
_(obj.nchar_10.strip).must_equal "五六"
|
|
667
668
|
obj.save!
|
|
668
|
-
_(obj.reload.nchar_10.strip).must_equal
|
|
669
|
+
_(obj.reload.nchar_10.strip).must_equal "五六"
|
|
669
670
|
end
|
|
670
671
|
|
|
671
|
-
it
|
|
672
|
-
col = column(
|
|
673
|
-
_(col.sql_type).must_equal
|
|
672
|
+
it "nvarchar(50)" do
|
|
673
|
+
col = column("nvarchar_50")
|
|
674
|
+
_(col.sql_type).must_equal "nvarchar(50)"
|
|
674
675
|
_(col.type).must_equal :string
|
|
675
676
|
_(col.null).must_equal true
|
|
676
|
-
_(col.default).must_equal
|
|
677
|
-
_(obj.nvarchar_50).must_equal
|
|
677
|
+
_(col.default).must_equal "test nvarchar_50 åå"
|
|
678
|
+
_(obj.nvarchar_50).must_equal "test nvarchar_50 åå"
|
|
678
679
|
_(col.default_function).must_be_nil
|
|
679
680
|
type = connection.lookup_cast_type_from_column(col)
|
|
680
681
|
_(type).must_be_instance_of Type::UnicodeVarchar
|
|
@@ -685,13 +686,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
685
686
|
assert_obj_set_and_save :nvarchar_50, "一二34五六"
|
|
686
687
|
end
|
|
687
688
|
|
|
688
|
-
it
|
|
689
|
-
col = column(
|
|
690
|
-
_(col.sql_type).must_equal
|
|
689
|
+
it "nvarchar(max)" do
|
|
690
|
+
col = column("nvarchar_max")
|
|
691
|
+
_(col.sql_type).must_equal "nvarchar(max)"
|
|
691
692
|
_(col.type).must_equal :text
|
|
692
693
|
_(col.null).must_equal true
|
|
693
|
-
_(col.default).must_equal
|
|
694
|
-
_(obj.nvarchar_max).must_equal
|
|
694
|
+
_(col.default).must_equal "test nvarchar_max åå"
|
|
695
|
+
_(obj.nvarchar_max).must_equal "test nvarchar_max åå"
|
|
695
696
|
_(col.default_function).must_be_nil
|
|
696
697
|
type = connection.lookup_cast_type_from_column(col)
|
|
697
698
|
_(type).must_be_instance_of Type::UnicodeVarcharMax
|
|
@@ -702,13 +703,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
702
703
|
assert_obj_set_and_save :nvarchar_max, "一二34五六"
|
|
703
704
|
end
|
|
704
705
|
|
|
705
|
-
it
|
|
706
|
-
col = column(
|
|
707
|
-
_(col.sql_type).must_equal
|
|
706
|
+
it "ntext" do
|
|
707
|
+
col = column("ntext")
|
|
708
|
+
_(col.sql_type).must_equal "ntext"
|
|
708
709
|
_(col.type).must_equal :ntext
|
|
709
710
|
_(col.null).must_equal true
|
|
710
|
-
_(col.default).must_equal
|
|
711
|
-
_(obj.ntext).must_equal
|
|
711
|
+
_(col.default).must_equal "test ntext åå"
|
|
712
|
+
_(obj.ntext).must_equal "test ntext åå"
|
|
712
713
|
_(col.default_function).must_be_nil
|
|
713
714
|
type = connection.lookup_cast_type_from_column(col)
|
|
714
715
|
_(type).must_be_instance_of Type::UnicodeText
|
|
@@ -721,12 +722,12 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
721
722
|
|
|
722
723
|
# Binary Strings
|
|
723
724
|
|
|
724
|
-
let(:binary_file) { File.join ARTest::SQLServer.test_root_sqlserver,
|
|
725
|
-
let(:binary_data) { File.open(binary_file,
|
|
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 } }
|
|
726
727
|
|
|
727
|
-
it
|
|
728
|
-
col = column(
|
|
729
|
-
_(col.sql_type).must_equal
|
|
728
|
+
it "binary(49)" do
|
|
729
|
+
col = column("binary_49")
|
|
730
|
+
_(col.sql_type).must_equal "binary(49)"
|
|
730
731
|
_(col.type).must_equal :binary_basic
|
|
731
732
|
_(col.null).must_equal true
|
|
732
733
|
_(col.default).must_be_nil
|
|
@@ -745,9 +746,9 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
745
746
|
_(obj.reload.binary_49).must_equal binary_data
|
|
746
747
|
end
|
|
747
748
|
|
|
748
|
-
it
|
|
749
|
-
col = column(
|
|
750
|
-
_(col.sql_type).must_equal
|
|
749
|
+
it "varbinary(49)" do
|
|
750
|
+
col = column("varbinary_49")
|
|
751
|
+
_(col.sql_type).must_equal "varbinary(49)"
|
|
751
752
|
_(col.type).must_equal :varbinary
|
|
752
753
|
_(col.null).must_equal true
|
|
753
754
|
_(col.default).must_be_nil
|
|
@@ -758,17 +759,17 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
758
759
|
_(type.precision).must_be_nil
|
|
759
760
|
_(type.scale).must_be_nil
|
|
760
761
|
# Basic set and save.
|
|
761
|
-
|
|
762
|
-
_(
|
|
763
|
-
obj.varbinary_49 =
|
|
764
|
-
_(obj.varbinary_49).must_equal
|
|
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
|
|
765
766
|
obj.save!
|
|
766
|
-
_(obj.reload.varbinary_49).must_equal
|
|
767
|
+
_(obj.reload.varbinary_49).must_equal binary_data20
|
|
767
768
|
end
|
|
768
769
|
|
|
769
|
-
it
|
|
770
|
-
col = column(
|
|
771
|
-
_(col.sql_type).must_equal
|
|
770
|
+
it "varbinary(max)" do
|
|
771
|
+
col = column("varbinary_max")
|
|
772
|
+
_(col.sql_type).must_equal "varbinary(max)"
|
|
772
773
|
_(col.type).must_equal :binary
|
|
773
774
|
_(col.null).must_equal true
|
|
774
775
|
_(col.default).must_be_nil
|
|
@@ -785,57 +786,55 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
785
786
|
|
|
786
787
|
# Other Data Types
|
|
787
788
|
|
|
788
|
-
it
|
|
789
|
-
col = column(
|
|
790
|
-
_(col.sql_type).must_equal
|
|
789
|
+
it "uniqueidentifier" do
|
|
790
|
+
col = column("uniqueidentifier")
|
|
791
|
+
_(col.sql_type).must_equal "uniqueidentifier"
|
|
791
792
|
_(col.type).must_equal :uuid
|
|
792
793
|
_(col.null).must_equal true
|
|
793
794
|
_(col.default).must_be_nil
|
|
794
|
-
_(col.default_function).must_equal
|
|
795
|
+
_(col.default_function).must_equal "newid()"
|
|
795
796
|
type = connection.lookup_cast_type_from_column(col)
|
|
796
|
-
_(type).must_be_instance_of
|
|
797
|
+
_(type).must_be_instance_of Type::Uuid
|
|
797
798
|
_(type.limit).must_be_nil
|
|
798
799
|
_(type.precision).must_be_nil
|
|
799
800
|
_(type.scale).must_be_nil
|
|
800
801
|
# Basic set and save.
|
|
801
802
|
obj.uniqueidentifier = "this will not qualify as valid"
|
|
802
803
|
_(obj.uniqueidentifier).must_be_nil
|
|
803
|
-
obj.save
|
|
804
|
-
_(obj.uniqueidentifier).must_match
|
|
804
|
+
obj.save!; obj.reload
|
|
805
|
+
_(obj.uniqueidentifier).must_match Type::Uuid::ACCEPTABLE_UUID
|
|
805
806
|
obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
|
806
|
-
_(obj.uniqueidentifier).must_equal
|
|
807
|
-
obj.save
|
|
808
|
-
_(obj.uniqueidentifier).must_equal
|
|
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"
|
|
809
810
|
end
|
|
810
811
|
|
|
811
|
-
it
|
|
812
|
-
col = column(
|
|
813
|
-
_(col.sql_type).must_equal
|
|
812
|
+
it "timestamp" do
|
|
813
|
+
col = column("timestamp")
|
|
814
|
+
_(col.sql_type).must_equal "timestamp"
|
|
814
815
|
_(col.type).must_equal :ss_timestamp
|
|
815
816
|
_(col.null).must_equal true
|
|
816
817
|
_(col.default).must_be_nil
|
|
817
818
|
_(col.default_function).must_be_nil
|
|
818
819
|
type = connection.lookup_cast_type_from_column(col)
|
|
819
|
-
_(type).must_be_instance_of
|
|
820
|
+
_(type).must_be_instance_of Type::Timestamp
|
|
820
821
|
_(type.limit).must_be_nil
|
|
821
822
|
_(type.precision).must_be_nil
|
|
822
823
|
_(type.scale).must_be_nil
|
|
823
824
|
# Basic read.
|
|
824
825
|
_(obj.timestamp).must_be_nil
|
|
825
|
-
obj.save
|
|
826
|
-
_(obj.timestamp).must_match
|
|
826
|
+
obj.save!; obj.reload
|
|
827
|
+
_(obj.timestamp).must_match %r|\000|
|
|
827
828
|
obj.timestamp
|
|
828
829
|
# Can set another attribute
|
|
829
830
|
obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
|
830
831
|
obj.save!
|
|
831
832
|
end
|
|
832
833
|
|
|
833
|
-
it
|
|
834
|
+
it "does not mark object as changed after save" do
|
|
834
835
|
obj.save!
|
|
835
836
|
obj.attributes
|
|
836
837
|
_(obj.changed?).must_equal false
|
|
837
838
|
end
|
|
838
|
-
|
|
839
839
|
end
|
|
840
|
-
|
|
841
840
|
end
|