From 8cef71766c2481cb4f100b705c01882d2d62db8e Mon Sep 17 00:00:00 2001 From: Khaja Minhajuddin Date: Thu, 30 Jun 2011 21:50:12 +0530 Subject: [PATCH] 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