aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2014-10-25 13:50:42 +0200
committerXavier Noria <fxn@hashref.com>2014-10-25 14:06:33 +0200
commitae07806858072cd66611c165d1eed2a113e639e5 (patch)
treeb8c5622a88dc410ffa4eeb7076b01610e93dd324 /activesupport/test
parentc4767e13d4ae927e6d605cad3846c9807745b883 (diff)
downloadrails-ae07806858072cd66611c165d1eed2a113e639e5.tar.gz
rails-ae07806858072cd66611c165d1eed2a113e639e5.tar.bz2
rails-ae07806858072cd66611c165d1eed2a113e639e5.zip
fixes circularity check in dependencies
The check for circular loading should depend on a stack of files being loaded at the moment, rather than the collection of loaded files. This showed up indirectly in #16468, where a misspelled helper would incorrectly result in a circularity error message. References #16468
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/autoloading_fixtures/typo.rb2
-rw-r--r--activesupport/test/dependencies_test.rb25
-rw-r--r--activesupport/test/dependencies_test_helpers.rb1
3 files changed, 28 insertions, 0 deletions
diff --git a/activesupport/test/autoloading_fixtures/typo.rb b/activesupport/test/autoloading_fixtures/typo.rb
new file mode 100644
index 0000000000..8e047f5fd4
--- /dev/null
+++ b/activesupport/test/autoloading_fixtures/typo.rb
@@ -0,0 +1,2 @@
+TypO = 1
+
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 899bb75eae..f2f60167c4 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -157,6 +157,31 @@ class DependenciesTest < ActiveSupport::TestCase
end
end
+ def test_ensures_the_expected_constant_is_defined
+ with_autoloading_fixtures do
+ e = assert_raise(LoadError) { Typo }
+ assert_match %r{Unable to autoload constant Typo, expected .*activesupport/test/autoloading_fixtures/typo.rb to define it}, e.message
+ end
+ end
+
+ def test_require_dependency_does_not_assume_any_particular_constant_is_defined
+ with_autoloading_fixtures do
+ require_dependency 'typo'
+ assert_equal 1, TypO
+ end
+ end
+
+ # Regression, see https://github.com/rails/rails/issues/16468.
+ def test_require_dependency_interaction_with_autoloading
+ with_autoloading_fixtures do
+ require_dependency 'typo'
+ assert_equal 1, TypO
+
+ e = assert_raise(LoadError) { Typo }
+ assert_match %r{Unable to autoload constant Typo, expected .*activesupport/test/autoloading_fixtures/typo.rb to define it}, e.message
+ end
+ end
+
def test_module_loading
with_autoloading_fixtures do
assert_kind_of Module, A
diff --git a/activesupport/test/dependencies_test_helpers.rb b/activesupport/test/dependencies_test_helpers.rb
index 9268512a97..e4d5197112 100644
--- a/activesupport/test/dependencies_test_helpers.rb
+++ b/activesupport/test/dependencies_test_helpers.rb
@@ -13,6 +13,7 @@ module DependenciesTestHelpers
ActiveSupport::Dependencies.autoload_paths = prior_autoload_paths
ActiveSupport::Dependencies.mechanism = old_mechanism
ActiveSupport::Dependencies.explicitly_unloadable_constants = []
+ ActiveSupport::Dependencies.clear
end
def with_autoloading_fixtures(&block)