activerecord-sqlserver-adapter 5.2.1 → 7.0.0.0

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