22
33# Provide direct access to the view helper methods
44class ViewHelperHelper
5+ extend ActionView ::Context
6+ extend ActionView ::Helpers ::CaptureHelper
57 extend React ::Rails ::ViewHelper
8+
69end
710
811class ViewHelperTest < ActionView ::TestCase
@@ -12,12 +15,31 @@ class ViewHelperTest < ActionView::TestCase
1215 assert_equal ( expected_html , rendered_html )
1316 end
1417
18+ test 'view helper accepts block usage' do
19+ expected_html = %{<div data-react-class="Component" data-react-props="{"a":"b"}">content</div>}
20+ rendered_html = ViewHelperHelper . react_component ( "Component" , { a : "b" } ) do
21+ "content"
22+ end
23+ assert_equal ( expected_html , rendered_html )
24+ end
25+
1526 test "view helper can be used in stand-alone views" do
1627 @name = "React-Rails"
1728 render template : "pages/show"
1829 assert_includes ( rendered , "React-Rails" )
1930 end
2031
32+ test "view helper can accept block and render inner content only once" do
33+ rendered_html = render partial : "pages/component_with_inner_html"
34+ expected_html = <<HTML
35+ < div data-react-class =\" GreetingMessage\" data-react-props=\" {"name":"Name"}\" id=\" component\" >
36+ < div id =\" unique-nested-id\" > NestedContent</ div>
37+ </ div>
38+ HTML
39+ assert_equal expected_html . strip , rendered_html
40+ end
41+
42+
2143 test "view helper uses the implementation class set in the initializer" do
2244 assert_equal (
2345 React ::Rails ::ViewHelper . helper_implementation_class . to_s ,
0 commit comments