OSDN Git Service

Adds functional test for project copy.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 7 Apr 2011 17:25:51 +0000 (17:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 7 Apr 2011 17:25:51 +0000 (17:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5355 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/functional/projects_controller_test.rb

index 2d6e2ef..4724b74 100644 (file)
@@ -683,6 +683,7 @@ class Project < ActiveRecord::Base
   end
   
   # Copies issues from +project+
+  # Note: issues assigned to a closed version won't be copied due to validation rules
   def copy_issues(project)
     # Stores the source issue id as a key and the copied issues as the
     # value.  Used to map the two togeather for issue relations.
index 12eb372..45256f0 100644 (file)
@@ -464,16 +464,34 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_response :redirect
     assert_redirected_to :controller => 'admin', :action => 'projects'
   end
-
-  context "POST :copy" do
-    should "TODO: test the rest of the method"
-
-    should "redirect to the project settings when successful" do
-      @request.session[:user_id] = 1 # admin
-      post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
-      assert_response :redirect
-      assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
+  
+  def test_post_copy_should_copy_requested_items
+    @request.session[:user_id] = 1 # admin
+    CustomField.delete_all
+    
+    assert_difference 'Project.count' do
+      post :copy, :id => 1,
+        :project => {
+          :name => 'Copy',
+          :identifier => 'unique-copy',
+          :tracker_ids => ['1', '2', '3', ''],
+          :enabled_modules => %w(issue_tracking time_tracking)
+        },
+        :only => %w(issues versions)
     end
+    project = Project.find('unique-copy')
+    source = Project.find(1)
+    assert_equal source.versions.count, project.versions.count, "All versions were not copied"
+    # issues assigned to a closed version won't be copied
+    assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.count, project.issues.count, "All issues were not copied"
+    assert_equal 0, project.members.count
+  end
+
+  def test_post_copy_should_redirect_to_settings_when_successful
+    @request.session[:user_id] = 1 # admin
+    post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
+    assert_response :redirect
+    assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
   end
 
   def test_jump_should_redirect_to_active_tab