From c2d2761caaf08df3b5e867cbb60622b79706dd37 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 7 Apr 2011 17:25:51 +0000 Subject: [PATCH] Adds functional test for project copy. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5355 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 1 + test/functional/projects_controller_test.rb | 36 +++++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2d6e2ef0e..4724b7465 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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. diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 12eb372e0..45256f02c 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -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 -- 2.39.5