@@ -47,20 +47,21 @@ def mock_check_constraint(name, expression)
4747 expression : expression )
4848 end
4949
50- def mock_connection ( indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] )
50+ def mock_connection ( table_comment , indexes = [ ] , foreign_keys = [ ] , check_constraints = [ ] )
5151 double ( 'Conn' ,
5252 indexes : indexes ,
5353 foreign_keys : foreign_keys ,
5454 check_constraints : check_constraints ,
5555 supports_foreign_keys? : true ,
5656 supports_check_constraints? : true ,
57- table_exists? : true )
57+ table_exists? : true ,
58+ table_comment : table_comment )
5859 end
5960
6061 # 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 : { } )
6263 options = {
63- connection : mock_connection ( indexes , foreign_keys , check_constraints ) ,
64+ connection : mock_connection ( table_comments [ table_name ] , indexes , foreign_keys , check_constraints ) ,
6465 table_exists? : true ,
6566 table_name : table_name ,
6667 primary_key : primary_key ,
@@ -1205,6 +1206,41 @@ def mock_column(name, type, options = {})
12051206 end
12061207 end
12071208
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+
12081244 context 'when columns have multibyte comments' do
12091245 let :columns do
12101246 [
0 commit comments