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

assert_changes should always assert some change #31011

Conversation

danielma
Copy link

Summary

While using assert_changes, I came across some unexpected behavior:
if you provide a to: argument, and the expression matches but didn't
actually change, the assertion will pass.

The way assert_changes reads, I assumed that it would both assert
that there was any change at all, and that the expression changed to
match my to: argument.

In the case of just a from: argument, assert_changes does what I
expect as well. It asserts that the before value === from and that
the after value changed.

My key change is that assert_changes will now always assert that
expression changes, no matter what combination of from: and to:
arguments

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@sgrif
Copy link
Contributor

sgrif commented Oct 30, 2017

I think we should give a specific error mentioning that the value was already the same as the given value to to:, rather than just giving the same generic "didn't change" error.

@rafaelfranca
Copy link
Member

Can you squash your commits?

While using `assert_changes`, I came across some unexpected behavior:
if you provide a `to:` argument, and the expression matches but didn't
actually change, the assertion will pass.

The way `assert_changes` reads, I assumed that it would both assert
that there was any change at all, _and_ that the expression changed to
match my `to:` argument.

In the case of just a `from:` argument, `assert_changes` does what I
expect as well. It asserts that the before value `=== from` and that
the after value changed.

My key change is that `assert_changes` will now _always_ assert that
expression changes, no matter what combination of `from:` and `to:`
arguments
@danielma danielma force-pushed the dma/assert-changes-with-to-should-still-assert-change branch from f2887ba to af0361d Compare November 13, 2017 19:52
@danielma
Copy link
Author

@rafaelfranca done

tgxworld pushed a commit to tgxworld/rails that referenced this pull request Jan 4, 2018
…to-should-still-assert-change

`assert_changes` should always assert some change
@kamipo kamipo merged commit af0361d into rails:master Jan 4, 2018
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.

5 participants