From 3a661794382c3b06cbb4d6dcc1859dd569cf8652 Mon Sep 17 00:00:00 2001
From: chrisfinne <chris.finne@gmail.com>
Date: Sat, 15 Mar 2014 03:32:24 -0700
Subject: AR .persisted? throws SystemStackError for an unsaved model with a
 custom primary_key that didn't save due to validation error

---
 activerecord/test/cases/transactions_test.rb | 6 ++++++
 activerecord/test/models/movie.rb            | 2 ++
 2 files changed, 8 insertions(+)

(limited to 'activerecord/test')

diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
index 1664f1a096..e6ed85394b 100644
--- a/activerecord/test/cases/transactions_test.rb
+++ b/activerecord/test/cases/transactions_test.rb
@@ -5,6 +5,7 @@ require 'models/developer'
 require 'models/book'
 require 'models/author'
 require 'models/post'
+require 'models/movie'
 
 class TransactionTest < ActiveRecord::TestCase
   self.use_transactional_fixtures = false
@@ -14,6 +15,11 @@ class TransactionTest < ActiveRecord::TestCase
     @first, @second = Topic.find(1, 2).sort_by { |t| t.id }
   end
 
+  def test_persisted_in_a_model_with_custom_primary_key_after_failed_save
+    movie = Movie.create
+    assert !movie.persisted?
+  end
+
   def test_raise_after_destroy
     assert_not @first.frozen?
 
diff --git a/activerecord/test/models/movie.rb b/activerecord/test/models/movie.rb
index c441be2bef..0302abad1e 100644
--- a/activerecord/test/models/movie.rb
+++ b/activerecord/test/models/movie.rb
@@ -1,3 +1,5 @@
 class Movie < ActiveRecord::Base
   self.primary_key = "movieid"
+
+  validates_presence_of :name
 end
-- 
cgit v1.2.3