1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Expand paths to app builders relative to the working directory

This commit is contained in:
Carl Lerche 2010-05-06 12:02:54 +03:00
parent 5be49884b5
commit 6d7f2790cd
2 changed files with 12 additions and 1 deletions

View file

@ -200,6 +200,9 @@ module Rails
def initialize(*args) def initialize(*args)
raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank? raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?
@original_wd = Dir.pwd
super super
if !options[:skip_activerecord] && !DATABASES.include?(options[:database]) if !options[:skip_activerecord] && !DATABASES.include?(options[:database])
@ -316,7 +319,7 @@ module Rails
if URI(path).is_a?(URI::HTTP) if URI(path).is_a?(URI::HTTP)
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read } contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
else else
contents = open(path) {|io| io.read } contents = open(File.expand_path(path, @original_wd)) {|io| io.read }
end end
prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1) prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)

View file

@ -238,6 +238,14 @@ class CustomAppGeneratorTest < Rails::Generators::TestCase
assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
end end
def test_builder_option_with_relative_path
here = File.expand_path(File.dirname(__FILE__))
FileUtils.cd(here)
run_generator([destination_root, "-b", "../fixtures/lib/simple_builder.rb"])
(DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path }
assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
end
def test_builder_option_with_tweak_app_builder def test_builder_option_with_tweak_app_builder
FileUtils.cd(Rails.root) FileUtils.cd(Rails.root)
run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"]) run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"])