From: Go MAEDA Date: Thu, 1 Apr 2021 14:48:50 +0000 (+0000) Subject: Fix "ActiveRecord::StaleObjectError: Attempted to update a stale object: Issue."... X-Git-Tag: 5.0.0~475 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e86476eb5be8abbabba60e0c9a34f4a50fafcfb9;p=redmine.git Fix "ActiveRecord::StaleObjectError: Attempted to update a stale object: Issue." (#29914, #32912). Patch by Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@20884 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/test/object_helpers.rb b/test/object_helpers.rb index e89e1bd05..3900bc45d 100644 --- a/test/object_helpers.rb +++ b/test/object_helpers.rb @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 34e0162cf..797e4eca7 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index f15fc937a..b154e6b90 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 8aac3ed72..ab1fe56ab 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -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