@@ -1344,6 +1344,146 @@ def mock_column(name, type, options = {})
1344
1344
end
1345
1345
end
1346
1346
end
1347
+
1348
+ context 'when "with_comment_column" is specified in options' do
1349
+ let :options do
1350
+ { with_comment_column : 'yes' }
1351
+ end
1352
+
1353
+ context 'when columns have comments' do
1354
+ let :columns do
1355
+ [
1356
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1357
+ mock_column ( :active , :boolean , limit : 1 , comment : 'Active' ) ,
1358
+ mock_column ( :name , :string , limit : 50 , comment : 'Name' ) ,
1359
+ mock_column ( :notes , :text , limit : 55 , comment : 'Notes' ) ,
1360
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil )
1361
+ ]
1362
+ end
1363
+
1364
+ let :expected_result do
1365
+ <<~EOS
1366
+ # Schema Info
1367
+ #
1368
+ # Table name: users
1369
+ #
1370
+ # id :integer not null, primary key ID
1371
+ # active :boolean not null Active
1372
+ # name :string(50) not null Name
1373
+ # notes :text(55) not null Notes
1374
+ # no_comment :text(20) not null
1375
+ #
1376
+ EOS
1377
+ end
1378
+
1379
+ it 'works with option "with_comment_column"' do
1380
+ is_expected . to eq expected_result
1381
+ end
1382
+ end
1383
+
1384
+ context 'when columns have multibyte comments' do
1385
+ let :columns do
1386
+ [
1387
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1388
+ mock_column ( :active , :boolean , limit : 1 , comment : 'ACTIVE' ) ,
1389
+ mock_column ( :name , :string , limit : 50 , comment : 'NAME' ) ,
1390
+ mock_column ( :notes , :text , limit : 55 , comment : 'NOTES' ) ,
1391
+ mock_column ( :cyrillic , :text , limit : 30 , comment : 'Кириллица' ) ,
1392
+ mock_column ( :japanese , :text , limit : 60 , comment : '熊本大学 イタリア 宝島' ) ,
1393
+ mock_column ( :arabic , :text , limit : 20 , comment : 'لغة' ) ,
1394
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil ) ,
1395
+ mock_column ( :location , :geometry_collection , limit : nil , comment : nil )
1396
+ ]
1397
+ end
1398
+
1399
+ let :expected_result do
1400
+ <<~EOS
1401
+ # Schema Info
1402
+ #
1403
+ # Table name: users
1404
+ #
1405
+ # id :integer not null, primary key ID
1406
+ # active :boolean not null ACTIVE
1407
+ # name :string(50) not null NAME
1408
+ # notes :text(55) not null NOTES
1409
+ # cyrillic :text(30) not null Кириллица
1410
+ # japanese :text(60) not null 熊本大学 イタリア 宝島
1411
+ # arabic :text(20) not null لغة
1412
+ # no_comment :text(20) not null
1413
+ # location :geometry_collect not null
1414
+ #
1415
+ EOS
1416
+ end
1417
+
1418
+ it 'works with option "with_comment_column"' do
1419
+ is_expected . to eq expected_result
1420
+ end
1421
+ end
1422
+
1423
+ context 'when columns have multiline comments' do
1424
+ let :columns do
1425
+ [
1426
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1427
+ mock_column ( :notes , :text , limit : 55 , comment : "Notes.\n May include things like notes." ) ,
1428
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil )
1429
+ ]
1430
+ end
1431
+
1432
+ let :expected_result do
1433
+ <<~EOS
1434
+ # Schema Info
1435
+ #
1436
+ # Table name: users
1437
+ #
1438
+ # id :integer not null, primary key ID
1439
+ # notes :text(55) not null Notes.\\ nMay include things like notes.
1440
+ # no_comment :text(20) not null
1441
+ #
1442
+ EOS
1443
+ end
1444
+
1445
+ it 'works with option "with_comment_column"' do
1446
+ is_expected . to eq expected_result
1447
+ end
1448
+ end
1449
+
1450
+ context 'when geometry columns are included' do
1451
+ let :columns do
1452
+ [
1453
+ mock_column ( :id , :integer , limit : 8 ) ,
1454
+ mock_column ( :active , :boolean , default : false , null : false ) ,
1455
+ mock_column ( :geometry , :geometry ,
1456
+ geometric_type : 'Geometry' , srid : 4326 ,
1457
+ limit : { srid : 4326 , type : 'geometry' } ) ,
1458
+ mock_column ( :location , :geography ,
1459
+ geometric_type : 'Point' , srid : 0 ,
1460
+ limit : { srid : 0 , type : 'geometry' } ) ,
1461
+ mock_column ( :non_srid , :geography ,
1462
+ geometric_type : 'Point' ,
1463
+ limit : { type : 'geometry' } )
1464
+ ]
1465
+ end
1466
+
1467
+ let :expected_result do
1468
+ <<~EOS
1469
+ # Schema Info
1470
+ #
1471
+ # Table name: users
1472
+ #
1473
+ # id :integer not null, primary key
1474
+ # active :boolean default(FALSE), not null
1475
+ # geometry :geometry not null, geometry, 4326
1476
+ # location :geography not null, point, 0
1477
+ # non_srid :geography not null, point
1478
+ #
1479
+ EOS
1480
+ end
1481
+
1482
+ it 'works with option "with_comment_column"' do
1483
+ is_expected . to eq expected_result
1484
+ end
1485
+ end
1486
+ end
1347
1487
end
1348
1488
end
1349
1489
end
0 commit comments