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

81 lines
2.2 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
class TestAutoloadModule < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
module ::Fixtures
extend ActiveSupport::Autoload
module Autoload
extend ActiveSupport::Autoload
end
end
2014-10-05 11:58:33 -04:00
def setup
@some_class_path = File.expand_path("test/fixtures/autoload/some_class.rb")
@another_class_path = File.expand_path("test/fixtures/autoload/another_class.rb")
end
test "the autoload module works like normal autoload" do
module ::Fixtures::Autoload
autoload :SomeClass, "fixtures/autoload/some_class"
end
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
test "when specifying an :eager constant it still works like normal autoload by default" do
module ::Fixtures::Autoload
2014-10-05 11:58:33 -04:00
eager_autoload do
autoload :SomeClass, "fixtures/autoload/some_class"
end
end
2014-10-05 11:58:33 -04:00
assert !$LOADED_FEATURES.include?(@some_class_path)
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
test "the location of autoloaded constants defaults to :name.underscore" do
module ::Fixtures::Autoload
autoload :SomeClass
end
2014-10-05 11:58:33 -04:00
assert !$LOADED_FEATURES.include?(@some_class_path)
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
test "the location of :eager autoloaded constants defaults to :name.underscore" do
module ::Fixtures::Autoload
2014-10-05 11:58:33 -04:00
eager_autoload do
autoload :SomeClass
end
end
2014-10-05 11:58:33 -04:00
assert !$LOADED_FEATURES.include?(@some_class_path)
::Fixtures::Autoload.eager_load!
2014-10-05 11:58:33 -04:00
assert $LOADED_FEATURES.include?(@some_class_path)
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
test "a directory for a block of autoloads can be specified" do
module ::Fixtures
autoload_under "autoload" do
autoload :AnotherClass
end
end
2014-10-05 11:58:33 -04:00
assert !$LOADED_FEATURES.include?(@another_class_path)
assert_nothing_raised { ::Fixtures::AnotherClass }
end
test "a path for a block of autoloads can be specified" do
module ::Fixtures
autoload_at "fixtures/autoload/another_class" do
autoload :AnotherClass
end
end
2014-10-05 11:58:33 -04:00
assert !$LOADED_FEATURES.include?(@another_class_path)
assert_nothing_raised { ::Fixtures::AnotherClass }
end
end