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

Test for the new exception of delegate_missing_to #30191

Merged
merged 6 commits into from Aug 12, 2017

Conversation

@colorfulfool
Copy link
Contributor

@colorfulfool colorfulfool commented Aug 11, 2017

A follow-up to the change to delegate_missing_to made in #30084.

@rails-bot
Copy link

@rails-bot rails-bot commented Aug 11, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

colorfulfool
Copy link
Member

@rafaelfranca rafaelfranca left a comment

Based on @matthewd's comment in the original PR, can you change the implementation to only check for nil if super raises NoMethodError?

@colorfulfool
Copy link
Contributor Author

@colorfulfool colorfulfool commented Aug 11, 2017

Done. I didn't go this way initially because the code turns out not pretty. Is there a better way to write it?

end
def delegation_error_if_target_nil(target, method)
begin

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 11, 2017
Member

You can remove the begin here.

end
end
def delegation_error_if_target_nil(target, method)

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 11, 2017
Member

This method should be private, and starts with _ to avoid conflicts with the methods in the including class.

This comment has been minimized.

@gsamokovarov

gsamokovarov Aug 11, 2017
Contributor

Should we extract the method at all, we're still monkey patching a core object here. Any pollution counts.

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 11, 2017
Member

Yeah, I don't think it is necessary. begin/end inside that else is good enough.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 11, 2017

I think that is fine

@colorfulfool colorfulfool force-pushed the colorfulfool:delegate-missing-to-test branch Aug 11, 2017
colorfulfool
@colorfulfool colorfulfool force-pushed the colorfulfool:delegate-missing-to-test branch to 632611a Aug 11, 2017
@colorfulfool
Copy link
Contributor Author

@colorfulfool colorfulfool commented Aug 11, 2017

Is delegate_missing_to meant to be used multiple times on the same class? If not, I can eliminate most of _delegation_error_if_target_nil arguments.

I'd say it isn't, because you can instead do

delegate_missing_to :person_responsible

def person_responsible
  president || chief || captain
end
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 11, 2017

It is not, because only the last call is going to be used.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 11, 2017

I think we can go with the version without the private method just to avoid polluting the caller more

colorfulfool
@rafaelfranca rafaelfranca merged commit e6c310b into rails:master Aug 12, 2017
2 checks passed
2 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 12, 2017

This is amazing. Thank you for doing this.

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

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.