From c20478b227806952a94aa5a0a45e4c2227f0d970 Mon Sep 17 00:00:00 2001 From: Colin Casey Date: Sun, 16 May 2010 18:10:50 -0300 Subject: [PATCH] fixed reloading new_record resulting in an inconsistent state --- activerecord/lib/active_record/persistence.rb | 3 ++- ...reloading_new_record_inconsistent_state_test.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletions(-) create mode 100644 activerecord/test/cases/reloading_new_record_inconsistent_state_test.rb diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 1078863..6ad478e 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -177,6 +177,7 @@ module ActiveRecord clear_association_cache @attributes.update(self.class.send(:with_exclusive_scope) { self.class.find(self.id, options) }.instance_variable_get('@attributes')) @attributes_cache = {} + @new_record = false self end @@ -227,4 +228,4 @@ module ActiveRecord end end end -end \ No newline at end of file +end diff --git a/activerecord/test/cases/reloading_new_record_inconsistent_state_test.rb b/activerecord/test/cases/reloading_new_record_inconsistent_state_test.rb new file mode 100644 index 0000000..cf10845 --- /dev/null +++ b/activerecord/test/cases/reloading_new_record_inconsistent_state_test.rb @@ -0,0 +1,17 @@ +require "cases/helper" + +class Post < ActiveRecord::Base +end + +class ReloadingNewRecordInconsistentStateTest < ActiveRecord::TestCase + fixtures :posts + + def test_reloaded_new_record_is_consistent + post_a = Post.new(:title => "Post 6014086", :body => 'ReloadingNewRecordInconsistentStateTest') + 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.0.4