diff options
Diffstat (limited to 'railties/test/app_rails_loader_test.rb')
-rw-r--r-- | railties/test/app_rails_loader_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/railties/test/app_rails_loader_test.rb b/railties/test/app_rails_loader_test.rb new file mode 100644 index 0000000000..87e0ad7bd7 --- /dev/null +++ b/railties/test/app_rails_loader_test.rb @@ -0,0 +1,41 @@ +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 |