aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Tambellini <atambellini@gmail.com>2012-01-26 14:19:49 -0500
committerJosé Valim <jose.valim@gmail.com>2012-01-26 20:52:51 +0100
commit6c367a0d787705746f262d0bd5ad8c4f13a8c809 (patch)
tree9c633afd45ae0e7988ebc536fded126f30570589
parent70cbb1c1cd40ec3a6f48b93a0608b1421965768a (diff)
downloadrails-6c367a0d787705746f262d0bd5ad8c4f13a8c809.tar.gz
rails-6c367a0d787705746f262d0bd5ad8c4f13a8c809.tar.bz2
rails-6c367a0d787705746f262d0bd5ad8c4f13a8c809.zip
safe_constantize should handle wrong constant name NameErrors Fixes #4710
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
-rw-r--r--activesupport/test/constantize_test_cases.rb5
2 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 1dc2e0487f..f47dfba4b0 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -258,7 +258,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)}\!$/
diff --git a/activesupport/test/constantize_test_cases.rb b/activesupport/test/constantize_test_cases.rb
index 81d200a0c8..135f894056 100644
--- a/activesupport/test/constantize_test_cases.rb
+++ b/activesupport/test/constantize_test_cases.rb
@@ -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 \ No newline at end of file
+end