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

[5-0-stable] Don't mutate parameters in test request helpers #32492

Merged
merged 1 commit into from
Apr 8, 2018

Conversation

eugeneius
Copy link
Member

Mutating the value passed as params when making a request in a controller test is surprising behaviour. We can avoid it by calling symbolize_keys first, which will make a copy of the hash.

This matches the behaviour on 5.1 and later, which was introduced in 98b8309. On 4.2 and earlier, passing format separately wasn't supported, so this fix is only needed on 5.0.

Mutating the value passed as the `params` keyword argument when making
a request in a controller test is surprising behaviour. We can avoid it
by calling `symbolize_keys` first, which will make a copy of the hash.

This matches the behaviour on 5.1 and later, which was introduced in
98b8309. On 4.2 and earlier, passing
`format` separately wasn't supported, so this fix is only needed on 5.0.
@rails-bot
Copy link

r? @pixeltrix

(@rails-bot has picked a reviewer for you, use r? to override)

@rails-bot
Copy link

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 5-0-stable. Please double check that you specified the right target!

@eugeneius eugeneius changed the title Don't mutate parameters in test request helpers [5-0-stable] Don't mutate parameters in test request helpers Apr 7, 2018
@pixeltrix pixeltrix merged commit 87fe73b into rails:5-0-stable Apr 8, 2018
@pixeltrix
Copy link
Contributor

@eugeneius thanks! 👍

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Apr 9, 2018
…utate_params`

Use `#freeze` in order to express that params don't mutate.

Related to rails#32492
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Apr 10, 2018
…master

Initially, the test was added to 5-0-stable in rails#32492
and a bit modified in rails#32506. This test ensures that request(in tests)
doesn't mutate params. It was fixed since v5.1.0.beta1 by
98b8309 and then on 5-0-stable by rails#32492.
This commit adds this test to master branch in order to prevent any
regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants