Skip to content

Commit ecb2a0b

Browse files
committed
Move test cases when "with_comment" is specified in options
1 parent bdaa07b commit ecb2a0b

File tree

1 file changed

+111
-119
lines changed

1 file changed

+111
-119
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 111 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,117 @@ def mock_column(name, type, options = {})
10511051
end
10521052
end
10531053
end
1054+
1055+
context 'when "with_comment" is specified in options' do
1056+
context 'when "with_comment" is "yes"' do
1057+
let :options do
1058+
{ with_comment: 'yes' }
1059+
end
1060+
1061+
context 'when columns have comments' do
1062+
let :columns do
1063+
[
1064+
mock_column(:id, :integer, limit: 8, comment: 'ID'),
1065+
mock_column(:active, :boolean, limit: 1, comment: 'Active'),
1066+
mock_column(:name, :string, limit: 50, comment: 'Name'),
1067+
mock_column(:notes, :text, limit: 55, comment: 'Notes'),
1068+
mock_column(:no_comment, :text, limit: 20, comment: nil)
1069+
]
1070+
end
1071+
1072+
let :expected_result do
1073+
<<~EOS
1074+
# Schema Info
1075+
#
1076+
# Table name: users
1077+
#
1078+
# id(ID) :integer not null, primary key
1079+
# active(Active) :boolean not null
1080+
# name(Name) :string(50) not null
1081+
# notes(Notes) :text(55) not null
1082+
# no_comment :text(20) not null
1083+
#
1084+
EOS
1085+
end
1086+
1087+
it 'works with option "with_comment"' do
1088+
is_expected.to eq expected_result
1089+
end
1090+
end
1091+
1092+
context 'when columns have multibyte comments' do
1093+
let :columns do
1094+
[
1095+
mock_column(:id, :integer, limit: 8, comment: 'ID'),
1096+
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
1097+
mock_column(:name, :string, limit: 50, comment: 'NAME'),
1098+
mock_column(:notes, :text, limit: 55, comment: 'NOTES'),
1099+
mock_column(:cyrillic, :text, limit: 30, comment: 'Кириллица'),
1100+
mock_column(:japanese, :text, limit: 60, comment: '熊本大学 イタリア 宝島'),
1101+
mock_column(:arabic, :text, limit: 20, comment: 'لغة'),
1102+
mock_column(:no_comment, :text, limit: 20, comment: nil),
1103+
mock_column(:location, :geometry_collection, limit: nil, comment: nil)
1104+
]
1105+
end
1106+
1107+
let :expected_result do
1108+
<<~EOS
1109+
# Schema Info
1110+
#
1111+
# Table name: users
1112+
#
1113+
# id(ID) :integer not null, primary key
1114+
# active(ACTIVE) :boolean not null
1115+
# name(NAME) :string(50) not null
1116+
# notes(NOTES) :text(55) not null
1117+
# cyrillic(Кириллица) :text(30) not null
1118+
# japanese(熊本大学 イタリア 宝島) :text(60) not null
1119+
# arabic(لغة) :text(20) not null
1120+
# no_comment :text(20) not null
1121+
# location :geometry_collect not null
1122+
#
1123+
EOS
1124+
end
1125+
1126+
it 'works with option "with_comment"' do
1127+
is_expected.to eq expected_result
1128+
end
1129+
end
1130+
1131+
context 'when geometry columns are included' do
1132+
let :columns do
1133+
[
1134+
mock_column(:id, :integer, limit: 8),
1135+
mock_column(:active, :boolean, default: false, null: false),
1136+
mock_column(:geometry, :geometry,
1137+
geometric_type: 'Geometry', srid: 4326,
1138+
limit: { srid: 4326, type: 'geometry' }),
1139+
mock_column(:location, :geography,
1140+
geometric_type: 'Point', srid: 0,
1141+
limit: { srid: 0, type: 'geometry' })
1142+
]
1143+
end
1144+
1145+
let :expected_result do
1146+
<<~EOS
1147+
# Schema Info
1148+
#
1149+
# Table name: users
1150+
#
1151+
# id :integer not null, primary key
1152+
# active :boolean default(FALSE), not null
1153+
# geometry :geometry not null, geometry, 4326
1154+
# location :geography not null, point, 0
1155+
#
1156+
EOS
1157+
end
1158+
1159+
it 'works with option "with_comment"' do
1160+
is_expected.to eq expected_result
1161+
end
1162+
end
1163+
end
1164+
end
10541165
end
10551166
end
10561167
end
@@ -1498,125 +1609,6 @@ def mock_column(name, type, options = {})
14981609
AnnotateModels.get_schema_info(klass, header, options)
14991610
end
15001611

1501-
context 'when header is "Schema Info"' do
1502-
let :header do
1503-
'Schema Info'
1504-
end
1505-
1506-
context 'with options' do
1507-
context 'when "with_comment" is specified in options' do
1508-
context 'when "with_comment" is "yes"' do
1509-
let :options do
1510-
{ with_comment: 'yes' }
1511-
end
1512-
1513-
context 'when columns have comments' do
1514-
let :columns do
1515-
[
1516-
mock_column(:id, :integer, limit: 8, comment: 'ID'),
1517-
mock_column(:active, :boolean, limit: 1, comment: 'Active'),
1518-
mock_column(:name, :string, limit: 50, comment: 'Name'),
1519-
mock_column(:notes, :text, limit: 55, comment: 'Notes'),
1520-
mock_column(:no_comment, :text, limit: 20, comment: nil)
1521-
]
1522-
end
1523-
1524-
let :expected_result do
1525-
<<~EOS
1526-
# Schema Info
1527-
#
1528-
# Table name: users
1529-
#
1530-
# id(ID) :integer not null, primary key
1531-
# active(Active) :boolean not null
1532-
# name(Name) :string(50) not null
1533-
# notes(Notes) :text(55) not null
1534-
# no_comment :text(20) not null
1535-
#
1536-
EOS
1537-
end
1538-
1539-
it 'works with option "with_comment"' do
1540-
is_expected.to eq expected_result
1541-
end
1542-
end
1543-
1544-
context 'when columns have multibyte comments' do
1545-
let :columns do
1546-
[
1547-
mock_column(:id, :integer, limit: 8, comment: 'ID'),
1548-
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
1549-
mock_column(:name, :string, limit: 50, comment: 'NAME'),
1550-
mock_column(:notes, :text, limit: 55, comment: 'NOTES'),
1551-
mock_column(:cyrillic, :text, limit: 30, comment: 'Кириллица'),
1552-
mock_column(:japanese, :text, limit: 60, comment: '熊本大学 イタリア 宝島'),
1553-
mock_column(:arabic, :text, limit: 20, comment: 'لغة'),
1554-
mock_column(:no_comment, :text, limit: 20, comment: nil),
1555-
mock_column(:location, :geometry_collection, limit: nil, comment: nil)
1556-
]
1557-
end
1558-
1559-
let :expected_result do
1560-
<<~EOS
1561-
# Schema Info
1562-
#
1563-
# Table name: users
1564-
#
1565-
# id(ID) :integer not null, primary key
1566-
# active(ACTIVE) :boolean not null
1567-
# name(NAME) :string(50) not null
1568-
# notes(NOTES) :text(55) not null
1569-
# cyrillic(Кириллица) :text(30) not null
1570-
# japanese(熊本大学 イタリア 宝島) :text(60) not null
1571-
# arabic(لغة) :text(20) not null
1572-
# no_comment :text(20) not null
1573-
# location :geometry_collect not null
1574-
#
1575-
EOS
1576-
end
1577-
1578-
it 'works with option "with_comment"' do
1579-
is_expected.to eq expected_result
1580-
end
1581-
end
1582-
1583-
context 'when geometry columns are included' do
1584-
let :columns do
1585-
[
1586-
mock_column(:id, :integer, limit: 8),
1587-
mock_column(:active, :boolean, default: false, null: false),
1588-
mock_column(:geometry, :geometry,
1589-
geometric_type: 'Geometry', srid: 4326,
1590-
limit: { srid: 4326, type: 'geometry' }),
1591-
mock_column(:location, :geography,
1592-
geometric_type: 'Point', srid: 0,
1593-
limit: { srid: 0, type: 'geometry' })
1594-
]
1595-
end
1596-
1597-
let :expected_result do
1598-
<<~EOS
1599-
# Schema Info
1600-
#
1601-
# Table name: users
1602-
#
1603-
# id :integer not null, primary key
1604-
# active :boolean default(FALSE), not null
1605-
# geometry :geometry not null, geometry, 4326
1606-
# location :geography not null, point, 0
1607-
#
1608-
EOS
1609-
end
1610-
1611-
it 'works with option "with_comment"' do
1612-
is_expected.to eq expected_result
1613-
end
1614-
end
1615-
end
1616-
end
1617-
end
1618-
end
1619-
16201612
context 'when header is "== Schema Information"' do
16211613
let :header do
16221614
AnnotateModels::PREFIX

0 commit comments

Comments
 (0)