aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG5
-rw-r--r--railties/lib/rails/cli.rb20
-rw-r--r--railties/lib/rails/script_rails_loader.rb28
-rw-r--r--railties/test/script_rails_loader_test.rb22
4 files changed, 56 insertions, 19 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 61924745c8..51bd4abd70 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,3 +1,8 @@
+*Rails 3.0.0 [Release Candidate] (unreleased)*
+
+* Made the rails command work even when you're in a subdirectory [Chad Fowler]
+
+
*Rails 3.0.0 [beta 4] (June 8th, 2010)*
* Version bump
diff --git a/railties/lib/rails/cli.rb b/railties/lib/rails/cli.rb
index 173f122445..d49431919d 100644
--- a/railties/lib/rails/cli.rb
+++ b/railties/lib/rails/cli.rb
@@ -1,23 +1,5 @@
require 'rbconfig'
-
-module Rails
- module ScriptRailsLoader
- RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
- SCRIPT_RAILS = File.join('script', 'rails')
-
- def self.exec_script_rails!
- cwd = Dir.pwd
- exec RUBY, SCRIPT_RAILS, *ARGV if File.exists?(SCRIPT_RAILS)
- 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_script_rails! unless cwd == Dir.pwd
- end
- rescue SystemCallError
- # could not chdir, no problem just return
- end
- end
-end
+require 'rails/script_rails_loader'
Rails::ScriptRailsLoader.exec_script_rails!
diff --git a/railties/lib/rails/script_rails_loader.rb b/railties/lib/rails/script_rails_loader.rb
new file mode 100644
index 0000000000..8fbd3bf492
--- /dev/null
+++ b/railties/lib/rails/script_rails_loader.rb
@@ -0,0 +1,28 @@
+require 'pathname'
+
+module Rails
+ module ScriptRailsLoader
+ RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
+ SCRIPT_RAILS = File.join('script', 'rails')
+
+ def self.exec_script_rails!
+ cwd = Dir.pwd
+ exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
+ 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_script_rails! unless cwd == Dir.pwd
+ end
+ rescue SystemCallError
+ # could not chdir, no problem just return
+ end
+
+ def self.in_rails_application?
+ File.exists?(SCRIPT_RAILS) || in_rails_application_subdirectory?
+ end
+
+ def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
+ File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent)
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/test/script_rails_loader_test.rb b/railties/test/script_rails_loader_test.rb
new file mode 100644
index 0000000000..2a87e5cb58
--- /dev/null
+++ b/railties/test/script_rails_loader_test.rb
@@ -0,0 +1,22 @@
+require 'abstract_unit'
+require 'rails/script_rails_loader'
+
+class ScriptRailsLoaderTest < ActiveSupport::TestCase
+
+ test "is in a rails application if script/rails exists" do
+ File.stubs(:exists?).returns(true)
+ assert Rails::ScriptRailsLoader.in_rails_application?
+ end
+
+ test "is in a rails application if parent directory has script/rails" do
+ File.stubs(:exists?).with("/foo/bar/script/rails").returns(false)
+ File.stubs(:exists?).with("/foo/script/rails").returns(true)
+ assert Rails::ScriptRailsLoader.in_rails_application_subdirectory?(Pathname.new("/foo/bar"))
+ end
+
+ test "is not in a rails application if at the root directory and doesn't have script/rails" do
+ Pathname.any_instance.stubs(:root?).returns true
+ assert !Rails::ScriptRailsLoader.in_rails_application?
+ end
+
+end \ No newline at end of file