aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-04-10 08:26:56 -0700
committerXavier Noria <fxn@hashref.com>2013-04-10 08:26:56 -0700
commit1c67ecca05f370faeb6adce44d0d98631a9541d4 (patch)
tree35a7ee80f77014a9ae333112497c487446b0a234
parent4658b0d48c6b339c504cb3273f5a1eb6960f85a4 (diff)
parent22e5ab31b52a287705083ad6f3cad836ab96b619 (diff)
downloadrails-1c67ecca05f370faeb6adce44d0d98631a9541d4.tar.gz
rails-1c67ecca05f370faeb6adce44d0d98631a9541d4.tar.bz2
rails-1c67ecca05f370faeb6adce44d0d98631a9541d4.zip
Merge pull request #10157 from prathamesh-sonpatki/app_loader
Searching for rails executable correctly
-rw-r--r--railties/lib/rails/app_rails_loader.rb27
-rw-r--r--railties/test/app_rails_loader_test.rb6
2 files changed, 14 insertions, 19 deletions
diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb
index 1c64f2dcc6..ef6fcd81b4 100644
--- a/railties/lib/rails/app_rails_loader.rb
+++ b/railties/lib/rails/app_rails_loader.rb
@@ -6,22 +6,22 @@ module Rails
EXECUTABLES = ['bin/rails', 'script/rails']
def self.exec_app_rails
- cwd = Dir.pwd
-
- exe = find_executable
- exe ||= find_executable_in_parent_path
- return unless exe
+ cwd = Dir.pwd
+ pathname = Pathname.new(Dir.pwd)
+
+ until exe = find_executable
+ # Return to working directory if root is hit without finding executable
+ Dir.chdir(cwd) and return if pathname.root?
+ # Otherwise keep moving upwards in search of executable
+ Dir.chdir("..")
+ pathname = pathname.parent
+ end
contents = File.read(exe)
# This is the Rails executable, let's use it
if contents =~ /(APP|ENGINE)_PATH/
- exec RUBY, exe, *ARGV if find_executable
- Dir.chdir("..") do
- # Recurse in a chdir block: if the search fails we want to be sure
- # the application is generated in the original working directory.
- exec_app_rails unless cwd == Dir.pwd
- end
+ exec RUBY, exe, *ARGV
# This is a Bundler binstub. Stop and explain how to upgrade.
elsif exe =~ /bin\/rails$/ && contents =~ /This file was generated by Bundler/
@@ -59,10 +59,5 @@ generate it and add it to source control:
EXECUTABLES.find { |exe| File.exists?(exe) }
end
- def self.find_executable_in_parent_path(path = Pathname.new(Dir.pwd).parent)
- EXECUTABLES.find do |exe|
- File.exists?(exe) || !path.root? && find_executable_in_parent_path(path.parent)
- end
- end
end
end
diff --git a/railties/test/app_rails_loader_test.rb b/railties/test/app_rails_loader_test.rb
index 63ed9eaef0..0402989705 100644
--- a/railties/test/app_rails_loader_test.rb
+++ b/railties/test/app_rails_loader_test.rb
@@ -17,14 +17,14 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
test "is not in a rails application if #{exe} exists but doesn't contain APP_PATH" do
File.stubs(:exists?).with(exe).returns(true)
File.stubs(:read).with(exe).returns("railties #{exe}")
- assert !Rails::AppRailsLoader.find_executable
+ assert !Rails::AppRailsLoader.exec_app_rails
end
test "is in a rails application if parent directory has #{exe} containing APP_PATH" do
File.stubs(:exists?).with("/foo/bar/#{exe}").returns(false)
File.stubs(:exists?).with("/foo/#{exe}").returns(true)
File.stubs(:read).with("/foo/#{exe}").returns('APP_PATH')
- assert Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar"))
+ assert_equal Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar")), "/foo/#{exe}"
end
test "is not in a rails application if at the root directory and doesn't have #{exe}" do
@@ -36,7 +36,7 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
File.stubs(:exists?).with("/foo/bar/#{exe}").returns(false)
File.stubs(:exists?).with("/foo/#{exe}").returns(true)
File.stubs(:read).with("/foo/#{exe}").returns('ENGINE_PATH')
- assert Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar"))
+ assert Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar")), "/foo/#{exe}"
end
test "is in a rails engine if #{exe} exists containing ENGINE_PATH" do