Skip to content

Commit 6d7f279

Browse files
author
Carl Lerche
committed
Expand paths to app builders relative to the working directory
1 parent 5be4988 commit 6d7f279

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class AppGenerator < Base
200200

201201
def initialize(*args)
202202
raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?
203+
204+
@original_wd = Dir.pwd
205+
203206
super
204207

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

322325
prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)

railties/test/generators/app_generator_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ def test_builder_option_with_simple_app_builder
238238
assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
239239
end
240240

241+
def test_builder_option_with_relative_path
242+
here = File.expand_path(File.dirname(__FILE__))
243+
FileUtils.cd(here)
244+
run_generator([destination_root, "-b", "../fixtures/lib/simple_builder.rb"])
245+
(DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path }
246+
assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
247+
end
248+
241249
def test_builder_option_with_tweak_app_builder
242250
FileUtils.cd(Rails.root)
243251
run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"])

0 commit comments

Comments
 (0)