Skip to content

Commit eb327d7

Browse files
committed
test(MarkdownBuilder): add builder test)
1 parent 7721eab commit eb327d7

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

spec/dummy/app/admin/invoices.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ActiveAdmin.register Invoice do
22
permit_params :legal_date, :number, :paid, :state, :attachment, :photo, :category_id, :city_id,
3-
:amount, :color, :updated_at, :picture, :active, item_ids: [], other_item_ids: []
3+
:amount, :color, :updated_at, :picture, :active, :description, item_ids: [], other_item_ids: []
44

55
filter :id, as: :numeric_range_filter
66

@@ -21,6 +21,7 @@
2121
attachment_column :attachment
2222
number_column :amount, as: :currency, unit: "$", separator: ","
2323
toggle_bool_column :active
24+
markdown_column :description
2425
column :created_at
2526
actions
2627
end
@@ -40,6 +41,7 @@
4041
row :legal_date
4142
number_row("Monto", :amount, as: :human, &:amount)
4243
row :city
44+
markdown_row(:description)
4345
bool_row :active
4446
end
4547

@@ -85,6 +87,8 @@
8587

8688
f.input :attachment
8789

90+
f.input :description
91+
8892
f.input :legal_date
8993

9094
f.input :photo
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require 'rails_helper'
2+
3+
describe "Markdown Builder", type: :feature do
4+
context "shows text as markdown" do
5+
before do
6+
register_index(Invoice) do
7+
markdown_column :description
8+
end
9+
end
10+
11+
context "with markdown text" do
12+
before do
13+
create_invoice(description: "# Header **bold** *italic*")
14+
visit admin_invoices_path
15+
end
16+
17+
it "shows parsed markdown" do
18+
expect(page.html).to include("<h1>Header <strong>bold</strong> <em>italic</em></h1>")
19+
end
20+
end
21+
end
22+
23+
context "shows text as markdown with custom options" do
24+
before do
25+
register_index(Invoice) do
26+
markdown_column :description, extensions: { highlight: true }
27+
end
28+
end
29+
30+
context "with markdown text" do
31+
before do
32+
create_invoice(description: "This is ==highlighted==")
33+
visit admin_invoices_path
34+
end
35+
36+
it "shows parsed markdown" do
37+
expect(page.html).to include("This is <mark>highlighted</mark>")
38+
end
39+
end
40+
end
41+
42+
context "passing a block" do
43+
before do
44+
register_show(Invoice) do
45+
markdown_row(:description) do
46+
"# Header **bold** *italic*"
47+
end
48+
end
49+
50+
visit admin_invoice_path(create_invoice)
51+
end
52+
53+
it "shows parsed markdown" do
54+
expect(page.html).to include("<h1>Header <strong>bold</strong> <em>italic</em></h1>")
55+
end
56+
end
57+
58+
context "passing a block with custom options" do
59+
before do
60+
register_show(Invoice) do
61+
markdown_row(:description, extensions: { highlight: true }) do
62+
"This is ==highlighted=="
63+
end
64+
end
65+
66+
visit admin_invoice_path(create_invoice)
67+
end
68+
69+
it "shows parsed markdown" do
70+
expect(page.html).to include("This is <mark>highlighted</mark>")
71+
end
72+
end
73+
end

0 commit comments

Comments
 (0)