Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AquaGeek/971649 to your computer and use it in GitHub Desktop.
Save AquaGeek/971649 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #3502
From 85ec41dfdd9d39fe1fc34e714ba261d5244e1cc0 Mon Sep 17 00:00:00 2001
From: Arya Asemanfar <[email protected]>
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
From c20478b227806952a94aa5a0a45e4c2227f0d970 Mon Sep 17 00:00:00 2001
From: Colin Casey <[email protected]>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment