-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Deprecate passing hash as first parameter into ActionController::Head #20407
Deprecate passing hash as first parameter into ActionController::Head #20407
Conversation
Shouldn't the hidden default |
yes |
I've deprecated both; passing hash as first parameter and default status code for this method. I asked this @rafaelfranca and he said deprecate both. |
Shouldn't the status key be deprecated too then? |
I've already deprecated passing |
Ah sorry, I didn't realize the code had been updated more. |
@kaspth no problem bro 😄 what do you think about this pr now? |
msg = "Passing Hash as first parameter" | ||
options, status = status, nil | ||
status ||= options.delete(:status) || ( | ||
(msg += " and default status code") && :ok |
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.
"Passing Hash as first parameter and default status code" doesn't make sense to me. What about and the implicit :ok status has been deprecated.
?
It's okay to not have the code be completely DRY. I'd prefer making this more readable 😄
@kaspth I've updated the pr. |
status ||= options.delete(:status) || ( | ||
(msg += " and the implicit :ok status") && :ok | ||
) | ||
ActiveSupport::Deprecation.warn(msg + " for `head` method has been deprecated and will be removed in Rails 5.1. Please visit http://api.rubyonrails.org/classes/ActionController/Head.html for usage.") |
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.
We should wrap this to 80 chars, right @zzak?
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.
@kaspth there are some deprecation warnings more then 200 line length.
@kaspth I've removed doc link from the deprecation message. |
status ||= options.delete(:status) || ( | ||
(msg += " and the implicit :ok status") && :ok | ||
) | ||
ActiveSupport::Deprecation.warn(msg + " for `head` method has been deprecated and will be removed in Rails 5.1.") |
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.
Actually, I don't think we need method
here.
@kaspth I've removed |
(msg += " and the implicit :ok status") && :ok | ||
) | ||
ActiveSupport::Deprecation.warn(msg + " for `head` has been deprecated and will be removed in Rails 5.1.") | ||
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.
Let's simplify this to:
if status.is_a?(Hash)
msg = "Passing Hash as first parameter"
msg << "and the implicit :ok status" unless status.key?(:status)
options, status = status, status.delete(:status) || :ok
ActiveSupport::Deprecation.warn(msg + "for `head`...")
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.
Should also add a line break between the if status.is_a?(Hash)
and location = options.delete(:location)
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.
Just a minor nit as well, Hash#delete accepts a block, which can be used to set defaults.
E.g. status.delete(:status) { :ok }
@rafaelfranca once my final comments have been addressed, this is ready 👍 @meinac well done 👏 |
@kaspth done. Thanks 💛 |
if status.is_a?(Hash) | ||
msg = "Passing Hash as first parameter" | ||
msg << " and the implicit :ok status" unless status.key?(:status) | ||
options, status = status, (status.delete(:status) || :ok) |
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.
As a tiny nitpick I don't like the parens here, I understand you're worried about the execution order. Would it help to follow @gsamokovarov's suggestion and use the block version?
👍 |
LGTM |
I'd just hit me - we're should deprecate the status argument too, right? |
@kaspth I thought that |
Right, I guess what I'm trying to guard against is a non issue. Though the warning says nothing about how to comply with the changes, so we should add something like: |
I'll have a go at a more natural-sounding deprecation message after I get some sleep. But note there are two behaviour changes around |
@matthewd have you come up with anything? I'm mostly drawing blanks here. |
How about: (status[:status] ? "The :status option" : "The implicit :ok status") <<
" on `head` has been deprecated and will be removed in Rails 5.1. Please pass the status as a separate parameter before the options, instead." To elaborate on my previous comment, this seems to currently change the behaviour of both: head(nil, {})
# and
head({ status: nil }) Unreasonable as those both may be, it seems unnecessary to break them while we're introducing a deprecation message. |
Completely agree that we shouldn't break them and I think your deprecation message is spot on. @meinac, are you okay with that? 😄 |
@kaspth I'm ok with this suggestion, I've changed the message but the line takes a little bit long 😄 I hope this is not a problem because there are some deprecation messages longer than this one. |
msg = status[:status] ? 'The :status option' : 'The implicit :ok status' | ||
options, status = status, status.delete(:status) { :ok } | ||
|
||
ActiveSupport::Deprecation.warn(msg + ' on `head` has been deprecated and will be removed in Rails 5.1. Please pass the status as a separate parameter before the options, instead.') |
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.
We could use squish
here to great effect:
rails/activerecord/lib/active_record/relation/predicate_builder/class_handler.rb
Lines 19 to 23 in 3179b4a
def print_deprecation_warning | |
ActiveSupport::Deprecation.warn(<<-MSG.squish) | |
Passing a class as a value in an Active Record query is deprecated and | |
will be removed. Pass a string instead. | |
MSG |
@kaspth what about this one? |
@meinac that's it! Lovely ❤️ @matthewd @rafaelfranca can one of you merge this? |
Still doesn't address my concerns about |
True, I missed that. We should handle those gracefully too. |
It technically won't give a warning for 👍 |
Sounds good, now you just need to rebase @meinac 😄 |
@kaspth done 👍 |
Great. @matthewd, you know what to do 😄 |
…ad_method Deprecate passing hash as first parameter into ActionController::Head
Deprecate passing hash as first parameter into
ActionController::Head
head
methodBy deprecating this, also implicit status code will be deprecated too.
See #20372 for more information.
/cc @rafaelfranca