summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-06 10:28:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-06 10:28:20 +0000
commit5f8e9d71182040473d4072241ce81fcadada497f (patch)
tree7701b9fed7aed50afd4dbf7fd34ec5ef08d40e5f /test/unit
parente1781235696fe23851154ebbdc913e970d3c0f3a (diff)
downloadredmine-5f8e9d71182040473d4072241ce81fcadada497f.tar.gz
redmine-5f8e9d71182040473d4072241ce81fcadada497f.zip
Version sharing (#465) + optional inclusion of subprojects in the roadmap view (#2666).
Each version of a project can be shared with: * subprojects * projects in the project hierarchy: ancestors + descendants (needs versions management permission on the root project) * projects in the project tree: root project + all its descendants (same as above) * all projects (can be set by admin users only) Notes: * when sharing a version of a private project with others projects, its name will be visible within the other projects * a project with versions used by non descendant projects can not be archived git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3123 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/enumeration_test.rb4
-rw-r--r--test/unit/helpers/projects_helper_test.rb63
-rw-r--r--test/unit/issue_priority_test.rb2
-rw-r--r--test/unit/issue_test.rb40
-rw-r--r--test/unit/project_test.rb112
-rw-r--r--test/unit/query_test.rb8
-rw-r--r--test/unit/version_test.rb35
7 files changed, 250 insertions, 14 deletions
diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb
index abb15353a..d9d330721 100644
--- a/test/unit/enumeration_test.rb
+++ b/test/unit/enumeration_test.rb
@@ -25,7 +25,7 @@ class EnumerationTest < ActiveSupport::TestCase
def test_objects_count
# low priority
- assert_equal 5, Enumeration.find(4).objects_count
+ assert_equal 6, Enumeration.find(4).objects_count
# urgent
assert_equal 0, Enumeration.find(7).objects_count
end
@@ -79,7 +79,7 @@ class EnumerationTest < ActiveSupport::TestCase
def test_destroy_with_reassign
Enumeration.find(4).destroy(Enumeration.find(6))
assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
- assert_equal 5, Enumeration.find(6).objects_count
+ assert_equal 6, Enumeration.find(6).objects_count
end
def test_should_be_customizable
diff --git a/test/unit/helpers/projects_helper_test.rb b/test/unit/helpers/projects_helper_test.rb
new file mode 100644
index 000000000..ce9598841
--- /dev/null
+++ b/test/unit/helpers/projects_helper_test.rb
@@ -0,0 +1,63 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class ProjectsHelperTest < HelperTestCase
+ include ApplicationHelper
+ include ProjectsHelper
+
+ fixtures :all
+
+ def setup
+ super
+ set_language_if_valid('en')
+ User.current = nil
+ end
+
+ def test_link_to_version_within_project
+ @project = Project.find(2)
+ User.current = User.find(1)
+ assert_equal '<a href="/versions/show/5">Alpha</a>', link_to_version(Version.find(5))
+ end
+
+ def test_link_to_version
+ User.current = User.find(1)
+ assert_equal '<a href="/versions/show/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5))
+ end
+
+ def test_link_to_private_version
+ assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5))
+ end
+
+ def test_link_to_version_invalid_version
+ assert_equal '', link_to_version(Object)
+ end
+
+ def test_format_version_name_within_project
+ @project = Project.find(1)
+ assert_equal "0.1", format_version_name(Version.find(1))
+ end
+
+ def test_format_version_name
+ assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
+ end
+
+ def test_format_version_name_for_system_version
+ assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7))
+ end
+end
diff --git a/test/unit/issue_priority_test.rb b/test/unit/issue_priority_test.rb
index 6574bf38c..51a6b82e3 100644
--- a/test/unit/issue_priority_test.rb
+++ b/test/unit/issue_priority_test.rb
@@ -26,7 +26,7 @@ class IssuePriorityTest < ActiveSupport::TestCase
def test_objects_count
# low priority
- assert_equal 5, IssuePriority.find(4).objects_count
+ assert_equal 6, IssuePriority.find(4).objects_count
# urgent
assert_equal 0, IssuePriority.find(7).objects_count
end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 6213524b8..dd732f97f 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -329,6 +329,46 @@ class IssueTest < ActiveSupport::TestCase
assert_nil issue.category_id
end
+ def test_move_to_another_project_should_clear_fixed_version_when_not_shared
+ issue = Issue.find(1)
+ issue.update_attribute(:fixed_version_id, 1)
+ assert issue.move_to(Project.find(2))
+ issue.reload
+ assert_equal 2, issue.project_id
+ # Cleared fixed_version
+ assert_equal nil, issue.fixed_version
+ end
+
+ def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
+ issue = Issue.find(1)
+ issue.update_attribute(:fixed_version_id, 4)
+ assert issue.move_to(Project.find(5))
+ issue.reload
+ assert_equal 5, issue.project_id
+ # Keep fixed_version
+ assert_equal 4, issue.fixed_version_id
+ end
+
+ def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
+ issue = Issue.find(1)
+ issue.update_attribute(:fixed_version_id, 1)
+ assert issue.move_to(Project.find(5))
+ issue.reload
+ assert_equal 5, issue.project_id
+ # Cleared fixed_version
+ assert_equal nil, issue.fixed_version
+ end
+
+ def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
+ issue = Issue.find(1)
+ issue.update_attribute(:fixed_version_id, 7)
+ assert issue.move_to(Project.find(2))
+ issue.reload
+ assert_equal 2, issue.project_id
+ # Keep fixed_version
+ assert_equal 7, issue.fixed_version_id
+ end
+
def test_copy_to_the_same_project
issue = Issue.find(1)
copy = nil
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 93e4bbf22..cbf9ce54f 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -18,10 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class ProjectTest < ActiveSupport::TestCase
- fixtures :projects, :enabled_modules,
- :issues, :issue_statuses, :journals, :journal_details,
- :users, :members, :member_roles, :roles, :projects_trackers, :trackers, :boards,
- :queries
+ fixtures :all
def setup
@ecookbook = Project.find(1)
@@ -111,6 +108,17 @@ class ProjectTest < ActiveSupport::TestCase
assert @ecookbook.descendants.active.empty?
end
+ def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects
+ # Assign an issue of a project to a version of a child project
+ Issue.find(4).update_attribute :fixed_version_id, 4
+
+ assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do
+ assert_equal false, @ecookbook.archive
+ end
+ @ecookbook.reload
+ assert @ecookbook.active?
+ end
+
def test_unarchive
user = @ecookbook.members.first.user
@ecookbook.archive
@@ -206,6 +214,38 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal 4, parent.children.size
assert_equal parent.children.sort_by(&:name), parent.children
end
+
+
+ def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
+ # Parent issue with a hierarchy project's fixed version
+ parent_issue = Issue.find(1)
+ parent_issue.update_attribute(:fixed_version_id, 4)
+ parent_issue.reload
+ assert_equal 4, parent_issue.fixed_version_id
+
+ # Should keep fixed versions for the issues
+ issue_with_local_fixed_version = Issue.find(5)
+ issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
+ issue_with_local_fixed_version.reload
+ assert_equal 4, issue_with_local_fixed_version.fixed_version_id
+
+ # Local issue with hierarchy fixed_version
+ issue_with_hierarchy_fixed_version = Issue.find(13)
+ issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
+ issue_with_hierarchy_fixed_version.reload
+ assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
+
+ # Move project out of the issue's hierarchy
+ moved_project = Project.find(3)
+ moved_project.set_parent!(Project.find(2))
+ parent_issue.reload
+ issue_with_local_fixed_version.reload
+ issue_with_hierarchy_fixed_version.reload
+
+ assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project"
+ assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in"
+ assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue."
+ end
def test_parent
p = Project.find(6).parent
@@ -277,13 +317,61 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
end
+
+ def test_shared_versions
+ parent = Project.find(1)
+ child = parent.children.find(3)
+ private_child = parent.children.find(5)
+
+ assert_equal [1,2,3], parent.version_ids.sort
+ assert_equal [4], child.version_ids
+ assert_equal [6], private_child.version_ids
+ assert_equal [7], Version.find_all_by_sharing('system').collect(&:id)
+
+ assert_equal 6, parent.shared_versions.size
+ parent.shared_versions.each do |version|
+ assert_kind_of Version, version
+ end
+
+ assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort
+ end
+
+ def test_shared_versions_should_ignore_archived_subprojects
+ parent = Project.find(1)
+ child = parent.children.find(3)
+ child.archive
+ parent.reload
+
+ assert_equal [1,2,3], parent.version_ids.sort
+ assert_equal [4], child.version_ids
+ assert !parent.shared_versions.collect(&:id).include?(4)
+ end
+
+ def test_shared_versions_visible_to_user
+ user = User.find(3)
+ parent = Project.find(1)
+ child = parent.children.find(5)
+
+ assert_equal [1,2,3], parent.version_ids.sort
+ assert_equal [6], child.version_ids
+
+ versions = parent.shared_versions.visible(user)
+
+ assert_equal 4, versions.size
+ versions.each do |version|
+ assert_kind_of Version, version
+ end
+
+ assert !versions.collect(&:id).include?(6)
+ end
+
def test_next_identifier
ProjectCustomField.delete_all
Project.create!(:name => 'last', :identifier => 'p2008040')
assert_equal 'p2008041', Project.next_identifier
end
-
+
def test_next_identifier_first_project
Project.delete_all
assert_nil Project.next_identifier
@@ -429,13 +517,15 @@ class ProjectTest < ActiveSupport::TestCase
end
should "change the new issues to use the copied version" do
- assigned_version = Version.generate!(:name => "Assigned Issues")
+ User.current = User.find(1)
+ assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
@source_project.versions << assigned_version
- assert_equal 1, @source_project.versions.size
- @source_project.issues << Issue.generate!(:fixed_version_id => assigned_version.id,
- :subject => "change the new issues to use the copied version",
- :tracker_id => 1,
- :project_id => @source_project.id)
+ assert_equal 3, @source_project.versions.size
+ Issue.generate_for_project!(@source_project,
+ :fixed_version_id => assigned_version.id,
+ :subject => "change the new issues to use the copied version",
+ :tracker_id => 1,
+ :project_id => @source_project.id)
assert @project.copy(@source_project)
@project.reload
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 31d3cd1dd..20447473b 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -31,6 +31,14 @@ class QueryTest < ActiveSupport::TestCase
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
:conditions => query.statement
end
+
+ def test_query_should_allow_shared_versions_for_a_project_query
+ subproject_version = Version.find(4)
+ query = Query.new(:project => Project.find(1), :name => '_')
+ query.add_filter('fixed_version_id', '=', [subproject_version.id.to_s])
+
+ assert query.statement.include?("#{Issue.table_name}.fixed_version_id IN ('4')")
+ end
def test_query_with_multiple_custom_fields
query = Query.find(1)
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb
index 5702fd181..dcc1edbc8 100644
--- a/test/unit/version_test.rb
+++ b/test/unit/version_test.rb
@@ -104,6 +104,41 @@ class VersionTest < ActiveSupport::TestCase
assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent
assert_progress_equal 25.0/100.0*100, v.closed_pourcent
end
+
+ test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
+ User.current = User.find(1) # Need the admin's permissions
+
+ @version = Version.find(7)
+ # Separate hierarchy
+ project_1_issue = Issue.find(1)
+ project_1_issue.fixed_version = @version
+ assert project_1_issue.save, project_1_issue.errors.full_messages
+
+ project_5_issue = Issue.find(6)
+ project_5_issue.fixed_version = @version
+ assert project_5_issue.save
+
+ # Project
+ project_2_issue = Issue.find(4)
+ project_2_issue.fixed_version = @version
+ assert project_2_issue.save
+
+ # Update the sharing
+ @version.sharing = 'none'
+ assert @version.save
+
+ # Project 1 now out of the shared scope
+ project_1_issue.reload
+ assert_equal nil, project_1_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
+
+ # Project 5 now out of the shared scope
+ project_5_issue.reload
+ assert_equal nil, project_5_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
+
+ # Project 2 issue remains
+ project_2_issue.reload
+ assert_equal @version, project_2_issue.fixed_version
+ end
private