summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaushik C <kaushik.chand@gmail.com>2015-06-09 16:00:06 -0400
committerKaushik C <kaushik.chand@gmail.com>2015-07-27 12:52:27 -0400
commitd9820c430b686a1dedd4ab2cadd20b0cadbbb0d7 (patch)
tree2ff7eef34ce7a81720aee46026ef06b6de61fc20
parentce0c2d7ac2685d4fab78a99bf8fa9838b39a5eb8 (diff)
downloadchef-d9820c430b686a1dedd4ab2cadd20b0cadbbb0d7.tar.gz
Fixing Issue #2513 - the broken render of nested partial templates with variables
Authors: Kaushik C <kaushik.chand@gmail.com>, Sam Dunne <sam@sam-dunne.com>
-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 d705a9e7be..9b35bbcc33 100644
--- a/lib/chef/mixin/template.rb
+++ b/lib/chef/mixin/template.rb
@@ -89,6 +89,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 ee4e0bed02..318c2a7e85 100644
--- a/spec/unit/cookbook/syntax_check_spec.rb
+++ b/spec/unit/cookbook/syntax_check_spec.rb
@@ -54,6 +54,8 @@ describe Chef::Cookbook::SyntaxCheck do
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
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
-