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

Merged
merged 1 commit into from Jan 4, 2018

Conversation

Projects
None yet
5 participants
@danielma
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot 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.

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

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Oct 30, 2017

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Nov 10, 2017

Member

Can you squash your commits?

Member

rafaelfranca commented Nov 10, 2017

Can you squash your commits?

`assert_changes` should always assert some change
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

This comment has been minimized.

Show comment
Hide comment
@danielma
Contributor

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

Merge pull request rails#31011 from danielma/dma/assert-changes-with-…
…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

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