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:
parent
e83f5a0ae9
commit
f3adddb966
2 changed files with 16 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue