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

Module#parent_name broken for frozen classes #27713

Merged
merged 1 commit into from Jan 18, 2017

Conversation

@coreyward
Copy link
Contributor

@coreyward coreyward commented Jan 17, 2017

Previously memoization inside of Module.parent_name resulted in a runtime error when called for the first time on a frozen module. This patch adds a regression test and refactors the method to resolve the issue.

Note: introspection tests were previously lumped into test/core_ext/module_test.rb despite the code having been extracted to core_exts/module/introspection.rb. I isolated the tests similarly, following convention (e.g., core_exts/module/anonymous.rb to test/core_ext/module/anonymous_test.rb). In the process, I removed some old (over 10 years) setup objects that were no longer being referenced.

@rails-bot
Copy link

@rails-bot rails-bot commented Jan 17, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (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.

@maclover7
Copy link
Member

@maclover7 maclover7 commented Jan 17, 2017

ref #27637

Copy link
Member

@maclover7 maclover7 left a comment

Can you squash down to one commit? Otherwise looks good to me. Thanks for working on this!

@coreyward coreyward force-pushed the coreyward:module_freeze_parent_name branch Jan 17, 2017
@coreyward
Copy link
Contributor Author

@coreyward coreyward commented Jan 17, 2017

Done!

activesupport/lib/active_support/core_ext/module/introspection.rb Outdated
else
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
end
return @parent_name if defined?(@parent_name)

This comment has been minimized.

@rafaelfranca

rafaelfranca Jan 18, 2017
Member

Can we keep the if/else where. We prefer it over short-circuit returns.

@coreyward coreyward force-pushed the coreyward:module_freeze_parent_name branch Jan 18, 2017
@coreyward coreyward force-pushed the coreyward:module_freeze_parent_name branch to 1d3ddac Jan 18, 2017
@coreyward
Copy link
Contributor Author

@coreyward coreyward commented Jan 18, 2017

@rafaelfranca Updated to reflect your concerns.

Cheers!

@rafaelfranca rafaelfranca merged commit 5ac8af2 into rails:master Jan 18, 2017
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
codeclimate no new or fixed issues
Details
@coreyward coreyward deleted the coreyward:module_freeze_parent_name branch Jan 18, 2017
rafaelfranca added a commit that referenced this pull request Jan 18, 2017
Module#parent_name broken for frozen classes
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Jan 18, 2017

Backported 9f4fc67

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