@@ -1308,6 +1308,146 @@ def mock_column(name, type, options = {})
1308
1308
end
1309
1309
end
1310
1310
end
1311
+
1312
+ context 'when "with_comment_column" is specified in options' do
1313
+ let :options do
1314
+ { with_comment_column : 'yes' }
1315
+ end
1316
+
1317
+ context 'when columns have comments' do
1318
+ let :columns do
1319
+ [
1320
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1321
+ mock_column ( :active , :boolean , limit : 1 , comment : 'Active' ) ,
1322
+ mock_column ( :name , :string , limit : 50 , comment : 'Name' ) ,
1323
+ mock_column ( :notes , :text , limit : 55 , comment : 'Notes' ) ,
1324
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil )
1325
+ ]
1326
+ end
1327
+
1328
+ let :expected_result do
1329
+ <<~EOS
1330
+ # Schema Info
1331
+ #
1332
+ # Table name: users
1333
+ #
1334
+ # id :integer not null, primary key ID
1335
+ # active :boolean not null Active
1336
+ # name :string(50) not null Name
1337
+ # notes :text(55) not null Notes
1338
+ # no_comment :text(20) not null
1339
+ #
1340
+ EOS
1341
+ end
1342
+
1343
+ it 'works with option "with_comment_column"' do
1344
+ is_expected . to eq expected_result
1345
+ end
1346
+ end
1347
+
1348
+ context 'when columns have multibyte comments' do
1349
+ let :columns do
1350
+ [
1351
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1352
+ mock_column ( :active , :boolean , limit : 1 , comment : 'ACTIVE' ) ,
1353
+ mock_column ( :name , :string , limit : 50 , comment : 'NAME' ) ,
1354
+ mock_column ( :notes , :text , limit : 55 , comment : 'NOTES' ) ,
1355
+ mock_column ( :cyrillic , :text , limit : 30 , comment : 'Кириллица' ) ,
1356
+ mock_column ( :japanese , :text , limit : 60 , comment : '熊本大学 イタリア 宝島' ) ,
1357
+ mock_column ( :arabic , :text , limit : 20 , comment : 'لغة' ) ,
1358
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil ) ,
1359
+ mock_column ( :location , :geometry_collection , limit : nil , comment : nil )
1360
+ ]
1361
+ end
1362
+
1363
+ let :expected_result do
1364
+ <<~EOS
1365
+ # Schema Info
1366
+ #
1367
+ # Table name: users
1368
+ #
1369
+ # id :integer not null, primary key ID
1370
+ # active :boolean not null ACTIVE
1371
+ # name :string(50) not null NAME
1372
+ # notes :text(55) not null NOTES
1373
+ # cyrillic :text(30) not null Кириллица
1374
+ # japanese :text(60) not null 熊本大学 イタリア 宝島
1375
+ # arabic :text(20) not null لغة
1376
+ # no_comment :text(20) not null
1377
+ # location :geometry_collect not null
1378
+ #
1379
+ EOS
1380
+ end
1381
+
1382
+ it 'works with option "with_comment_column"' do
1383
+ is_expected . to eq expected_result
1384
+ end
1385
+ end
1386
+
1387
+ context 'when columns have multiline comments' do
1388
+ let :columns do
1389
+ [
1390
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1391
+ mock_column ( :notes , :text , limit : 55 , comment : "Notes.\n May include things like notes." ) ,
1392
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil )
1393
+ ]
1394
+ end
1395
+
1396
+ let :expected_result do
1397
+ <<~EOS
1398
+ # Schema Info
1399
+ #
1400
+ # Table name: users
1401
+ #
1402
+ # id :integer not null, primary key ID
1403
+ # notes :text(55) not null Notes.\\ nMay include things like notes.
1404
+ # no_comment :text(20) not null
1405
+ #
1406
+ EOS
1407
+ end
1408
+
1409
+ it 'works with option "with_comment_column"' do
1410
+ is_expected . to eq expected_result
1411
+ end
1412
+ end
1413
+
1414
+ context 'when geometry columns are included' do
1415
+ let :columns do
1416
+ [
1417
+ mock_column ( :id , :integer , limit : 8 ) ,
1418
+ mock_column ( :active , :boolean , default : false , null : false ) ,
1419
+ mock_column ( :geometry , :geometry ,
1420
+ geometric_type : 'Geometry' , srid : 4326 ,
1421
+ limit : { srid : 4326 , type : 'geometry' } ) ,
1422
+ mock_column ( :location , :geography ,
1423
+ geometric_type : 'Point' , srid : 0 ,
1424
+ limit : { srid : 0 , type : 'geometry' } ) ,
1425
+ mock_column ( :non_srid , :geography ,
1426
+ geometric_type : 'Point' ,
1427
+ limit : { type : 'geometry' } )
1428
+ ]
1429
+ end
1430
+
1431
+ let :expected_result do
1432
+ <<~EOS
1433
+ # Schema Info
1434
+ #
1435
+ # Table name: users
1436
+ #
1437
+ # id :integer not null, primary key
1438
+ # active :boolean default(FALSE), not null
1439
+ # geometry :geometry not null, geometry, 4326
1440
+ # location :geography not null, point, 0
1441
+ # non_srid :geography not null, point
1442
+ #
1443
+ EOS
1444
+ end
1445
+
1446
+ it 'works with option "with_comment_column"' do
1447
+ is_expected . to eq expected_result
1448
+ end
1449
+ end
1450
+ end
1311
1451
end
1312
1452
end
1313
1453
end
0 commit comments