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
Use kwargs in ActionController::TestCase and ActionDispatch::Integration HTTP methods #18323
Conversation
session = args[0][:session] | ||
flash = args[0][:flash] | ||
else | ||
parameters, session, flash = args |
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 deprecate this path or we will not be able to use kwargs for real here in the future.
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.
Since we are deprecating all documentation and tests should use the kwarg implementation and we can remove the old implementation from the documentation keeping only a few tests to make sure it works and it is deprecated.
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.
Good point, thanks.
Here is rdoc syntax for usual arguments:
- +action+: The controller action to call.
- +http_method+: Request method used to send the http request. Possible values
are +GET+, +POST+, +PATCH+, +PUT+, +DELETE+, +HEAD+. Defaults to +GET+.
- +parameters+: The HTTP parameters. This may be +nil+, a hash, or a
string that is appropriately encoded (+application/x-www-form-urlencoded+
or +multipart/form-data+).
- +session+: A hash of parameters to store in the session. This may be +nil+.
- +flash+: A hash of parameters to store in the flash. This may be +nil+.
Any suggestions how it will look like with kwargs? Couldn't find it in docs.
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.
New form should be:
process action, method: 'GET', params: {}, session: {}, flash: {}
And then we add on with:
post/get/put/patch/delete/head action, params: {}, session: {}, flash: {}
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.
Got it. I meant the rdoc syntax for describing kwargs
We should do the same treatment to ActionDispatch::IntegrationTest. |
@dhh in the same PR or in the separate? |
In the same On Sun, Jan 4, 2015, 15:04 Kir Shatrov notifications@github.com wrote:
|
We can do a separate PR for that. Just that we don’t want the two APIs to diverge in a release.
|
Ha, I don't really care if it's the same or separate. But yeah, @rafaelfranca is probably right that we might as well treat it as one change. Since it's the same API. Although IntegrationTests also have |
Yeah, they can be different commits but I'd like to have the whole set of On Sun, Jan 4, 2015, 15:08 David Heinemeier Hansson <
|
@rafaelfranca @dhh done |
end | ||
end | ||
end | ||
# class MetalIntegrationTest < ActionDispatch::IntegrationTest |
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.
Why is this test commented out?
Should we update the testing guide? |
@rafaelfranca TODO is fixed, thanks! I will update the guide soon. |
@rafaelfranca guide updated. |
# be +nil+, a hash, or a string that is appropriately encoded | ||
# - action: The controller action to call. | ||
# - params: The hash with HTTP parameters that you want to pass. This may be +nil+. | ||
# - body: The request body with a string that is appropriately encoded | ||
# (<tt>application/x-www-form-urlencoded</tt> or <tt>multipart/form-data</tt>). | ||
# - +session+: A hash of parameters to store in the session. This may be +nil+. |
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.
If we removed the fixed size of fonts of the other arguments we should do the same with session
and flash
.
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.
But I really not sure if we should remove it @fxn?
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.
What do you mean under "fixed size of fonts"?
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 +action+
over action
.
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.
Yep, we should keep it.
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.
@kirs when you refer to variables, keyword arguments, etc. you use fixed-width font for them. That is assigns
, rather than just assigns. Have a look at the API guidelines.
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.
Thanks for review and explanation, I will fix it.
@rafaelfranca I added the CHANGELOG entry. Ready for merge? |
@@ -491,58 +491,64 @@ def determine_default_controller_class(name) | |||
end | |||
end | |||
|
|||
# Simulate a GET request with the given parameters. | |||
# Simulate a GET request with the given keyword arguments. |
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.
"parameters" is maybe a better fit here ; "keyword arguments" is more an implementation detail and we are still passing the action as a normal parameter, not as a keyword argument. What do you think ?
Awesome work @kirs ! There's just a tiny missing change here to avoid displaying a deprecation warning running the test suite. Also, regarding deprecation warnings, you may want to use
But well, that's just styling concerns, there's no big deal. Thank you ! |
Anyone having trouble with this change specifically may want to take a look at the rails5-spec-converter gem |
This warning was awfully hard to understand because by reading my code, it seemed like my params were already "keyword arguments". Now I understand that what it really means for all of my usages is that params can no longer be passed bare anymore. |
Is there a way of writing |
@aaronrussell they'll still pass in both, but will print deprecation warnings on 5. |
Prevent hitting integration tests users with two deprecation warnings by clarifying how they should upgrade to the request helpers `get` and friends. It's hard to imagine people having `xhr` calls that use keywords, why not follow the xhr deprecation message? Why instead insert a middle layer of migration? They have to switch to something else anyway, so just show how that looks and nudge them a bit more. The code was originally added in #18323, but then wasn't touched when deprecating xhr in #18771.
rails/rails#18323 Changes code like: * get :show, params.merge(format: :atom) * get(path, {}, headers) to * get :show, params: params.merge(format: :atom) * get(path, params: {}, headers: headers) Thanks to @rosmith76 and @asackofwheat
Adds both `html` and `js` responses allowing the editting/updating of `first_name`, `last_name`, & `location` on a users profile. Introduces the `profile.edit` & `profile.edit.others` permissions. Removes the `Rail/HttpPositionalArguments` Cop from `rubocop`, this is due to the fact that we're using `rails-4.2.7.1` and that cop is intended to catch behaviour that was deprecated in this [PR](rails/rails#18323) however that deprecation does not affect our current `rails` version.
…ests#676 - update jsonapi initializer and corresponding JSON response keys - add rails-controller-testing gem to support 'assert_template' and 'assigns' - see rspec/rspec-rails#1393 - update controller tests as Rails5 only accepts keyword arguments - see rails/rails#18323
Rails 5 introduces a breaking change to request helpers synopsis. Unfortunately, the modern way doesn't work in Rails 4, so we need to choose between old and new helpers depending on Rails version. See: - rails/rails#18323 - https://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html
Rails 5 introduces a breaking change to request helpers synopsis. Unfortunately, the modern way doesn't work in Rails 4, so we need to choose between old and new helpers depending on Rails version. See: - rails/rails#18323 - https://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html
- Use kwargs in HTTP request methods in rspec See: rails/rails#18323
- Use kwargs in HTTP request methods in rspec See: rails/rails#18323
As @dhh suggested, controller HTTP methods are a prime candidate for kwargs.
post url, nil, nil, { a: 'b' }
doesn't make sense.More explicit way would be:
post url, params: { y: x }, session: { a: 'b' }.