tweaked the upstart export code so that it looks for templates in ~/.foreman if no template_root is specified.

This commit is contained in:
Khaja Minhajuddin
2011-06-30 21:50:12 +05:30
parent a2ba079665
commit 8cef71766c
2 changed files with 18 additions and 0 deletions

View File

@@ -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

View File

@@ -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