]> source.dussan.org Git - redmine.git/commitdiff
Fix "ActiveRecord::StaleObjectError: Attempted to update a stale object: Issue."...
authorGo MAEDA <maeda@farend.jp>
Thu, 1 Apr 2021 14:48:50 +0000 (14:48 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 1 Apr 2021 14:48:50 +0000 (14:48 +0000)
Patch by Pavel Rosický.

git-svn-id: http://svn.redmine.org/redmine/trunk@20884 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/object_helpers.rb
test/unit/issue_test.rb
test/unit/project_test.rb
test/unit/user_test.rb

index e89e1bd0515e4b19656da7e1efead5ea86720f6e..3900bc45d62f93a8df9b0943c1f517deb9cbf45c 100644 (file)
@@ -105,7 +105,7 @@ module ObjectHelpers
   def Issue.generate!(attributes={}, &block)
     issue = Issue.generate(attributes, &block)
     issue.save!
-    issue
+    issue.reload
   end
 
   # Generates an issue with 2 children and a grandchild
index 34e0162cf35acabf68fccfb3aeeff0e2e180ea88..797e4eca7f80bf74ba11a6c1e258ba1db475c17d 100644 (file)
@@ -1440,7 +1440,7 @@ class IssueTest < ActiveSupport::TestCase
     copy = issue.reload.copy
     assert_difference 'Issue.count', 1+issue.descendants.count do
       assert copy.save
-      assert copy.save
+      assert copy.reload.save
     end
   end
 
@@ -2502,6 +2502,7 @@ class IssueTest < ActiveSupport::TestCase
     relation = new_record(IssueRelation) do
       copy.save!
     end
+    copy.reload
 
     copy.parent_issue_id = parent.id
     assert_save copy
@@ -2756,7 +2757,7 @@ class IssueTest < ActiveSupport::TestCase
                                      :possible_values => ['value1', 'value2', 'value3'],
                                      :multiple => true)
 
-    issue = Issue.create!(:project_id => 1, :tracker_id => 1,
+    issue = Issue.generate!(:project_id => 1, :tracker_id => 1,
                           :subject => 'Test', :author_id => 1)
 
     assert_difference 'Journal.count' do
index f15fc937ae7ad1fd6b1844523be6da6b3942186d..b154e6b90dc24853361393eef0d9aba95adc9f9d 100644 (file)
@@ -245,7 +245,7 @@ class ProjectTest < ActiveSupport::TestCase
   def test_destroy_should_destroy_subtasks
     issues =
       (0..2).to_a.map do
-        Issue.create!(:project_id => 1, :tracker_id => 1,
+        Issue.generate!(:project_id => 1, :tracker_id => 1,
                       :author_id => 1, :subject => 'test')
       end
     issues[0].update! :parent_issue_id => issues[1].id
index 8aac3ed72ca88eeac4cb512ffca6b9c5c9ded794..ab1fe56abefd0f07891c1fac4bcdf6b3ee7fb4fa 100644 (file)
@@ -305,7 +305,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_destroy_should_update_journals
-    issue = Issue.create!(:project_id => 1, :author_id => 2,
+    issue = Issue.generate!(:project_id => 1, :author_id => 2,
                           :tracker_id => 1, :subject => 'foo')
     issue.init_journal(User.find(2), "update")
     issue.save!
@@ -316,7 +316,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_destroy_should_update_journal_details_old_value
-    issue = Issue.create!(:project_id => 1, :author_id => 1,
+    issue = Issue.generate!(:project_id => 1, :author_id => 1,
                           :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2)
     issue.init_journal(User.find(1), "update")
     issue.assigned_to_id = nil
@@ -332,7 +332,7 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_destroy_should_update_journal_details_value
-    issue = Issue.create!(:project_id => 1, :author_id => 1,
+    issue = Issue.generate!(:project_id => 1, :author_id => 1,
                           :tracker_id => 1, :subject => 'foo')
     issue.init_journal(User.find(1), "update")
     issue.assigned_to_id = 2