1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/app_rails_loader_test.rb

41 lines
1.9 KiB
Ruby

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?
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
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 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 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?
end
end