-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test coverage for Partial Helpers #64
Conversation
Introduce renderer test coverage to exercise that Partials can declare their own [isolated helper methods][] for use within templates. [isolated helper methods]: https://github.com/bullet-train-co/nice_partials/tree/v0.1.5#defining-and-using-well-isolated-helper-methods
end | ||
%> | ||
|
||
<p><%= upcase yield %></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we can call upcase
without doing partial.upcase
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this benefiting from a misuse of a Section
definition?
https://github.com/bullet-train-co/nice_partials/blob/main/lib/nice_partials/partial.rb#L107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm not quite sure what's going on here, I'll try to look locally.
@kaspth the outer diff --git a/test/fixtures/_partial_with_helpers.html.erb b/test/fixtures/_partial_with_helpers.html.erb
index e4b57e3..3131172 100644
--- a/test/fixtures/_partial_with_helpers.html.erb
+++ b/test/fixtures/_partial_with_helpers.html.erb
@@ -11,3 +11,5 @@
%>
<p><%= upcase yield %></p>
+
+<%= partial.block %>
diff --git a/test/renderer_test.rb b/test/renderer_test.rb
index c5bcaf7..bde5a72 100644
--- a/test/renderer_test.rb
+++ b/test/renderer_test.rb
@@ -55,6 +55,14 @@ class RendererTest < NicePartials::Test
assert_css "p", text: "TEXT WITH SPACES"
end
+ test "render partial exposes helper methods within caller's blocks" do
+ render "partial_with_helpers" do |partial|
+ partial.block { partial.upcase("text in a block") }
+ end
+
+ assert_text "TEXT IN A BLOCK"
+ end
+
test "accessing partial in outer context won't leak state to inner render" do
render "partial_accessed_in_outer_context" That makes the partial: <%
partial.helpers do
def upcase(content)
content.upcase
end
def squish(content)
content.gsub(/\s+/, " ")
end
end
%>
<p><%= upcase yield %></p>
<%= partial.block %> The test failure is something like:
|
Introduce renderer test coverage to exercise that Partials can declare their own [isolated helper methods][] for use within templates. Fixes #64 [isolated helper methods]: https://github.com/bullet-train-co/nice_partials/tree/v0.1.5#defining-and-using-well-isolated-helper-methods
Introduce renderer test coverage to exercise that Partials can declare their own [isolated helper methods][] for use within templates. Fixes #64 [isolated helper methods]: https://github.com/bullet-train-co/nice_partials/tree/v0.1.5#defining-and-using-well-isolated-helper-methods
Introduce renderer test coverage to exercise that Partials can declare their own [isolated helper methods][] for use within templates. Fixes #64 [isolated helper methods]: https://github.com/bullet-train-co/nice_partials/tree/v0.1.5#defining-and-using-well-isolated-helper-methods Co-authored-by: Sean Doyle <sean.p.doyle24@gmail.com>
interesting, I'm a little tired so I can't quite get it, do you want to double check now and open a new issue? |
Introduce renderer test coverage to exercise that Partials can declare their own isolated helper methods for use within templates.