@@ -47,20 +47,21 @@ def mock_check_constraint(name, expression)
47
47
expression : expression )
48
48
end
49
49
50
- def mock_connection ( indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] )
50
+ def mock_connection ( table_comment , indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] )
51
51
double ( 'Conn' ,
52
52
indexes : indexes ,
53
53
foreign_keys : foreign_keys ,
54
54
check_constraints : check_constraints ,
55
55
supports_foreign_keys? : true ,
56
56
supports_check_constraints? : true ,
57
- table_exists? : true )
57
+ table_exists? : true ,
58
+ table_comment : table_comment )
58
59
end
59
60
60
61
# rubocop:disable Metrics/ParameterLists
61
- def mock_class ( table_name , primary_key , columns , indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] )
62
+ def mock_class ( table_name , primary_key , columns , indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] , table_comments : { } )
62
63
options = {
63
- connection : mock_connection ( indexes , foreign_keys , check_constraints ) ,
64
+ connection : mock_connection ( table_comments [ table_name ] , indexes , foreign_keys , check_constraints ) ,
64
65
table_exists? : true ,
65
66
table_name : table_name ,
66
67
primary_key : primary_key ,
@@ -1205,6 +1206,41 @@ def mock_column(name, type, options = {})
1205
1206
end
1206
1207
end
1207
1208
1209
+ context 'when table have comment' do
1210
+ let :klass do
1211
+ mock_class ( :users , primary_key , columns , indexes , foreign_keys , check_constraints , table_comments : { users : 'Users' } )
1212
+ end
1213
+
1214
+ let :columns do
1215
+ [
1216
+ mock_column ( :id , :integer , limit : 8 , comment : 'ID' ) ,
1217
+ mock_column ( :active , :boolean , limit : 1 , comment : 'Active' ) ,
1218
+ mock_column ( :name , :string , limit : 50 , comment : 'Name' ) ,
1219
+ mock_column ( :notes , :text , limit : 55 , comment : 'Notes' ) ,
1220
+ mock_column ( :no_comment , :text , limit : 20 , comment : nil )
1221
+ ]
1222
+ end
1223
+
1224
+ let :expected_result do
1225
+ <<~EOS
1226
+ # Schema Info
1227
+ #
1228
+ # Table name: users(Users)
1229
+ #
1230
+ # id(ID) :integer not null, primary key
1231
+ # active(Active) :boolean not null
1232
+ # name(Name) :string(50) not null
1233
+ # notes(Notes) :text(55) not null
1234
+ # no_comment :text(20) not null
1235
+ #
1236
+ EOS
1237
+ end
1238
+
1239
+ it 'returns schema info in Markdown format' do
1240
+ is_expected . to eq expected_result
1241
+ end
1242
+ end
1243
+
1208
1244
context 'when columns have multibyte comments' do
1209
1245
let :columns do
1210
1246
[
0 commit comments