]> source.dussan.org Git - redmine.git/commitdiff
Fixed that project copy triggers a 500 error if project validation fails.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 22:29:50 +0000 (22:29 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 22:29:50 +0000 (22:29 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13848 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index afb0ee0c5f6bb56b8bd1a0237a2ccc5d29923a80..deb497484eeaa8c737f64a86c8b4c76ed14d0b5c 100644 (file)
@@ -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+
index 42c6ff74707b65f47e9819cbc3457874f1e17c9e..8e209002d10aa1ce160a8fc9d5b4bda57db5f75b 100644 (file)
@@ -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'
index 2f1f6ee59974407b280a452a2de8cf4cc44f71a1..c10a5de15c097f3d5ec3fdfccd407d7655881195 100644 (file)
@@ -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",