mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
c5a9c02e01
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.
48 lines
1.9 KiB
Ruby
48 lines
1.9 KiB
Ruby
require 'abstract_unit'
|
|
require 'rails/app_rails_loader'
|
|
|
|
class AppRailsLoaderTest < ActiveSupport::TestCase
|
|
|
|
setup do
|
|
File.stubs(:exists?).returns(false)
|
|
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 #{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 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 #{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
|