From cf3364a03c665374f6419a8875474ebf8623ea67 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 1 Jun 2011 01:05:17 +0100 Subject: Raise NameError instead of ArgumentError in ActiveSupport::Dependencies ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. Closes #1423 --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/dependencies.rb | 2 +- activesupport/test/dependencies_test.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index bf48306684..6b7044aeae 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -7,6 +7,8 @@ *Rails 3.1.0 (unreleased)* +* ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White] + * Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton] * New reporting method Kernel#quietly. [fxn] diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index cae68c3c95..26c5c157cb 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -473,7 +473,7 @@ module ActiveSupport #:nodoc: raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" end - raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name) + raise NameError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name) qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 2ddbce5150..b4edf0f51d 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -441,7 +441,7 @@ class DependenciesTest < Test::Unit::TestCase with_autoloading_fixtures do require_dependency '././counting_loader' assert_equal 1, $counting_loaded_times - assert_raise(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader } + assert_raise(NameError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader } assert_equal 1, $counting_loaded_times end end -- cgit v1.2.3