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 #51463] Raise an error when invalid :on
or :except
options are given to #resource
or #resources
#51464
base: main
Are you sure you want to change the base?
Conversation
:on
or :except
options are given to #resource or #resouces:on
or :except
options are given to #resource
or #resouces
f0fb46c
to
ad8ac7b
Compare
475d14a
to
8b6140c
Compare
:on
or :except
options are given to #resource
or #resouces
:on
or :except
options are given to #resource
or #resources
4a6ac93
to
fc2da04
Compare
Hmm the test failures are scenarios where the scope's Addressed in these changes. |
…ons are given to `#resource` or `#resources`
fc2da04
to
a0d7574
Compare
attr_reader :controller, :path, :param | ||
|
||
def initialize(entities, api_only, shallow, options = {}) | ||
if options[:param].to_s.include?(":") | ||
raise ArgumentError, ":param option can't contain colons" | ||
end | ||
|
||
if (invalid_actions = (options.values_at(:only, :except).flatten.compact - default_actions)).any? | ||
raise ArgumentError, "expected :only and :except to be one or more of #{default_actions}, got #{invalid_actions}" | ||
end |
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.
The method assert_valid_keys
would be a better approach as it's used elsewhere within Rails to perform the same task, e.g.
rails/actionview/lib/action_view/helpers/output_safety_helper.rb
Lines 43 to 50 in 778039b
def to_sentence(array, options = {}) | |
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) | |
default_connectors = { | |
words_connector: ", ", | |
two_words_connector: " and ", | |
last_word_connector: ", and " | |
} |
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.
I don't think it works here since we're asserting the values and not the keys.
Motivation / Background
Fixes #51463.
Detail
Raises an
ArgumentError
when aActionDispatch::Routing::Mapper::Resources::Resource
is initalized with:on
or:except
options that aren't default (index, create, new, show, update, and destroy) actions .Additional information
See my comment below as to why this seems like more changes than it needs to be.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]