From 85ec41dfdd9d39fe1fc34e714ba261d5244e1cc0 Mon Sep 17 00:00:00 2001 From: Arya Asemanfar Date: Sun, 17 Jan 2010 17:27:28 -0800 Subject: [PATCH] fixed reloading new_record resulting in an inconsistent state --- activerecord/lib/active_record/base.rb | 1 + .../reloading_new_record_inconsistent_state.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/cases/reloading_new_record_inconsistent_state.rb diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 78c580f..2793c3d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2718,6 +2718,7 @@ module ActiveRecord #:nodoc: clear_association_cache @attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes')) @attributes_cache = {} + @new_record = false self end diff --git a/activerecord/test/cases/reloading_new_record_inconsistent_state.rb b/activerecord/test/cases/reloading_new_record_inconsistent_state.rb new file mode 100644 index 0000000..e96b0d0 --- /dev/null +++ b/activerecord/test/cases/reloading_new_record_inconsistent_state.rb @@ -0,0 +1,17 @@ +require "cases/helper" + +class Post < ActiveRecord::Base +end + +class ReloadingNewReordInconsistentState < ActiveRecord::TestCase + fixtures :posts + + def test_reloaded_new_record_is_consistent + post_a = Post.new(:title => "Post 6014086") + post_b = Post.new + post_a.id = post_b.id = 6014086 + post_a.save + post_b.reload + assert !post_b.new_record? + end +end -- 1.6.3.2