Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rescue_from subclasses default #651

Closed

Conversation

xevix
Copy link
Contributor

@xevix xevix commented May 23, 2014

This fixes rescue_from to properly set rescue_subclasses to true by default, as per the documentation. This was brought up in #649

Because it was defaulting to false, all other unit tests that involved rescuing (such as rescue_from :all and rescuing from a given block) were passing, but when the default was properly set to true, some of them broke. In other words, it exposed a bug in a combination of rescue_subclasses set to true in combination with rescue_from :all and rescuing using a given block as a handler. This has been fixed as well.

Added a unit test to ensure that by default, subclasses are rescued from (i.e., code behaves as if rescue_subclasses is true).

@@ -214,7 +214,13 @@ def rescue_from(*args, &block)
options = args.last.is_a?(Hash) ? args.pop : {}
handler ||= proc { options[:with] } if options.key?(:with)

handler_type = !!options[:rescue_subclasses] ? :rescue_handlers : :base_only_rescue_handlers
handler_type =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock The !! trick works when you want nil, false but since we want nil, true I ended up with a case statement. Do you know of a prettier more idiomatic way of doing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is totally fine.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just swap it around (nil != false):

handler_type = options[:rescue_subclasses] == false ? :base_only_rescue_handlers : :rescue_handlers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrianmacneil Yeah that would do the trick, thanks for the suggestion. In this case I'll stick with the case as it reads a bit clearer.

@dblock
Copy link
Member

dblock commented May 23, 2014

This really needs a CHANGELOG entry, please.

@xevix
Copy link
Contributor Author

xevix commented May 26, 2014

@dblock Separated the handler that rescues from all so it's less obscure. Added CHANGELOG.

@dblock
Copy link
Member

dblock commented May 26, 2014

Merged via f55e55f. I also added an integration test at API level.

@dblock dblock closed this May 26, 2014
@dblock
Copy link
Member

dblock commented May 26, 2014

This is good work, thanks much.

@xevix
Copy link
Contributor Author

xevix commented May 27, 2014

@dblock Thanks for CC'ing me, adding the integration test and the quick merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants