aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/autoload.rb80
-rw-r--r--activesupport/test/fixtures/autoload/another_class.rb2
-rw-r--r--activesupport/test/fixtures/autoload/some_class.rb2
3 files changed, 84 insertions, 0 deletions
diff --git a/activesupport/test/autoload.rb b/activesupport/test/autoload.rb
new file mode 100644
index 0000000000..5d8026a9ca
--- /dev/null
+++ b/activesupport/test/autoload.rb
@@ -0,0 +1,80 @@
+require 'abstract_unit'
+
+class TestAutoloadModule < ActiveSupport::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ module ::Fixtures
+ extend ActiveSupport::Autoload
+
+ module Autoload
+ extend ActiveSupport::Autoload
+ end
+ 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
+ autoload :SomeClass, "fixtures/autoload/some_class"
+ end
+
+ assert !$LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
+ assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
+ end
+
+ test ":eager constants can be triggered via ActiveSupport::Autoload.eager_autoload!" do
+ module ::Fixtures::Autoload
+ autoload :SomeClass, "fixtures/autoload/some_class"
+ end
+ ActiveSupport::Autoload.eager_autoload!
+ assert $LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
+ assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
+ end
+
+ test "the location of autoloaded constants defaults to :name.underscore" do
+ module ::Fixtures::Autoload
+ autoload :SomeClass
+ end
+
+ assert !$LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
+ assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
+ end
+
+ test "the location of :eager autoloaded constants defaults to :name.underscore" do
+ module ::Fixtures::Autoload
+ autoload :SomeClass
+ end
+
+ ActiveSupport::Autoload.eager_autoload!
+ assert $LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
+ 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
+
+ assert !$LOADED_FEATURES.include?("fixtures/autoload/another_class.rb")
+ 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
+
+ assert !$LOADED_FEATURES.include?("fixtures/autoload/another_class.rb")
+ assert_nothing_raised { ::Fixtures::AnotherClass }
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/fixtures/autoload/another_class.rb b/activesupport/test/fixtures/autoload/another_class.rb
new file mode 100644
index 0000000000..a240b3de41
--- /dev/null
+++ b/activesupport/test/fixtures/autoload/another_class.rb
@@ -0,0 +1,2 @@
+class Fixtures::AnotherClass
+end \ No newline at end of file
diff --git a/activesupport/test/fixtures/autoload/some_class.rb b/activesupport/test/fixtures/autoload/some_class.rb
new file mode 100644
index 0000000000..13b3c73ef5
--- /dev/null
+++ b/activesupport/test/fixtures/autoload/some_class.rb
@@ -0,0 +1,2 @@
+class Fixtures::Autoload::SomeClass
+end \ No newline at end of file