Skip to content

Commit

Permalink
there is no reason for ARGV[0] to be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 30, 2013
1 parent 36ea8e6 commit 19ca095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -362,15 +362,17 @@ def railsrc(argv)
end
end

def read_rc_file(railsrc)
return [] unless File.exists?(railsrc)
extra_args_string = File.read(railsrc)
extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
puts "Using #{extra_args.join(" ")} from #{railsrc}"
extra_args
end

def insert_railsrc_into_argv!(argv, railsrc)
if File.exist?(railsrc)
extra_args_string = File.read(railsrc)
extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
puts "Using #{extra_args.join(" ")} from #{railsrc}"
[argv.first] + extra_args + argv.drop(1)
else
argv
end
extra_args = read_rc_file railsrc
argv.take(1) + extra_args + argv.drop(1)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions railties/test/generators/argv_scrubber_test.rb
Expand Up @@ -67,7 +67,7 @@ def test_new_homedir_rc
define_method(:puts) { |msg| message = msg }
}.new ['new']
args = scrubber.prepare!
assert_equal [nil, '--hello-world'], args
assert_equal ['--hello-world'], args
assert_match 'hello-world', message
assert_match file.path, message
ensure
Expand All @@ -85,7 +85,7 @@ def test_new_rc_option
define_method(:puts) { |msg| message = msg }
}.new ['new', "--rc=#{file.path}"]
args = scrubber.prepare!
assert_equal [nil, '--hello-world'], args
assert_equal ['--hello-world'], args
assert_match 'hello-world', message
assert_match file.path, message
ensure
Expand Down

0 comments on commit 19ca095

Please sign in to comment.