Skip to content
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

Fixing Issue #2513 - the broken render of nested partial templates #3510

Merged
merged 1 commit into from
Sep 2, 2015
Merged
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
1 change: 1 addition & 0 deletions lib/chef/mixin/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def render(partial_name, options = {})
raise "You cannot render partials in this context" unless @template_finder

partial_variables = options.delete(:variables) || _public_instance_variables
partial_variables[:template_finder] = @template_finder
partial_context = self.class.new(partial_variables)
partial_context._extend_modules(@_extension_modules)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
before <%= render 'nested_partial.erb', :variables => { :hello => @test } %> after
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{<%= @hello %>}
2 changes: 2 additions & 0 deletions spec/unit/cookbook/syntax_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
basenames = %w{ helpers_via_partial_test.erb
helper_test.erb
openldap_stuff.conf.erb
nested_openldap_partials.erb
nested_partial.erb
openldap_variable_stuff.conf.erb
test.erb
some_windows_line_endings.erb
Expand Down
6 changes: 5 additions & 1 deletion spec/unit/mixin/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
output == "before {super secret is candy} after"
end

it "should pass the template finder to the partials" do
output = @template_context.render_template_from_string("before {<%= render 'nested_openldap_partials.erb', :variables => {:hello => 'Hello World!' } %>} after")
output == "before {Hello World!} after"
end

it "should pass variables to partials" do
output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb', :variables => {:secret => 'whatever' } %>} after")
expect(output).to eq("before {super secret is whatever} after")
Expand Down Expand Up @@ -266,4 +271,3 @@ def do_raise
end
end
end