Skip to content

Commit

Permalink
Expand paths to app builders relative to the working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed May 6, 2010
1 parent 5be4988 commit 6d7f279
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -200,6 +200,9 @@ class AppGenerator < Base

def initialize(*args)
raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?

@original_wd = Dir.pwd

super

if !options[:skip_activerecord] && !DATABASES.include?(options[:database])
Expand Down Expand Up @@ -316,7 +319,7 @@ def builder
if URI(path).is_a?(URI::HTTP)
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
else
contents = open(path) {|io| io.read }
contents = open(File.expand_path(path, @original_wd)) {|io| io.read }
end

prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)
Expand Down
8 changes: 8 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -238,6 +238,14 @@ def test_builder_option_with_simple_app_builder
assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
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
FileUtils.cd(Rails.root)
run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"])
Expand Down

0 comments on commit 6d7f279

Please sign in to comment.