Skip to content

Commit 51c75d3

Browse files
committed
tests for no prerendering in controllers
1 parent ec7a6f5 commit 51c75d3

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

test/dummy/app/controllers/server_controller.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ def console_example_suppressed
1515
@todos = %w{todo1 todo2 todo3}
1616
end
1717

18-
def inline_component
18+
def inline_component_prerender_true
1919
render component: 'TodoList',
2020
props: { todos: ['Render this inline'] },
2121
tag: 'span',
2222
class: 'custom-class',
2323
id: 'custom-id',
2424
data: { remote: true }
2525
end
26+
27+
def inline_component_prerender_false
28+
render component: 'TodoList',
29+
props: { todos: ['Render this inline'] },
30+
tag: 'span',
31+
class: 'custom-class',
32+
id: 'custom-id',
33+
data: { remote: true },
34+
prerender: false
35+
end
2636
end

test/dummy/config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
collection do
55
get :console_example
66
get :console_example_suppressed
7-
get :inline_component
7+
get :inline_component_prerender_true
8+
get :inline_component_prerender_false
89
end
910
end
1011
end

test/server_rendered_html_test.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def wait_to_ensure_asset_pipeline_detects_changes
5353
assert_no_match(/console.error/, response.body)
5454
end
5555

56-
test 'react inline component rendering' do
57-
get '/server/inline_component'
56+
test 'react inline component rendering (pre-rendered)' do
57+
get '/server/inline_component_prerender_true'
5858
rendered_html = response.body
5959
assert_match(/<span.*data-react-class=\"TodoList\"/, rendered_html)
6060
# make sure that the items are prerendered
@@ -67,5 +67,21 @@ def wait_to_ensure_asset_pipeline_detects_changes
6767
assert_match(/id=\"custom-id\"/, rendered_html)
6868
assert_match(/data-remote=\"true\"/, rendered_html)
6969
end
70+
71+
test 'react inline component rendering (not pre-rendered)' do
72+
get '/server/inline_component_prerender_false'
73+
rendered_html = response.body
74+
75+
assert_match(/<span.*data-react-class=\"TodoList\"/, rendered_html)
76+
# make sure that the items are prerendered
77+
assert_match(/Render this inline/, rendered_html)
78+
assert_match(/<\/span>/, rendered_html, "it accepts a tag override")
79+
# make sure that the layout is rendered with the component
80+
assert_match(/<title>Dummy<\/title>/, rendered_html)
81+
# make sure that custom html attributes are rendered
82+
assert_match(/class=\"custom-class\"/, rendered_html)
83+
assert_match(/id=\"custom-id\"/, rendered_html)
84+
assert_match(/data-remote=\"true\"/, rendered_html)
85+
end
7086
end
7187
end

0 commit comments

Comments
 (0)