summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-10-19 00:07:37 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-10-19 00:07:37 +0000
commita150689be9281f3a814cd5bdedd42f80f431fe41 (patch)
treedc9f10c027d2f985aa36f47272a6b49ba38bbcd5 /test
parent6531c3f88721c083f32c3e313efec6b40708382a (diff)
downloadredmine-a150689be9281f3a814cd5bdedd42f80f431fe41.tar.gz
redmine-a150689be9281f3a814cd5bdedd42f80f431fe41.zip
Improved Project#copy to copy more data from the source Project. #3367
* Versions * Associate the copied issues with the new versions * Wiki * WikiPages * WikiContents * IssueCategories git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2934 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/exemplars/user_exemplar.rb2
-rw-r--r--test/exemplars/version_exemplar.rb10
-rw-r--r--test/test_helper.rb13
-rw-r--r--test/unit/project_test.rb82
4 files changed, 105 insertions, 2 deletions
diff --git a/test/exemplars/user_exemplar.rb b/test/exemplars/user_exemplar.rb
index d88f5fe7d..154b16d8f 100644
--- a/test/exemplars/user_exemplar.rb
+++ b/test/exemplars/user_exemplar.rb
@@ -1,4 +1,4 @@
-class User < ActiveRecord::Base
+class User < Principal
generator_for :login, :method => :next_email
generator_for :mail, :method => :next_email
generator_for :firstname, :method => :next_firstname
diff --git a/test/exemplars/version_exemplar.rb b/test/exemplars/version_exemplar.rb
new file mode 100644
index 000000000..8aef99f4b
--- /dev/null
+++ b/test/exemplars/version_exemplar.rb
@@ -0,0 +1,10 @@
+class Version < ActiveRecord::Base
+ generator_for :name, :method => :next_name
+
+ def self.next_name
+ @last_name ||= 'Version 1.0.0'
+ @last_name.succ!
+ @last_name
+ end
+
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 308b43097..37f8bfd00 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -21,6 +21,19 @@ require 'test_help'
require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb')
+# TODO: The gem or official version of ObjectDaddy doesn't set
+# protected attributes so they need to be wrapped.
+def User.generate_with_protected!(attributes={})
+ user = User.spawn(attributes) do |user|
+ user.login = User.next_login
+ attributes.each do |attr,v|
+ user.send("#{attr}=", v)
+ end
+ end
+ user.save!
+ user
+end
+
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index cd4be20e8..2ace065ab 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -290,7 +290,7 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal 1, copied_project.status
end
- context "#copy" do
+ context "Project#copy" do
setup do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
Project.destroy_all :identifier => "copy-test"
@@ -313,6 +313,25 @@ class ProjectTest < ActiveSupport::TestCase
end
end
+ should "change the new issues to use the copied version" do
+ assigned_version = Version.generate!(:name => "Assigned Issues")
+ @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 @project.copy(@source_project)
+ @project.reload
+ copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
+
+ assert copied_issue
+ assert copied_issue.fixed_version
+ assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
+ assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
+ end
+
should "copy members" do
assert @project.valid?
assert @project.members.empty?
@@ -337,6 +356,67 @@ class ProjectTest < ActiveSupport::TestCase
end
end
+ should "copy versions" do
+ @source_project.versions << Version.generate!
+ @source_project.versions << Version.generate!
+
+ assert @project.versions.empty?
+ assert @project.copy(@source_project)
+
+ assert_equal @source_project.versions.size, @project.versions.size
+ @project.versions.each do |version|
+ assert version
+ assert_equal @project, version.project
+ end
+ end
+
+ should "copy wiki" do
+ assert @project.copy(@source_project)
+
+ assert @project.wiki
+ assert_not_equal @source_project.wiki, @project.wiki
+ assert_equal "Start page", @project.wiki.start_page
+ end
+
+ should "copy wiki pages and content" do
+ assert @project.copy(@source_project)
+
+ assert @project.wiki
+ assert_equal 1, @project.wiki.pages.length
+
+ @project.wiki.pages.each do |wiki_page|
+ assert wiki_page.content
+ assert !@source_project.wiki.pages.include?(wiki_page)
+ end
+ end
+
+ should "copy custom fields"
+
+ should "copy issue categories" do
+ assert @project.copy(@source_project)
+
+ assert_equal 2, @project.issue_categories.size
+ @project.issue_categories.each do |issue_category|
+ assert !@source_project.issue_categories.include?(issue_category)
+ end
+ end
+
+ should "change the new issues to use the copied issue categories" do
+ issue = Issue.find(4)
+ issue.update_attribute(:category_id, 3)
+
+ assert @project.copy(@source_project)
+
+ @project.issues.each do |issue|
+ assert issue.category
+ assert_equal "Stock management", issue.category.name # Same name
+ assert_not_equal IssueCategory.find(3), issue.category # Different record
+ end
+ end
+
+ should "copy issue relations"
+ should "link issue relations if cross project issue relations are valid"
+
end
end