Skip to content

Commit

Permalink
Merge pull request #68 from github/component-collections
Browse files Browse the repository at this point in the history
Support latest ViewComponent syntax
  • Loading branch information
joelhawksley authored May 21, 2020
2 parents 1d5ac0b + a632d06 commit 535c4ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/rubocop/cop/github/rails_view_render_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class RailsViewRenderLiteral < Cop
(send nil? :render (send _ :new ...) ...)
PATTERN

def_node_matcher :render_const?, <<-PATTERN
(send nil? :render (const _ _) ...)
def_node_matcher :render_collection?, <<-PATTERN
(send nil? :render (send _ :with_collection ...) ...)
PATTERN

def_node_matcher :render_with_options?, <<-PATTERN
Expand All @@ -50,7 +50,7 @@ class RailsViewRenderLiteral < Cop
def on_send(node)
return unless render?(node)

if render_literal?(node) || render_inst?(node) || render_const?(node)
if render_literal?(node) || render_inst?(node) || render_collection?(node)
elsif option_pairs = render_with_options?(node)
if option_pairs.any? { |pair| ignore_key?(pair) }
return
Expand Down
24 changes: 8 additions & 16 deletions test/test_rails_view_render_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,33 @@ def test_render_component_no_offense
assert_equal 0, cop.offenses.count
end

def test_render_component_class_name_no_offense
erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb"
<%= render Module::MyClass, title: "foo", bar: "baz" %>
ERB

assert_equal 0, cop.offenses.count
end

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

assert_equal 0, cop.offenses.count
end

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

assert_equal 0, cop.offenses.count
end

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

assert_equal 0, cop.offenses.count
end

def test_render_component_class_block_no_offense
def test_render_component_module_collection_no_offense
erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb"
<%= render Module::MyClass, title: "foo", bar: "baz" do %>Content<% end %>
<%= render Foo::MyClass.with_collection(title: "foo", bar: "baz") %>
ERB

assert_equal 0, cop.offenses.count
Expand Down

0 comments on commit 535c4ae

Please sign in to comment.