diff options
author | Anton Khamets <colorfulfool@gmail.com> | 2017-08-13 01:23:17 +0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2017-08-12 18:23:17 -0400 |
commit | e6c310b3f8144e9e08bc20a16d9889974d890030 (patch) | |
tree | b05891804e5a20234cbe42d4ea9ab042b3015012 /activesupport/lib/active_support/core_ext/module | |
parent | 98360a96cc1e0bb6ab9eb31f421a36439e66eefc (diff) | |
download | rails-e6c310b3f8144e9e08bc20a16d9889974d890030.tar.gz rails-e6c310b3f8144e9e08bc20a16d9889974d890030.tar.bz2 rails-e6c310b3f8144e9e08bc20a16d9889974d890030.zip |
Test for the new exception of delegate_missing_to (#30191)
* Add test for the new exception of delegate_missing_to
* Add a changelog entry
* Only check for nil if NoMethodError was raised
* Make method private
* Have to pass both target name and value
* Inline the re-raise
[Rafael Mendonça França + Anton Khamets]
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index c979af9de3..1840dc942f 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -273,10 +273,16 @@ class Module def method_missing(method, *args, &block) if #{target}.respond_to?(method) #{target}.public_send(method, *args, &block) - elsif #{target}.nil? - raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil" else - super + begin + super + rescue NoMethodError + if #{target}.nil? + raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil" + else + raise + end + end end end RUBY |