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
Contributor

@danielma danielma commented Oct 30, 2017

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

@rails-bot rails-bot commented Oct 30, 2017

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 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

@rafaelfranca rafaelfranca commented Nov 10, 2017

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 danielma:dma/assert-changes-with-to-should-still-assert-change branch to af0361d Nov 13, 2017
@danielma
Copy link
Contributor Author

@danielma danielma commented Nov 13, 2017

@kamipo kamipo added activesupport and removed activerecord labels Jan 3, 2018
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
2 checks passed
2 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.