Skip to content

Commit 227e80c

Browse files
committed
Move test cases when "format_markdown" and "with_comment" are specified in options
1 parent 5464b75 commit 227e80c

File tree

1 file changed

+64
-80
lines changed

1 file changed

+64
-80
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 64 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,70 @@ def mock_column(name, type, options = {})
15381538
end
15391539
end
15401540
end
1541+
1542+
context 'when "format_markdown" and "with_comment" are specified in options' do
1543+
let :options do
1544+
{ format_markdown: true, with_comment: true }
1545+
end
1546+
1547+
context 'when columns have comments' do
1548+
let :columns do
1549+
[
1550+
mock_column(:id, :integer, comment: 'ID'),
1551+
mock_column(:name, :string, limit: 50, comment: 'Name')
1552+
]
1553+
end
1554+
1555+
let :expected_result do
1556+
<<~EOS
1557+
# == Schema Information
1558+
#
1559+
# Table name: `users`
1560+
#
1561+
# ### Columns
1562+
#
1563+
# Name | Type | Attributes
1564+
# ----------------- | ------------------ | ---------------------------
1565+
# **`id(ID)`** | `integer` | `not null, primary key`
1566+
# **`name(Name)`** | `string(50)` | `not null`
1567+
#
1568+
EOS
1569+
end
1570+
1571+
it 'returns schema info in Markdown format' do
1572+
is_expected.to eq expected_result
1573+
end
1574+
end
1575+
1576+
context 'when columns have multibyte comments' do
1577+
let :columns do
1578+
[
1579+
mock_column(:id, :integer, comment: 'ID'),
1580+
mock_column(:name, :string, limit: 50, comment: 'NAME')
1581+
]
1582+
end
1583+
1584+
let :expected_result do
1585+
<<~EOS
1586+
# == Schema Information
1587+
#
1588+
# Table name: `users`
1589+
#
1590+
# ### Columns
1591+
#
1592+
# Name | Type | Attributes
1593+
# --------------------- | ------------------ | ---------------------------
1594+
# **`id(ID)`** | `integer` | `not null, primary key`
1595+
# **`name(NAME)`** | `string(50)` | `not null`
1596+
#
1597+
EOS
1598+
end
1599+
1600+
it 'returns schema info in Markdown format' do
1601+
is_expected.to eq expected_result
1602+
end
1603+
end
1604+
end
15411605
end
15421606
end
15431607
end
@@ -1633,86 +1697,6 @@ def mock_column(name, type, options = {})
16331697
end
16341698
end
16351699

1636-
describe '.get_schema_info (with custom options)' do
1637-
let :klass do
1638-
mock_class(:users, :id, columns)
1639-
end
1640-
1641-
subject do
1642-
AnnotateModels.get_schema_info(klass, header, options)
1643-
end
1644-
1645-
context 'when header is "== Schema Information"' do
1646-
let :header do
1647-
AnnotateModels::PREFIX
1648-
end
1649-
1650-
context 'when "format_markdown" and "with_comment" are specified in options' do
1651-
let :options do
1652-
{ format_markdown: true, with_comment: true }
1653-
end
1654-
1655-
context 'when columns have comments' do
1656-
let :columns do
1657-
[
1658-
mock_column(:id, :integer, comment: 'ID'),
1659-
mock_column(:name, :string, limit: 50, comment: 'Name')
1660-
]
1661-
end
1662-
1663-
let :expected_result do
1664-
<<~EOS
1665-
# == Schema Information
1666-
#
1667-
# Table name: `users`
1668-
#
1669-
# ### Columns
1670-
#
1671-
# Name | Type | Attributes
1672-
# ----------------- | ------------------ | ---------------------------
1673-
# **`id(ID)`** | `integer` | `not null, primary key`
1674-
# **`name(Name)`** | `string(50)` | `not null`
1675-
#
1676-
EOS
1677-
end
1678-
1679-
it 'returns schema info in Markdown format' do
1680-
is_expected.to eq expected_result
1681-
end
1682-
end
1683-
1684-
context 'when columns have multibyte comments' do
1685-
let :columns do
1686-
[
1687-
mock_column(:id, :integer, comment: 'ID'),
1688-
mock_column(:name, :string, limit: 50, comment: 'NAME')
1689-
]
1690-
end
1691-
1692-
let :expected_result do
1693-
<<~EOS
1694-
# == Schema Information
1695-
#
1696-
# Table name: `users`
1697-
#
1698-
# ### Columns
1699-
#
1700-
# Name | Type | Attributes
1701-
# --------------------- | ------------------ | ---------------------------
1702-
# **`id(ID)`** | `integer` | `not null, primary key`
1703-
# **`name(NAME)`** | `string(50)` | `not null`
1704-
#
1705-
EOS
1706-
end
1707-
1708-
it 'returns schema info in Markdown format' do
1709-
is_expected.to eq expected_result
1710-
end
1711-
end
1712-
end
1713-
end
1714-
end
1715-
17161700
describe '.get_model_files' do
17171701
subject { described_class.get_model_files(options) }
17181702

0 commit comments

Comments
 (0)