]> source.dussan.org Git - redmine.git/commitdiff
When moving an issue to another project, reassign it to the category with same name...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Jul 2008 09:27:07 +0000 (09:27 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Jul 2008 09:27:07 +0000 (09:27 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1697 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/fixtures/issue_categories.yml
test/unit/issue_test.rb

index cae603dd8dd3f15dcf557b2e04dfa5d715c9555a..e2405a04cb00d9d34280b62a9b6fca02292e9347 100644 (file)
@@ -77,7 +77,9 @@ class Issue < ActiveRecord::Base
           self.relations_to.clear
         end
         # issue is moved to another project
-        self.category = nil 
+        # reassign to the category with same name if any
+        new_category = category.nil? ? nil : new_project.issue_categories.find_by_name(category.name)
+        self.category = new_category
         self.fixed_version = nil
         self.project = new_project
       end
index 2b74b59775729dc63fb9c2642a379457cc01283b..aa2f703510e20b77264f5c701784658e5a644a14 100644 (file)
@@ -14,4 +14,9 @@ issue_categories_003:
   project_id: 2\r
   assigned_to_id: \r
   id: 3\r
+issue_categories_004: \r
+  name: Printing\r
+  project_id: 2\r
+  assigned_to_id: \r
+  id: 4\r
   
\ No newline at end of file
index 0d98f89d25321cbd3b6c75a083b31e51c890bb1c..12b4da33619cd3add3c0500a897eb55d7c5b47b0 100644 (file)
@@ -165,17 +165,26 @@ class IssueTest < Test::Unit::TestCase
     assert !issue1.reload.closed?
   end
   
-  def test_move_to_another_project
+  def test_move_to_another_project_with_same_category
     issue = Issue.find(1)
     assert issue.move_to(Project.find(2))
     issue.reload
     assert_equal 2, issue.project_id
-    # Category removed
-    assert_nil issue.category
+    # Category changes
+    assert_equal 4, issue.category_id
     # Make sure time entries were move to the target project
     assert_equal 2, issue.time_entries.first.project_id
   end
   
+  def test_move_to_another_project_without_same_category
+    issue = Issue.find(2)
+    assert issue.move_to(Project.find(2))
+    issue.reload
+    assert_equal 2, issue.project_id
+    # Category cleared
+    assert_nil issue.category_id
+  end
+  
   def test_issue_destroy
     Issue.find(1).destroy
     assert_nil Issue.find_by_id(1)