File tree Expand file tree Collapse file tree 4 files changed +56
-19
lines changed Expand file tree Collapse file tree 4 files changed +56
-19
lines changed Original file line number Diff line number Diff line change 1+ *Rails 3.0.0 [Release Candidate] (unreleased)*
2+
3+ * Made the rails command work even when you're in a subdirectory [Chad Fowler]
4+
5+
16*Rails 3.0.0 [beta 4] (June 8th, 2010)*
27
38* Version bump
Original file line number Diff line number Diff line change 11require 'rbconfig'
2-
3- module Rails
4- module ScriptRailsLoader
5- RUBY = File . join ( *RbConfig ::CONFIG . values_at ( "bindir" , "ruby_install_name" ) ) + RbConfig ::CONFIG [ "EXEEXT" ]
6- SCRIPT_RAILS = File . join ( 'script' , 'rails' )
7-
8- def self . exec_script_rails!
9- cwd = Dir . pwd
10- exec RUBY , SCRIPT_RAILS , *ARGV if File . exists? ( SCRIPT_RAILS )
11- Dir . chdir ( ".." ) do
12- # Recurse in a chdir block: if the search fails we want to be sure
13- # the application is generated in the original working directory.
14- exec_script_rails! unless cwd == Dir . pwd
15- end
16- rescue SystemCallError
17- # could not chdir, no problem just return
18- end
19- end
20- end
2+ require 'rails/script_rails_loader'
213
224Rails ::ScriptRailsLoader . exec_script_rails!
235
Original file line number Diff line number Diff line change 1+ require 'pathname'
2+
3+ module Rails
4+ module ScriptRailsLoader
5+ RUBY = File . join ( *RbConfig ::CONFIG . values_at ( "bindir" , "ruby_install_name" ) ) + RbConfig ::CONFIG [ "EXEEXT" ]
6+ SCRIPT_RAILS = File . join ( 'script' , 'rails' )
7+
8+ def self . exec_script_rails!
9+ cwd = Dir . pwd
10+ exec RUBY , SCRIPT_RAILS , *ARGV if in_rails_application?
11+ Dir . chdir ( ".." ) do
12+ # Recurse in a chdir block: if the search fails we want to be sure
13+ # the application is generated in the original working directory.
14+ exec_script_rails! unless cwd == Dir . pwd
15+ end
16+ rescue SystemCallError
17+ # could not chdir, no problem just return
18+ end
19+
20+ def self . in_rails_application?
21+ File . exists? ( SCRIPT_RAILS ) || in_rails_application_subdirectory?
22+ end
23+
24+ def self . in_rails_application_subdirectory? ( path = Pathname . new ( Dir . pwd ) )
25+ File . exists? ( File . join ( path , SCRIPT_RAILS ) ) || !path . root? && in_rails_application_subdirectory? ( path . parent )
26+ end
27+ end
28+ end
Original file line number Diff line number Diff line change 1+ require 'abstract_unit'
2+ require 'rails/script_rails_loader'
3+
4+ class ScriptRailsLoaderTest < ActiveSupport ::TestCase
5+
6+ test "is in a rails application if script/rails exists" do
7+ File . stubs ( :exists? ) . returns ( true )
8+ assert Rails ::ScriptRailsLoader . in_rails_application?
9+ end
10+
11+ test "is in a rails application if parent directory has script/rails" do
12+ File . stubs ( :exists? ) . with ( "/foo/bar/script/rails" ) . returns ( false )
13+ File . stubs ( :exists? ) . with ( "/foo/script/rails" ) . returns ( true )
14+ assert Rails ::ScriptRailsLoader . in_rails_application_subdirectory? ( Pathname . new ( "/foo/bar" ) )
15+ end
16+
17+ test "is not in a rails application if at the root directory and doesn't have script/rails" do
18+ Pathname . any_instance . stubs ( :root? ) . returns true
19+ assert !Rails ::ScriptRailsLoader . in_rails_application?
20+ end
21+
22+ end
You can’t perform that action at this time.
0 commit comments