1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove objects from identity map if save! failed, otherwise finding again the same record will have invalid attributes.

This commit is contained in:
Emilio Tagua 2010-09-15 11:22:24 -03:00
parent e83f5a0ae9
commit f3adddb966
2 changed files with 16 additions and 0 deletions

View file

@ -33,6 +33,9 @@ module ActiveRecord
@previously_changed = changes
@changed_attributes.clear
end
rescue
IdentityMap.remove(self) if IdentityMap.enabled?
raise
end
# <tt>reload</tt> the record and clears changed attributes.

View file

@ -261,4 +261,17 @@ class IdentityMapTest < ActiveRecord::TestCase
assert_not_equal developer.salary, same_developer.salary
end
def test_reload_object_if_forced_save_failed
developer = Developer.first
developer.salary = 0
assert_raise(ActiveRecord::RecordInvalid) { 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