diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-15 11:18:34 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-11-19 19:07:43 -0300 |
commit | e83f5a0ae97889dddfd0956081b0f4582594cda9 (patch) | |
tree | 261b3bb6f7bcafa2cd108a7105bd032b987b7108 /activerecord | |
parent | a9edd6cf932b299e28677cb1e0af397c533caffe (diff) | |
download | rails-e83f5a0ae97889dddfd0956081b0f4582594cda9.tar.gz rails-e83f5a0ae97889dddfd0956081b0f4582594cda9.tar.bz2 rails-e83f5a0ae97889dddfd0956081b0f4582594cda9.zip |
Remove objects from identity map if save failed, otherwise finding again the same record will have invalid attributes.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/identity_map_test.rb | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 439880c1fa..91d16ca97a 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -21,6 +21,8 @@ module ActiveRecord if status = super @previously_changed = changes @changed_attributes.clear + elsif IdentityMap.enabled? + IdentityMap.remove(self) end status end diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb index c51bdf5f69..d4be698082 100644 --- a/activerecord/test/cases/identity_map_test.rb +++ b/activerecord/test/cases/identity_map_test.rb @@ -30,7 +30,7 @@ class IdentityMapTest < ActiveRecord::TestCase end def test_find_id_without_identity_map - IdentityMap.without do + ActiveRecord::IdentityMap.without do assert_not_same(Client.find(3), Client.find(3)) end end @@ -247,4 +247,18 @@ class IdentityMapTest < ActiveRecord::TestCase Developer.joins(', projects').each { |d| assert d.readonly? } Developer.joins(', projects').readonly(false).each { |d| assert d.readonly? } end + + def test_reload_object_if_save_failed + developer = Developer.first + developer.salary = 0 + + assert !developer.save + + same_developer = Developer.first + + assert_not_same developer, same_developer + assert_not_equal 0, same_developer.salary + assert_not_equal developer.salary, same_developer.salary + end + end |