1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

safe_constantize should handle wrong constant name NameErrors Fixes #4710

This commit is contained in:
Alex Tambellini 2012-01-26 14:19:49 -05:00
parent 82ba5c469f
commit 7598284c0b
2 changed files with 4 additions and 3 deletions

View file

@ -243,7 +243,7 @@ module ActiveSupport
begin
constantize(camel_cased_word)
rescue NameError => e
raise unless e.message =~ /uninitialized constant #{const_regexp(camel_cased_word)}$/ ||
raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
e.name.to_s == camel_cased_word.to_s
rescue ArgumentError => e
raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/

View file

@ -19,7 +19,7 @@ module ConstantizeTestCases
assert_raise(NameError) { yield("Ace::ConstantizeTestCases") }
assert_raise(NameError) { yield("Ace::Base::ConstantizeTestCases") }
end
def run_safe_constantize_tests_on
assert_nothing_raised { assert_equal Ace::Base::Case, yield("Ace::Base::Case") }
assert_nothing_raised { assert_equal Ace::Base::Case, yield("::Ace::Base::Case") }
@ -33,5 +33,6 @@ module ConstantizeTestCases
assert_nothing_raised { assert_equal nil, yield("blargle") }
assert_nothing_raised { assert_equal nil, yield("Ace::ConstantizeTestCases") }
assert_nothing_raised { assert_equal nil, yield("Ace::Base::ConstantizeTestCases") }
assert_nothing_raised { assert_equal nil, yield("#<Class:0x7b8b718b>::Nested_1") }
end
end
end