aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector/methods.rb
diff options
context:
space:
mode:
authorKeenan Brock <keenan@thebrocks.net>2019-01-07 14:13:45 -0500
committerKeenan Brock <keenan@thebrocks.net>2019-01-09 14:52:46 -0500
commita930f5ba0654e8c8c7ac7b3febbb573d03559a40 (patch)
treeeb61061ebddf53c0f41b40b04a563cc9bc664121 /activesupport/lib/active_support/inflector/methods.rb
parent9f1a07af0499080c9fd8815705a03a4c7e8fb506 (diff)
downloadrails-a930f5ba0654e8c8c7ac7b3febbb573d03559a40.tar.gz
rails-a930f5ba0654e8c8c7ac7b3febbb573d03559a40.tar.bz2
rails-a930f5ba0654e8c8c7ac7b3febbb573d03559a40.zip
Fix safe_constantize to not raise a LoadError.
### Summary There was an issues when using `safe_constantize` on a string that has the wrong case. File `em.rb` defines `EM`. `"Em".safe_constantize` causes a little confusion with the autoloader. The autoloader finds file "em.rb", expecting it to define `Em`, but `Em` is not defined. The autoloader raises a `LoadError`, which is good, But `safe_constantize` is defined to return `nil` when a class is not found. ### Before ``` "Em".safe_constantize LoadError: Unable to autoload constant Em, \ expected rails/activesupport/test/autoloading_fixtures/em.rb to define it ``` ### After ``` "Em".safe_constantize # => nil ```
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 1af9833d46..ee193add6f 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -328,6 +328,8 @@ module ActiveSupport
e.name.to_s == camel_cased_word.to_s)
rescue ArgumentError => e
raise unless /not missing constant #{const_regexp(camel_cased_word)}!$/.match?(e.message)
+ rescue LoadError => e
+ raise unless /Unable to autoload constant #{const_regexp(camel_cased_word)}/.match?(e.message)
end
# Returns the suffix that should be added to a number to denote the position