From: Jean-Philippe Lang Date: Wed, 7 Jan 2015 22:29:50 +0000 (+0000) Subject: Fixed that project copy triggers a 500 error if project validation fails. X-Git-Tag: 3.0.0~164 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fd4a91130465f6b5ae4fc937da13e8674ee4d4de;p=redmine.git Fixed that project copy triggers a 500 error if project validation fails. git-svn-id: http://svn.redmine.org/redmine/trunk@13848 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index afb0ee0c5..deb497484 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -723,9 +723,10 @@ class Project < ActiveRecord::Base end Redmine::Hook.call_hook(:model_project_copy_before_save, :source_project => project, :destination_project => self) save + else + false end end - true end # Returns a new unsaved Project instance with attributes copied from +project+ diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 42c6ff747..8e209002d 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -608,6 +608,13 @@ class ProjectsControllerTest < ActionController::TestCase assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' end + def test_post_copy_with_failure + @request.session[:user_id] = 1 + post :copy, :id => 1, :project => {:name => 'Copy', :identifier => ''} + assert_response :success + assert_template 'copy' + end + def test_jump_should_redirect_to_active_tab get :show, :id => 1, :jump => 'issues' assert_redirected_to '/projects/ecookbook/issues' diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index 2f1f6ee59..c10a5de15 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -46,6 +46,11 @@ class ProjectCopyTest < ActiveSupport::TestCase @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) end + def test_copy_should_return_false_if_save_fails + project = Project.new(:name => 'Copy', :identifier => nil) + assert_equal false, project.copy(@source_project) + end + test "#copy should copy issues" do @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'), :subject => "copy issue status",