From e0912b99f5ab1767b8c34956619d216ad7ab73b1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 13 Dec 2016 20:01:57 +0000 Subject: [PATCH] Unarchive link not working for subprojects of closed projects (#24595). git-svn-id: http://svn.redmine.org/redmine/trunk@16071 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 12 ++++++++++-- test/unit/project_test.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2f258f3f9..3582a2c67 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -350,6 +350,10 @@ class Project < ActiveRecord::Base self.status == STATUS_ACTIVE end + def closed? + self.status == STATUS_CLOSED + end + def archived? self.status == STATUS_ARCHIVED end @@ -377,8 +381,12 @@ class Project < ActiveRecord::Base # Unarchives the project # All its ancestors must be active def unarchive - return false if ancestors.detect {|a| !a.active?} - update_attribute :status, STATUS_ACTIVE + return false if ancestors.detect {|a| a.archived?} + new_status = STATUS_ACTIVE + if parent + new_status = parent.status + end + update_attribute :status, new_status end def close diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 3809662f7..b740ee649 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -205,6 +205,18 @@ class ProjectTest < ActiveSupport::TestCase assert @ecookbook_sub1.unarchive end + def test_unarchive_a_child_of_a_closed_project_should_set_status_to_closed + Project.find(1).close + child = Project.find(3) + assert_equal Project::STATUS_CLOSED, child.status + + child.archive + assert_equal Project::STATUS_ARCHIVED, child.status + + child.unarchive + assert_equal Project::STATUS_CLOSED, child.status + end + def test_destroy # 2 active members assert_equal 2, @ecookbook.members.size -- 2.39.5