aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-08-17 03:35:36 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-08-17 03:35:36 +0000
commit924ef18d4bf8f82c18b8362f3e7aab9e60ba5826 (patch)
tree7d904eff924f2dcb67c7134688ce08493a5f5b23 /activesupport
parent2b37d59976268013b7e518e5af244947f688d315 (diff)
downloadrails-924ef18d4bf8f82c18b8362f3e7aab9e60ba5826.tar.gz
rails-924ef18d4bf8f82c18b8362f3e7aab9e60ba5826.tar.bz2
rails-924ef18d4bf8f82c18b8362f3e7aab9e60ba5826.zip
Detect missing_constants calls from removed modules and fail accordingly.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4780 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/dependencies.rb4
-rw-r--r--activesupport/test/dependencies_test.rb15
3 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 485e8edc83..b1bba4055c 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Detect missing_constants calls from removed modules and fail accordingly. [Nicholas Seckar]
+
* Stop using defined? in Dependencies.qualified_const_defined? since defined? may invoke const_missing. [Nicholas Seckar]
* Dependencies can autoload directories of nested classes. [Jeremy Kemper]
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 5f3c35839b..2d1649d22c 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -182,6 +182,10 @@ module Dependencies #:nodoc:
# If we have an anonymous module, all we can do is attempt to load from Object.
from_mod = Object if from_mod.name.empty?
+ unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id
+ raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
+ end
+
raise ArgumentError, "Expected #{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)
qualified_name = qualified_name_for from_mod, const_name
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index f043bbd438..f969a30891 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -372,4 +372,19 @@ class DependenciesTest < Test::Unit::TestCase
end
end
+ def test_removal_from_tree_should_be_detected
+ with_loading 'dependencies' do
+ root = Dependencies.autoload_paths.first
+ c = ServiceOne
+ Dependencies.clear
+ assert ! defined?(ServiceOne)
+ begin
+ Dependencies.load_missing_constant(c, :FakeMissing)
+ flunk "Expected exception"
+ rescue ArgumentError => e
+ assert_match %r{ServiceOne has been removed from the module tree}i, e.message
+ end
+ end
+ end
+
end