summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-05-03 21:25:37 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-05-03 21:25:37 +0000
commitfa7bd1c71dca1e9c74e6d83277336321393dac9f (patch)
tree4f1adac8a535ae7424887ea21f6171a22eb698ea /test/unit
parent29c0dae1518ecb8a86d10da8e05caf70f731d746 (diff)
downloadredmine-fa7bd1c71dca1e9c74e6d83277336321393dac9f.tar.gz
redmine-fa7bd1c71dca1e9c74e6d83277336321393dac9f.zip
Added the ability to copy a project in the Project Administration panel.
* Added Copy project button. * Added Project#copy_from to duplicate a project to be modified and saved by the user * Added a ProjectsController#copy based off the add method ** Used Project#copy_from to create a duplicate project in memory * Implemented Project#copy to copy data for a project from another and save it. ** Members ** Project level queries ** Project custom fields * Added a plugin hook for Project#copy. #1125 #1556 #886 #309 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2704 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/project_test.rb86
1 files changed, 85 insertions, 1 deletions
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index f579e14ff..f9a17e2ec 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -20,7 +20,8 @@ require File.dirname(__FILE__) + '/../test_helper'
class ProjectTest < Test::Unit::TestCase
fixtures :projects, :enabled_modules,
:issues, :issue_statuses, :journals, :journal_details,
- :users, :members, :roles, :projects_trackers, :trackers, :boards
+ :users, :members, :roles, :projects_trackers, :trackers, :boards,
+ :queries
def setup
@ecookbook = Project.find(1)
@@ -221,6 +222,7 @@ class ProjectTest < Test::Unit::TestCase
assert_nil Project.next_identifier
end
+
def test_enabled_module_names_should_not_recreate_enabled_modules
project = Project.find(1)
# Remove one module
@@ -233,4 +235,86 @@ class ProjectTest < Test::Unit::TestCase
# Ids should be preserved
assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
end
+
+ def test_copy_from_existing_project
+ source_project = Project.find(1)
+ copied_project = Project.copy_from(1)
+
+ assert copied_project
+ # Cleared attributes
+ assert copied_project.id.blank?
+ assert copied_project.name.blank?
+ assert copied_project.identifier.blank?
+
+ # Duplicated attributes
+ assert_equal source_project.description, copied_project.description
+ assert_equal source_project.enabled_modules, copied_project.enabled_modules
+ assert_equal source_project.trackers, copied_project.trackers
+
+ # Default attributes
+ assert_equal 1, copied_project.status
+ end
+
+ # Context: Project#copy
+ def test_copy_should_copy_issues
+ # Setup
+ ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
+ source_project = Project.find(2)
+ Project.destroy_all :identifier => "copy-test"
+ project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
+ project.trackers = source_project.trackers
+ assert project.valid?
+
+ assert project.issues.empty?
+ assert project.copy(source_project)
+
+ # Tests
+ assert_equal source_project.issues.size, project.issues.size
+ project.issues.each do |issue|
+ assert issue.valid?
+ assert ! issue.assigned_to.blank?
+ assert_equal project, issue.project
+ end
+ end
+
+ def test_copy_should_copy_members
+ # Setup
+ ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
+ source_project = Project.find(2)
+ project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
+ project.trackers = source_project.trackers
+ project.enabled_modules = source_project.enabled_modules
+ assert project.valid?
+
+ assert project.members.empty?
+ assert project.copy(source_project)
+
+ # Tests
+ assert_equal source_project.members.size, project.members.size
+ project.members.each do |member|
+ assert member
+ assert_equal project, member.project
+ end
+ end
+
+ def test_copy_should_copy_project_level_queries
+ # Setup
+ ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
+ source_project = Project.find(2)
+ project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
+ project.trackers = source_project.trackers
+ project.enabled_modules = source_project.enabled_modules
+ assert project.valid?
+
+ assert project.queries.empty?
+ assert project.copy(source_project)
+
+ # Tests
+ assert_equal source_project.queries.size, project.queries.size
+ project.queries.each do |query|
+ assert query
+ assert_equal project, query.project
+ end
+ end
+
end