From 8cef71766c2481cb4f100b705c01882d2d62db8e Mon Sep 17 00:00:00 2001 From: Khaja Minhajuddin Date: Thu, 30 Jun 2011 21:50:12 +0530 Subject: [PATCH 1/2] tweaked the upstart export code so that it looks for templates in ~/.foreman if no template_root is specified. --- lib/foreman/export/base.rb | 2 ++ spec/foreman/export/upstart_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/foreman/export/base.rb b/lib/foreman/export/base.rb index e771196..09fd89f 100644 --- a/lib/foreman/export/base.rb +++ b/lib/foreman/export/base.rb @@ -26,6 +26,8 @@ private ###################################################################### def export_template(exporter, file, template_root) if template_root && File.exist?(file_path = File.join(template_root, file)) File.read(file_path) + elsif File.exist?(file_path = File.join("~/.foreman/", file)) + File.read(file_path) else File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__)) end diff --git a/spec/foreman/export/upstart_spec.rb b/spec/foreman/export/upstart_spec.rb index db746c0..ef8f653 100644 --- a/spec/foreman/export/upstart_spec.rb +++ b/spec/foreman/export/upstart_spec.rb @@ -36,4 +36,20 @@ describe Foreman::Export::Upstart do File.read("/tmp/init/app.conf").should == "alternate_template\n" end end + + context "with alternate templates from home dir" do + let(:default_template_root) {File.expand_path("~/.foreman")} + + before do + FileUtils.mkdir_p default_template_root + File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" } + end + + it "can export with alternate template files" do + upstart.export("/tmp/init") + + File.read("/tmp/init/app.conf").should == "default_alternate_template\n" + end + end + end From 64338c5a09402e3113771ca86512f6a2c8472342 Mon Sep 17 00:00:00 2001 From: Khaja Minhajuddin Date: Thu, 30 Jun 2011 22:23:38 +0530 Subject: [PATCH 2/2] use a dedicated directory (~/.foreman/templates) to store the templates --- lib/foreman/export/base.rb | 2 +- spec/foreman/export/upstart_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/foreman/export/base.rb b/lib/foreman/export/base.rb index 09fd89f..1c38c1f 100644 --- a/lib/foreman/export/base.rb +++ b/lib/foreman/export/base.rb @@ -26,7 +26,7 @@ private ###################################################################### def export_template(exporter, file, template_root) if template_root && File.exist?(file_path = File.join(template_root, file)) File.read(file_path) - elsif File.exist?(file_path = File.join("~/.foreman/", file)) + elsif File.exist?(file_path = File.join("~/.foreman/templates", file)) File.read(file_path) else File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__)) diff --git a/spec/foreman/export/upstart_spec.rb b/spec/foreman/export/upstart_spec.rb index ef8f653..b06dfda 100644 --- a/spec/foreman/export/upstart_spec.rb +++ b/spec/foreman/export/upstart_spec.rb @@ -38,7 +38,7 @@ describe Foreman::Export::Upstart do end context "with alternate templates from home dir" do - let(:default_template_root) {File.expand_path("~/.foreman")} + let(:default_template_root) {File.expand_path("~/.foreman/templates")} before do FileUtils.mkdir_p default_template_root