mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
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
This commit is contained in:
@@ -1308,7 +1308,6 @@ MSG
|
||||
rescue NameError => e
|
||||
# We don't want to swallow NoMethodError < NameError errors
|
||||
raise e unless e.instance_of?(NameError)
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1766,6 +1766,13 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_compute_type_argument_error
|
||||
ActiveSupport::Dependencies.stubs(:constantize).raises(ArgumentError)
|
||||
assert_raises ArgumentError do
|
||||
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
||||
end
|
||||
end
|
||||
|
||||
def test_clear_cache!
|
||||
# preheat cache
|
||||
c1 = Post.columns
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user