Skip to content

Commit 7adc813

Browse files
committed
minor cleanup + update for simple tests, make sure index name <= 30 chars
1 parent dc4611b commit 7adc813

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

test/db/oracle/simple_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def test_insert_returns_id
1515
end
1616

1717
def test_default_id_type_is_integer
18+
user = User.create! :login => 'id_type'
19+
Entry.create! :title => 'first', :user_id => user.id
1820
assert Integer === Entry.first.id
1921
end
2022

test/simple.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_save_time_with_utc
289289

290290
def test_save_time_with_zone
291291
t = Time.now
292-
#precision will only be expected to the second.
292+
# precision will only be expected to the second :
293293
original_time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
294294
time = original_time.in_time_zone
295295
e = DbType.first
@@ -302,7 +302,7 @@ def test_save_time_with_zone
302302

303303
def test_save_date_time
304304
t = Time.now
305-
#precision will only be expected to the second.
305+
# precision will only be expected to the second :
306306
time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
307307
datetime = time.to_datetime
308308
e = DbType.first
@@ -360,64 +360,65 @@ def test_save_float
360360
e.save!
361361

362362
e = DbType.first
363-
assert_equal(12.0, e.sample_float)
363+
assert_equal 12.0, e.sample_float
364364
end
365-
365+
366366
def test_boolean
367-
# An unset boolean should default to nil
368367
e = DbType.first
369-
assert_equal(nil, e.sample_boolean)
368+
assert_nil e.sample_boolean # unset boolean should default to nil
370369

370+
e.update_attributes :sample_boolean => false
371+
372+
e = DbType.first
373+
assert_equal false, e.sample_boolean
374+
371375
e.sample_boolean = true
372376
e.save!
373377

374378
e = DbType.first
375-
assert_equal(true, e.sample_boolean)
379+
assert_equal true, e.sample_boolean
376380
end
377381

378382
def test_integer
379-
# An unset boolean should default to nil
380383
e = DbType.first
381-
assert_equal(nil, e.sample_integer)
384+
assert_nil e.sample_integer
382385

383386
e.sample_integer = 10
384387
e.save!
385388

386389
e = DbType.first
387-
assert_equal(10, e.sample_integer)
390+
assert_equal 10, e.sample_integer
388391
end
389392

390393
def test_text
391-
# An unset boolean should default to nil
392394
e = DbType.first
393-
394395
assert_null_text e.sample_text
395396

396397
e.sample_text = "ooop?"
397398
e.save!
398399

399400
e = DbType.first
400-
assert_equal("ooop?", e.sample_text)
401+
assert_equal "ooop?", e.sample_text
401402
end
402403

403404
def test_string
404405
e = DbType.first
405-
406406
assert_empty_string e.sample_string
407407

408408
e.sample_string = "ooop?"
409409
e.save!
410410

411411
e = DbType.first
412-
assert_equal("ooop?", e.sample_string)
412+
assert_equal "ooop?", e.sample_string
413413
end
414414

415415
def test_save_binary
416-
#string is 60_000 bytes
416+
# string is 60_000 bytes
417417
binary_string = "\000ABCDEFGHIJKLMNOPQRSTUVWXYZ'\001\003" * 1 # 2_000
418418
e = DbType.first
419419
e.sample_binary = binary_string
420420
e.save!
421+
421422
e = DbType.first
422423
assert_equal binary_string, e.sample_binary
423424
end
@@ -456,8 +457,9 @@ def test_indexes
456457
indexes = connection.indexes(:entries)
457458
assert_equal 0, indexes.size
458459

459-
connection.add_index :entries, :updated_on, :name => "entries_updated_index"
460-
connection.add_index :entries, [ :title, :user_id ], :unique => true
460+
connection.add_index :entries, :updated_on
461+
connection.add_index :entries, [ :title, :user_id ], :unique => true,
462+
:name => 'x_entries_on_title_and_user_id' # <= 30 chars
461463

462464
indexes = connection.indexes(:entries)
463465
assert_equal 2, indexes.size
@@ -471,11 +473,11 @@ def test_indexes
471473
updated_index = (indexes - [ title_index ]).first
472474

473475
assert_equal "entries", updated_index.table.to_s
474-
assert_equal "entries_updated_index", updated_index.name
476+
assert_equal "index_entries_on_updated_on", updated_index.name
475477
assert ! updated_index.unique
476478
assert_equal [ 'updated_on' ], updated_index.columns
477479

478-
connection.remove_index :entries, :name => "entries_updated_index"
480+
connection.remove_index :entries, :updated_on
479481
indexes = connection.indexes(:entries)
480482
assert_equal 1, indexes.size
481483
end

0 commit comments

Comments
 (0)