summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-09-02 13:42:07 +0100
committerThom May <thom@may.lt>2015-09-02 13:42:07 +0100
commitb25ff490b191bbec7f291733108f6980f68000a1 (patch)
treed54b80693ab2bb55df74368e31eac65e4eca3e1e
parentb86ba5b0858676da98e0456d340ac2f1a031a0d1 (diff)
parentd9820c430b686a1dedd4ab2cadd20b0cadbbb0d7 (diff)
downloadchef-b25ff490b191bbec7f291733108f6980f68000a1.tar.gz
Merge pull request #3510 from ckaushik/issue_2513
Fixing Issue #2513 - the broken render of nested partial templates
-rw-r--r--lib/chef/mixin/template.rb1
-rw-r--r--spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb1
-rw-r--r--spec/data/cookbooks/openldap/templates/default/nested_partial.erb1
-rw-r--r--spec/unit/cookbook/syntax_check_spec.rb2
-rw-r--r--spec/unit/mixin/template_spec.rb6
5 files changed, 10 insertions, 1 deletions
diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb
index be83edc697..db9a2f6d91 100644
--- a/lib/chef/mixin/template.rb
+++ b/lib/chef/mixin/template.rb
@@ -136,6 +136,7 @@ class Chef
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)
diff --git a/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb b/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb
new file mode 100644
index 0000000000..2d356ec21d
--- /dev/null
+++ b/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb
@@ -0,0 +1 @@
+before <%= render 'nested_partial.erb', :variables => { :hello => @test } %> after
diff --git a/spec/data/cookbooks/openldap/templates/default/nested_partial.erb b/spec/data/cookbooks/openldap/templates/default/nested_partial.erb
new file mode 100644
index 0000000000..415646ca31
--- /dev/null
+++ b/spec/data/cookbooks/openldap/templates/default/nested_partial.erb
@@ -0,0 +1 @@
+{<%= @hello %>}
diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb
index 764829c387..efdb5b7926 100644
--- a/spec/unit/cookbook/syntax_check_spec.rb
+++ b/spec/unit/cookbook/syntax_check_spec.rb
@@ -55,6 +55,8 @@ describe Chef::Cookbook::SyntaxCheck do
helper_test.erb
helpers.erb
openldap_stuff.conf.erb
+ nested_openldap_partials.erb
+ nested_partial.erb
openldap_variable_stuff.conf.erb
test.erb
some_windows_line_endings.erb
diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb
index 6a867b5f9a..95d0eb6711 100644
--- a/spec/unit/mixin/template_spec.rb
+++ b/spec/unit/mixin/template_spec.rb
@@ -150,6 +150,11 @@ describe Chef::Mixin::Template, "render_template" do
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")
@@ -266,4 +271,3 @@ describe Chef::Mixin::Template, "render_template" do
end
end
end
-