diff options
author | Steve Klabnik <steve@steveklabnik.com> | 2013-02-22 14:09:43 -0500 |
---|---|---|
committer | Steve Klabnik <steve@steveklabnik.com> | 2013-02-22 14:30:21 -0500 |
commit | c5a9c02e01040831f7e00d3dfa0cfe423f7eb1f9 (patch) | |
tree | 02440fd4138684d5af38c7a12ff5e44f14183746 /railties/test | |
parent | 31f807c7aaaf12c16ea1572559c00f49d54d6f43 (diff) | |
download | rails-c5a9c02e01040831f7e00d3dfa0cfe423f7eb1f9.tar.gz rails-c5a9c02e01040831f7e00d3dfa0cfe423f7eb1f9.tar.bz2 rails-c5a9c02e01040831f7e00d3dfa0cfe423f7eb1f9.zip |
Fix backwards compatibility with Rails 3 apps.
When we removed script/rails and introduced bin/rails, we accidentally
introduced a regression. If you install Rails 4 as a gem, then try to do
something in a Rails 3 application:
$ rails g
This will throw the 'please type rails new foo' message rather than the
proper generator documentation message. This is because older apps don't
have bin/rails.
Therefore, we now *prefer* bin/rails, but still search for script/rails,
and exec the one we find.
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/app_rails_loader_test.rb | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/railties/test/app_rails_loader_test.rb b/railties/test/app_rails_loader_test.rb index 87e0ad7bd7..63ed9eaef0 100644 --- a/railties/test/app_rails_loader_test.rb +++ b/railties/test/app_rails_loader_test.rb @@ -2,40 +2,47 @@ require 'abstract_unit' require 'rails/app_rails_loader' class AppRailsLoaderTest < ActiveSupport::TestCase - test "is in a rails application if bin/rails exists and contains APP_PATH" do - File.stubs(:exists?).returns(true) - File.stubs(:read).with('bin/rails').returns('APP_PATH') - assert Rails::AppRailsLoader.in_rails_application_or_engine? - end - test "is not in a rails application if bin/rails exists but doesn't contain APP_PATH" do - File.stubs(:exists?).returns(true) - File.stubs(:read).with('bin/rails').returns('railties bin/rails') - assert !Rails::AppRailsLoader.in_rails_application_or_engine? + setup do + File.stubs(:exists?).returns(false) end - test "is in a rails application if parent directory has bin/rails containing APP_PATH" do - File.stubs(:exists?).with("/foo/bar/bin/rails").returns(false) - File.stubs(:exists?).with("/foo/bin/rails").returns(true) - File.stubs(:read).with('/foo/bin/rails').returns('APP_PATH') - assert Rails::AppRailsLoader.in_rails_application_or_engine_subdirectory?(Pathname.new("/foo/bar")) - end + ['bin/rails', 'script/rails'].each do |exe| + test "is in a rails application if #{exe} exists and contains APP_PATH" do + File.stubs(:exists?).with(exe).returns(true) + File.stubs(:read).with(exe).returns('APP_PATH') + assert Rails::AppRailsLoader.find_executable + end - test "is not in a rails application if at the root directory and doesn't have bin/rails" do - Pathname.any_instance.stubs(:root?).returns true - assert !Rails::AppRailsLoader.in_rails_application_or_engine? - end + 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 + end - test "is in a rails engine if parent directory has bin/rails containing ENGINE_PATH" do - File.stubs(:exists?).with("/foo/bar/bin/rails").returns(false) - File.stubs(:exists?).with("/foo/bin/rails").returns(true) - File.stubs(:read).with('/foo/bin/rails').returns('ENGINE_PATH') - assert Rails::AppRailsLoader.in_rails_application_or_engine_subdirectory?(Pathname.new("/foo/bar")) - 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")) + end + + test "is not in a rails application if at the root directory and doesn't have #{exe}" do + Pathname.any_instance.stubs(:root?).returns true + assert !Rails::AppRailsLoader.find_executable + end + + test "is in a rails engine if parent directory has #{exe} containing ENGINE_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('ENGINE_PATH') + assert Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar")) + end - test "is in a rails engine if bin/rails exists containing ENGINE_PATH" do - File.stubs(:exists?).returns(true) - File.stubs(:read).with('bin/rails').returns('ENGINE_PATH') - assert Rails::AppRailsLoader.in_rails_application_or_engine? + test "is in a rails engine if #{exe} exists containing ENGINE_PATH" do + File.stubs(:exists?).with(exe).returns(true) + File.stubs(:read).with(exe).returns('ENGINE_PATH') + assert Rails::AppRailsLoader.find_executable + end end end |