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

Deprecate string options in URL helpers #17743

Conversation

mrgilman
Copy link

@mrgilman mrgilman commented Nov 24, 2014

Fixes #16958

I pretty much implemented @bronzle's fix in the issue comments, so he should have credit too.

@zzak
Copy link
Member

zzak commented Nov 24, 2014

I think this would need a changelog

@sgrif
Copy link
Contributor

sgrif commented Nov 24, 2014

If you want to credit someone else, put both names in the changelog, and at the bottom of the commit message put [your handle & their handle]

@@ -293,6 +293,19 @@ def handle_positional_args(controller_options, inner_options, args, result, path

result.merge!(inner_options)
end

DEPRECATED_STRING_OPTIONS = %w[controller action].freeze
Copy link
Contributor

@sgrif sgrif Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a set?

Copy link
Contributor

@bronzle bronzle Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea.

@mrgilman mrgilman force-pushed the deprecate-string-options-in-url-helpers branch from eedc183 to 3da29bd Compare Nov 24, 2014
@mrgilman
Copy link
Author

mrgilman commented Nov 24, 2014

Thanks for the feedback! Made the suggested changes and added a changelog entry.

@rafaelfranca
Copy link
Member

rafaelfranca commented Nov 24, 2014

I pretty much implemented @bronzle's fix in the issue comments, so he should have credit too.

❤️

ActiveSupport::Deprecation.warn(msg)
DEPRECATED_STRING_OPTIONS.each do |option|
value = options.delete(option)
options[option.to_sym] ||= value if value
Copy link
Member

@rafaelfranca rafaelfranca Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a pretty complex logic here without test. For example, why were are using ||=? Why we need to check if value is present?

I'd add tests for these cases to make sure we don't have regressions on this code.

@sgrif
Copy link
Contributor

sgrif commented Nov 24, 2014

This looks good to me

DEPRECATED_STRING_OPTIONS = Set.new(%w[controller action])

def deprecate_string_options(options = {})
if options && options.each_key.any? { |k| DEPRECATED_STRING_OPTIONS.include?(k) }
Copy link
Member

@rafaelfranca rafaelfranca Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to write

if options && (deprecated_string_options = options & DEPRECATED_STRING_OPTIONS)

and we use the deprecated_string_options variable to print the correct message and to iterate on the each loop.

This way to deleting an option that doesn't existe there.

Copy link
Contributor

@sgrif sgrif Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would need to be on the keys specifically. I think that'd be more readable on two lines, as well. :)

@rafaelfranca rafaelfranca self-assigned this Nov 24, 2014
@rafaelfranca rafaelfranca added this to the 4.2.0 milestone Nov 24, 2014
@mrgilman mrgilman force-pushed the deprecate-string-options-in-url-helpers branch from 3da29bd to 8b59aa2 Compare Nov 24, 2014
@@ -293,6 +293,22 @@ def handle_positional_args(controller_options, inner_options, args, result, path

result.merge!(inner_options)
end

DEPRECATED_STRING_OPTIONS = Set.new(%w[controller action])
Copy link
Member

@rafaelfranca rafaelfranca Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a set now?

Copy link
Contributor

@sgrif sgrif Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I'm about to merge, will fix as I merge.

@mrgilman mrgilman force-pushed the deprecate-string-options-in-url-helpers branch from 8b59aa2 to 4d84922 Compare Nov 25, 2014
Fixes rails#16958

[Byron Bischoff & Melanie Gilman]
@mrgilman mrgilman force-pushed the deprecate-string-options-in-url-helpers branch from 4d84922 to ce28e89 Compare Nov 25, 2014
@sgrif
Copy link
Contributor

sgrif commented Nov 25, 2014

Gah... We tried to update the changelog format at the same time. This was merged.

@sgrif sgrif closed this Nov 25, 2014
zzak added a commit to zzak/rails that referenced this pull request Nov 25, 2014
sgrif added a commit that referenced this pull request Nov 25, 2014
@heaven
Copy link

heaven commented May 15, 2015

Something is wrong with this:

admin_dashboard_path(params)

Where params is an instance of ActionController::Parameters, produces:

DEPRECATION WARNING: Calling URL helpers with string keys controller, action is deprecated. ...
/dashboard

@agis
Copy link
Contributor

agis commented Sep 17, 2015

@heaven Indeed. Follow the discussion in #21648.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails 4.2 URL helper change of behaviour (possible bug?)
8 participants