Skip to content

Commit

Permalink
Merge pull request #89 from github/component-with-content
Browse files Browse the repository at this point in the history
Add support for rendering ViewComponents `with_content`
  • Loading branch information
joelhawksley authored Jun 24, 2021
2 parents 527a7e0 + ac8cb0b commit 320115a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rubocop/cop/github/render_literal_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ module RenderLiteralHelpers
(send nil? {:render :render_to_string} ({str sym} $_) $...)
PATTERN

def_node_matcher :render_inst?, <<-PATTERN
(send nil? {:render :render_to_string} (send _ :new ...) ...)
PATTERN

def_node_matcher :render_with_options?, <<-PATTERN
(send nil? {:render :render_to_string} (hash $...) ...)
PATTERN
Expand All @@ -32,6 +28,10 @@ module RenderLiteralHelpers
(send nil? {:render :render_to_string} (send _ :new ...) ...)
PATTERN

def_node_matcher :render_view_component_instance_with_content?, <<-PATTERN
(send nil? {:render :render_to_string} (send (send _ :new ...) `:with_content ...))
PATTERN

def_node_matcher :render_view_component_collection?, <<-PATTERN
(send nil? {:render :render_to_string} (send _ :with_collection ...) ...)
PATTERN
Expand All @@ -45,7 +45,8 @@ def hash_with_literal_keys?(hash)
end

def render_view_component?(node)
render_view_component_instance?(node) ||
render_view_component_instance_with_content?(node) ||
render_view_component_instance?(node) ||
render_view_component_collection?(node)
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/test_rails_view_render_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def test_render_component_instance_no_offense
assert_equal 0, cop.offenses.count
end

def test_render_component_instance_with_content_no_offense
erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb"
<%= render MyClass.new(title: "foo", bar: "baz").with_content("foo") %>
ERB

assert_equal 0, cop.offenses.count
end

def test_render_component_instance_block_no_offense
erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb"
<%= render Module::MyClass.new(title: "foo", bar: "baz") do %>Content<% end %>
Expand Down

0 comments on commit 320115a

Please sign in to comment.