@@ -318,45 +318,6 @@ def mock_column(name, type, options = {})
318
318
expect ( AnnotateModels . get_schema_info ( klass , 'Schema Info' ) ) . to eql ( expected_result )
319
319
end
320
320
321
- it 'should get foreign key info' do
322
- klass = mock_class ( :users ,
323
- :id ,
324
- [
325
- mock_column ( :id , :integer ) ,
326
- mock_column ( :foreign_thing_id , :integer )
327
- ] ,
328
- [ ] ,
329
- [
330
- mock_foreign_key ( 'fk_rails_cf2568e89e' ,
331
- 'foreign_thing_id' ,
332
- 'foreign_things' ) ,
333
- mock_foreign_key ( 'custom_fk_name' ,
334
- 'other_thing_id' ,
335
- 'other_things' ) ,
336
- mock_foreign_key ( 'fk_rails_a70234b26c' ,
337
- 'third_thing_id' ,
338
- 'third_things' )
339
- ] )
340
-
341
- expected_result = <<~EOS
342
- # Schema Info
343
- #
344
- # Table name: users
345
- #
346
- # id :integer not null, primary key
347
- # foreign_thing_id :integer not null
348
- #
349
- # Foreign Keys
350
- #
351
- # custom_fk_name (other_thing_id => other_things.id)
352
- # fk_rails_... (foreign_thing_id => foreign_things.id)
353
- # fk_rails_... (third_thing_id => third_things.id)
354
- #
355
- EOS
356
-
357
- expect ( AnnotateModels . get_schema_info ( klass , 'Schema Info' , show_foreign_keys : true ) ) . to eql ( expected_result )
358
- end
359
-
360
321
it 'should get indexes keys' do
361
322
klass = mock_class ( :users ,
362
323
:id ,
@@ -562,6 +523,45 @@ def mock_column(name, type, options = {})
562
523
expect ( AnnotateModels . get_schema_info ( klass , 'Schema Info' , show_indexes : true ) ) . to eql ( expected_result )
563
524
end
564
525
526
+ it 'should get foreign key info' do
527
+ klass = mock_class ( :users ,
528
+ :id ,
529
+ [
530
+ mock_column ( :id , :integer ) ,
531
+ mock_column ( :foreign_thing_id , :integer )
532
+ ] ,
533
+ [ ] ,
534
+ [
535
+ mock_foreign_key ( 'fk_rails_cf2568e89e' ,
536
+ 'foreign_thing_id' ,
537
+ 'foreign_things' ) ,
538
+ mock_foreign_key ( 'custom_fk_name' ,
539
+ 'other_thing_id' ,
540
+ 'other_things' ) ,
541
+ mock_foreign_key ( 'fk_rails_a70234b26c' ,
542
+ 'third_thing_id' ,
543
+ 'third_things' )
544
+ ] )
545
+
546
+ expected_result = <<~EOS
547
+ # Schema Info
548
+ #
549
+ # Table name: users
550
+ #
551
+ # id :integer not null, primary key
552
+ # foreign_thing_id :integer not null
553
+ #
554
+ # Foreign Keys
555
+ #
556
+ # custom_fk_name (other_thing_id => other_things.id)
557
+ # fk_rails_... (foreign_thing_id => foreign_things.id)
558
+ # fk_rails_... (third_thing_id => third_things.id)
559
+ #
560
+ EOS
561
+
562
+ expect ( AnnotateModels . get_schema_info ( klass , 'Schema Info' , show_foreign_keys : true ) ) . to eql ( expected_result )
563
+ end
564
+
565
565
it 'should get foreign key info if on_delete/on_update options present' do
566
566
klass = mock_class ( :users ,
567
567
:id ,
0 commit comments