Skip to content

Commit 86a29bf

Browse files
committed
Changing a few tests to harden things up.
1 parent e356aa5 commit 86a29bf

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

test/cases/column_test_sqlserver.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ def assert_obj_set_and_save(attribute, value)
282282
type.precision.must_equal nil
283283
type.scale.must_equal nil
284284
# Can cast strings.
285-
obj.date = '0001-01-01'
286-
obj.date.must_equal Date.civil(0001, 1, 1)
285+
obj.date = '0001-04-01'
286+
obj.date.must_equal Date.civil(0001, 4, 1)
287287
obj.save!
288-
obj.date.must_equal Date.civil(0001, 1, 1)
288+
obj.date.must_equal Date.civil(0001, 4, 1)
289289
obj.reload
290-
obj.date.must_equal Date.civil(0001, 1, 1)
290+
obj.date.must_equal Date.civil(0001, 4, 1)
291291
# Can keep and return assigned date.
292292
assert_obj_set_and_save :date, Date.civil(1972, 04, 14)
293293
# Can accept and cast time objects.
@@ -311,17 +311,17 @@ def assert_obj_set_and_save(attribute, value)
311311
type.precision.must_equal nil
312312
type.scale.must_equal nil
313313
# Can save to proper accuracy and return again.
314-
obj.datetime = Time.utc(2010, 01, 01, 12, 34, 56, 3000)
315-
obj.datetime.must_equal Time.utc(2010, 01, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.datetime.usec}> vs <3000>"
314+
obj.datetime = Time.utc(2010, 04, 01, 12, 34, 56, 3000)
315+
obj.datetime.must_equal Time.utc(2010, 04, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.datetime.usec}> vs <3000>"
316316
obj.save!
317-
obj.datetime.must_equal Time.utc(2010, 01, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.reload.datetime.usec}> vs <3000>"
317+
obj.datetime.must_equal Time.utc(2010, 04, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.reload.datetime.usec}> vs <3000>"
318318
obj.reload
319-
obj.datetime.must_equal Time.utc(2010, 01, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.reload.datetime.usec}> vs <3000>"
319+
obj.datetime.must_equal Time.utc(2010, 04, 01, 12, 34, 56, 3000), "Microseconds were <#{obj.reload.datetime.usec}> vs <3000>"
320320
# Will cast to true DB value on attribute write, save and return again.
321-
obj.datetime = Time.utc(2010, 01, 01, 12, 34, 56, 234567)
322-
obj.datetime.must_equal Time.utc(2010, 01, 01, 12, 34, 56, 233000), "Microseconds were <#{obj.datetime.usec}> vs <233000>"
321+
obj.datetime = Time.utc(2010, 04, 01, 12, 34, 56, 234567)
322+
obj.datetime.must_equal Time.utc(2010, 04, 01, 12, 34, 56, 233000), "Microseconds were <#{obj.datetime.usec}> vs <233000>"
323323
obj.save!
324-
obj.reload.datetime.must_equal Time.utc(2010, 01, 01, 12, 34, 56, 233000), "Microseconds were <#{obj.reload.datetime.usec}> vs <233000>"
324+
obj.reload.datetime.must_equal Time.utc(2010, 04, 01, 12, 34, 56, 233000), "Microseconds were <#{obj.reload.datetime.usec}> vs <233000>"
325325
end
326326

327327
it 'datetime2' do
@@ -388,20 +388,19 @@ def assert_obj_set_and_save(attribute, value)
388388
type.precision.must_equal 7
389389
type.scale.must_equal nil
390390
# Can save 100 nanosecond precisoins and return again.
391-
obj.datetimeoffset_7 = Time.new(2010, 01, 01, 12, 34, 56, +18000).change(nsec: 123456755)
392-
obj.datetimeoffset_7.must_equal Time.new(2010, 01, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
391+
obj.datetimeoffset_7 = Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456755)
392+
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>"
393393
obj.save!
394-
obj.datetimeoffset_7.must_equal Time.new(2010, 01, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
394+
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>"
395395
obj.reload
396-
obj.datetimeoffset_7.must_equal Time.new(2010, 01, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
396+
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>"
397397
# With other precisions.
398398
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
399399
col = column('datetimeoffset_3')
400400
connection.lookup_cast_type_from_column(col).precision.must_equal 3
401401
obj.datetimeoffset_3 = time
402402
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
403403
# TODO: FreeTDS date bug fixed: https://github.com/FreeTDS/freetds/issues/44
404-
return
405404
obj.save! ; obj.reload
406405
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
407406
col = column('datetime2_1')

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
99

1010
it 'sst_datatypes' do
1111
generate_schema_for_table 'sst_datatypes'
12-
# Exact Numerics
1312
assert_line :bigint, type: 'bigint', limit: nil, precision: nil, scale: nil, default: 42
1413
assert_line :int, type: 'integer', limit: nil, precision: nil, scale: nil, default: 42
1514
assert_line :smallint, type: 'integer', limit: 2, precision: nil, scale: nil, default: 42
@@ -210,10 +209,20 @@ def inspect
210209

211210
def parse_line
212211
_all, type_method, col_name, options = @line.match(LINE_PARSER).to_a
213-
options = options.present? ? eval("{#{options}}") : {}
212+
options = parse_options(options)
214213
[type_method, col_name, options]
215214
end
216215

216+
def parse_options(opts)
217+
if opts.present?
218+
eval "{#{opts}}"
219+
else
220+
{}
221+
end
222+
rescue SyntaxError
223+
{}
224+
end
225+
217226
end
218227

219228
end

0 commit comments

Comments
 (0)