Skip to content
This repository
Browse code

safe_constantize should handle wrong constant name NameErrors Fixes #…

…4710

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 6c367a0d787705746f262d0bd5ad8c4f13a8c809 1 parent 70cbb1c
Alex Tambellini authored January 26, 2012 josevalim committed January 26, 2012
2  activesupport/lib/active_support/inflector/methods.rb
@@ -258,7 +258,7 @@ def safe_constantize(camel_cased_word)
258 258
       begin
259 259
         constantize(camel_cased_word)
260 260
       rescue NameError => e
261  
-        raise unless e.message =~ /uninitialized constant #{const_regexp(camel_cased_word)}$/ ||
  261
+        raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
262 262
           e.name.to_s == camel_cased_word.to_s
263 263
       rescue ArgumentError => e
264 264
         raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
5  activesupport/test/constantize_test_cases.rb
@@ -19,7 +19,7 @@ def run_constantize_tests_on
19 19
     assert_raise(NameError) { yield("Ace::ConstantizeTestCases") }
20 20
     assert_raise(NameError) { yield("Ace::Base::ConstantizeTestCases") }
21 21
   end
22  
-  
  22
+
23 23
   def run_safe_constantize_tests_on
24 24
     assert_nothing_raised { assert_equal Ace::Base::Case, yield("Ace::Base::Case") }
25 25
     assert_nothing_raised { assert_equal Ace::Base::Case, yield("::Ace::Base::Case") }
@@ -33,5 +33,6 @@ def run_safe_constantize_tests_on
33 33
     assert_nothing_raised { assert_equal nil, yield("blargle") }
34 34
     assert_nothing_raised { assert_equal nil, yield("Ace::ConstantizeTestCases") }
35 35
     assert_nothing_raised { assert_equal nil, yield("Ace::Base::ConstantizeTestCases") }
  36
+    assert_nothing_raised { assert_equal nil, yield("#<Class:0x7b8b718b>::Nested_1") }
36 37
   end
37  
-end
  38
+end

0 notes on commit 6c367a0

Please sign in to comment.
Something went wrong with that request. Please try again.