aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-02 14:01:44 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-02 14:11:51 -0300
commit99f622de230e582c372e20f4b72792c0fce0fd4a (patch)
tree11e9b53483059998d333f9ed5534022c7a21bcdc /activerecord
parent59c4b22c4528e9f97d3eb394f603dc50c3cf41a9 (diff)
downloadrails-99f622de230e582c372e20f4b72792c0fce0fd4a.tar.gz
rails-99f622de230e582c372e20f4b72792c0fce0fd4a.tar.bz2
rails-99f622de230e582c372e20f4b72792c0fce0fd4a.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb2
-rw-r--r--activerecord/test/cases/dirty_test.rb15
3 files changed, 21 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 48725116fa..669811c74f 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## Rails 3.2.8 ##
+* Do not consider the numeric attribute as changed if the old value is zero and the new value
+ is not a string.
+ Fixes #7237.
+
+ *Rafael Mendonça França*
+
* Removes the deprecation of `update_attribute`. *fxn*
* Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 586a189011..ed863a9696 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -104,7 +104,7 @@ module ActiveRecord
def changes_from_zero_to_string?(old, value)
# For columns with old 0 and value non-empty string
- old == 0 && value.present? && value != '0'
+ old == 0 && value.is_a?(String) && value.present? && value != '0'
end
end
end
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index 60497ac5d8..d939e13d9a 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -201,7 +201,7 @@ class DirtyTest < ActiveRecord::TestCase
end
end
- def test_nullable_integer_zero_to_string_zero_not_marked_as_changed
+ def test_integer_zero_to_string_zero_not_marked_as_changed
pirate = Pirate.new
pirate.parrot_id = 0
pirate.catchphrase = 'arrr'
@@ -213,6 +213,19 @@ class DirtyTest < ActiveRecord::TestCase
assert !pirate.changed?
end
+ def test_integer_zero_to_integer_zero_not_marked_as_changed
+ pirate = Pirate.new
+ pirate.parrot_id = 0
+ pirate.catchphrase = 'arrr'
+ assert pirate.save!
+
+ assert !pirate.changed?
+
+ pirate.parrot_id = 0
+ assert !pirate.changed?
+ end
+
+
def test_zero_to_blank_marked_as_changed
pirate = Pirate.new
pirate.catchphrase = "Yarrrr, me hearties"