aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorTim Chater <t.chater@gmail.com>2008-06-17 13:54:03 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-27 21:31:06 -0700
commit1415df8f49a19d469b9e2c15785db32eb312c000 (patch)
treec5921b7638e3ea3e937d489cbb23d3b43169cd4b /activerecord/test
parent9a25315076bf90c39ab5471fa8d81736a3b2478e (diff)
downloadrails-1415df8f49a19d469b9e2c15785db32eb312c000.tar.gz
rails-1415df8f49a19d469b9e2c15785db32eb312c000.tar.bz2
rails-1415df8f49a19d469b9e2c15785db32eb312c000.zip
Dirty: recognize when an integer changes from zero to blank. [#433 state:resolved]
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/dirty_test.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index d70a787208..e5e022050d 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -55,6 +55,33 @@ class DirtyTest < ActiveRecord::TestCase
end
end
+ def test_zero_to_blank_marked_as_changed
+ pirate = Pirate.new
+ pirate.catchphrase = "Yarrrr, me hearties"
+ pirate.parrot_id = 1
+ pirate.save
+
+ # check the change from 1 to ''
+ pirate = Pirate.find_by_catchphrase("Yarrrr, me hearties")
+ pirate.parrot_id = ''
+ assert pirate.parrot_id_changed?
+ assert_equal([1, nil], pirate.parrot_id_change)
+ pirate.save
+
+ # check the change from nil to 0
+ pirate = Pirate.find_by_catchphrase("Yarrrr, me hearties")
+ pirate.parrot_id = 0
+ assert pirate.parrot_id_changed?
+ assert_equal([nil, 0], pirate.parrot_id_change)
+ pirate.save
+
+ # check the change from 0 to ''
+ pirate = Pirate.find_by_catchphrase("Yarrrr, me hearties")
+ pirate.parrot_id = ''
+ assert pirate.parrot_id_changed?
+ assert_equal([0, nil], pirate.parrot_id_change)
+ end
+
def test_object_should_be_changed_if_any_attribute_is_changed
pirate = Pirate.new
assert !pirate.changed?