]> source.dussan.org Git - redmine.git/commitdiff
Do not clear category on project change if category with same exists (#16941).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 20 Oct 2015 18:57:44 +0000 (18:57 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 20 Oct 2015 18:57:44 +0000 (18:57 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14715 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/functional/issues_controller_test.rb

index ed39a5a737530368606ceb23073635e296941035..3d57c722c72db8787d1858a235111752f1e2a7b0 100644 (file)
@@ -454,6 +454,11 @@ class Issue < ActiveRecord::Base
       if allowed_target_projects(user).where(:id => p.to_i).exists?
         self.project_id = p
       end
+
+      if project_id_changed? && attrs['category_id'].to_s == category_id_was.to_s
+        # Discard submitted category on previous project
+        attrs.delete('category_id')
+      end
     end
 
     if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
index 9c56b2a24e18fb21df62e84531e49e6819194aed..48ba8148500e987e53c3bafa11a053af70f4d361 100644 (file)
@@ -3096,6 +3096,22 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal 'This is the test_new issue', issue.subject
   end
 
+  def test_update_form_should_keep_category_with_same_when_changing_project
+    source = Project.generate!
+    target = Project.generate!
+    source_category = IssueCategory.create!(:name => 'Foo', :project => source)
+    target_category = IssueCategory.create!(:name => 'Foo', :project => target)
+    issue = Issue.generate!(:project => source, :category => source_category)
+
+    @request.session[:user_id] = 1
+    patch :edit, :id => issue.id,
+      :issue => {:project_id => target.id, :category_id => source_category.id}
+    assert_response :success
+
+    issue = assigns(:issue)
+    assert_equal target_category, issue.category
+  end
+
   def test_update_form_should_propose_default_status_for_existing_issue
     @request.session[:user_id] = 2
     WorkflowTransition.delete_all