Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Improper render text detection #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/cache_digests/template_digestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class TemplateDigestor
# render(topics) => render("topics/topic")
# render(message.topics) => render("topics/topic")
RENDER_DEPENDENCY = /
render\s* # render, followed by optional whitespace
\(? # start an optional parenthesis for the render call
render(?:\s+?| # render, followed by optional whitespace
\() # start an optional parenthesis for the render call
(partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture
([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture
/x
Expand Down Expand Up @@ -106,4 +106,4 @@ def explicit_dependencies
source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
end
end
end
end
45 changes: 45 additions & 0 deletions test/render_dependency_matcher_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'cache_digests/test_helper'
require 'fileutils'

class RenderDependencyMatcherTest < MiniTest::Unit::TestCase
def test_matches_render_partial
assert_matched "render partial: \"comments/comment\", collection: commentable.comments"
end

def test_matches_render_no_partial_double_quote
assert_matched "render \"comments/comments\""
end

def test_matches_render_no_partial_single_quote
assert_matched "render 'comments/comments'"
end

def test_matches_render_no_partial_single_quote_in_parens
assert_matched "render('comments/comments')"
end

def test_matches_render_with_instance_var
assert_matched "render(@topic)"
end

def test_matches_render_with_local_var
assert_matched "render(topics)"
end

def test_misses_string_rendered
assert_misses "rendered"
end

private
def matcher
CacheDigests::TemplateDigestor::RENDER_DEPENDENCY
end

def assert_matched(str)
assert str =~ matcher, "Should have matched #{str} but didn't."
end

def assert_misses(str)
assert str !~ matcher, "Matched #{str} but should not have."
end
end