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

Projects
None yet
5 participants
@coreyward
Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Member

maclover7 commented Jan 17, 2017

ref #27637

@maclover7

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

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

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

Merge pull request #27713 from coreyward/module_freeze_parent_name
Module#parent_name broken for frozen classes
@rafaelfranca

This comment has been minimized.

Member

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