-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
Support setting parent_controller #903
Open
jaynetics
wants to merge
2
commits into
activeadmin:master
Choose a base branch
from
jaynetics:support-setting-parent-controller
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'test_helper' | ||
|
||
def force_parent_controller(value) | ||
InheritedResources.send(:remove_const, :Base) | ||
InheritedResources.parent_controller = value | ||
load File.join(__dir__, '..', 'app', 'controllers', 'inherited_resources', 'base.rb') | ||
end | ||
|
||
class ParentControllerTest < ActionController::TestCase | ||
def test_setting_parent_controller | ||
original_parent = InheritedResources::Base.superclass | ||
|
||
assert_equal ApplicationController, original_parent | ||
|
||
force_parent_controller('ActionController::Base') | ||
|
||
assert_equal ActionController::Base, InheritedResources::Base.superclass | ||
ensure | ||
force_parent_controller(original_parent.to_s) # restore original parent | ||
jaynetics marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can I ask if this is the same as
https://github.com/heartcombo/devise/blob/a259ff3c28912a27329727f4a3c2623d3f5cb6f2/lib/devise.rb#L244-L245
?
Ref: https://github.com/rails/rails/blob/56fbc632a378acc40d99f5b4be321f80a5d8b8c4/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb#L208-L212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tagliala i'd say its equivalent – the block is evaluated and the class variable is set immediately:
https://github.com/rails/rails/blob/56fbc632a378acc40d99f5b4be321f80a5d8b8c4/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb#L69-L70
i think the devise code is just like that because when José Valim wrote these lines 13 years ago, mattr_accessor did not yet support passing a default value:
https://github.com/rails/rails/blob/bf526c2dbeb73bf11553004e43889a804b72866d/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb#L60