Incorrect integer status using {attribute}_changed? in Rails 3.2.7 #7237

Closed
timedimension opened this Issue Aug 2, 2012 · 0 comments

Projects

None yet

2 participants

@timedimension

After upgrading from Rails 3.2.6 to 3.2.7, encountered a test failure when evaluating an integer attribute that contained a zero value as changed. Tested other non-integer values and the _changed? status was correct. The following is a quick test to reproduce the problem:

First obtain an integer attribute from the database table (using postgres in my case):
r=Review.find_by_issue(11)
r.issue
=> 11
r.changes
=> {}
r.issue = 11
=> 11
r.changed?
=> false
r.changes
=> {}

The above works as it did before in Rails 3.2.6. The next test using zero has a different behavior:

r=Review.find_by_issue(0)
r.issue
=> 0
r.changes
=> {}
r.issue = 0
=> 0
r.changed?
=> true
r.changes
=> {"issue"=>[0,0]}

It now treats a zero value to the same zero value as a change in Rails 3.2.7. I also tested this against Rails 3.2.8rc1 and encountered the same problem.

@rafaelfranca rafaelfranca was assigned Aug 2, 2012
@rafaelfranca rafaelfranca added a commit that closed this issue Aug 2, 2012
@rafaelfranca rafaelfranca Do not consider the numeric attribute as changed if the old value is
zero and the new value is not a string.

Before this commit this was the behavior

r = Review.find_by_issue(0)
r.issue
=> 0
r.changes
=> {}
r.issue = 0
=> 0
r.changed?
=> true
r.changes
=> {"issue"=>[0,0]}

Fixes #7237
99f622d
@rafaelfranca rafaelfranca added a commit that referenced this issue Aug 2, 2012
@rafaelfranca rafaelfranca Do not consider the numeric attribute as changed if the old value is
zero and the new value is not a string.

Before this commit this was the behavior

r = Review.find_by_issue(0)
r.issue
=> 0
r.changes
=> {}
r.issue = 0
=> 0
r.changed?
=> true
r.changes
=> {"issue"=>[0,0]}

Fixes #7237

Conflicts:
	activerecord/CHANGELOG.md
4028bed
@rafaelfranca rafaelfranca added a commit that referenced this issue Aug 2, 2012
@rafaelfranca @spastorino rafaelfranca + spastorino Do not consider the numeric attribute as changed if the old value is
zero and the new value is not a string.

Before this commit this was the behavior

r = Review.find_by_issue(0)
r.issue
=> 0
r.changes
=> {}
r.issue = 0
=> 0
r.changed?
=> true
r.changes
=> {"issue"=>[0,0]}

Fixes #7237
55e05d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment