Permalink
Browse files

Remove objects from identity map if save failed, otherwise finding ag…

…ain the same record will have invalid attributes.
  • Loading branch information...
1 parent a9edd6c commit e83f5a0ae97889dddfd0956081b0f4582594cda9 @miloops miloops committed Sep 15, 2010
@@ -21,6 +21,8 @@ def save(*) #:nodoc:
if status = super
@previously_changed = changes
@changed_attributes.clear
+ elsif IdentityMap.enabled?
+ IdentityMap.remove(self)
end
status
end
@@ -30,7 +30,7 @@ def test_find_id
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 @@ def test_find_with_joins_option_implies_readonly
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

0 comments on commit e83f5a0

Please sign in to comment.