]> source.dussan.org Git - redmine.git/commitdiff
Merged r15318 and r15319 (#22342).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 12 Apr 2016 16:55:30 +0000 (16:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 12 Apr 2016 16:55:30 +0000 (16:55 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.2-stable@15329 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
test/functional/issues_controller_test.rb

index cf657d63ac90a65ae2aa578f039f3c32be2eb558..ae3dd103a8d6eda3ca7ffa98ad7f3d148dd1d87d 100644 (file)
@@ -302,16 +302,17 @@ class Issue < ActiveRecord::Base
   # * or if the status was not part of the new tracker statuses
   # * or the status was nil
   def tracker=(tracker)
-    if tracker != self.tracker
-      if status == default_status
+    tracker_was = self.tracker
+    association(:tracker).writer(tracker)
+    if tracker != tracker_was
+      if status == tracker_was.try(:default_status)
         self.status = nil
       elsif status && tracker && !tracker.issue_status_ids.include?(status.id)
         self.status = nil
       end
-      @custom_field_values = nil
+      reassign_custom_field_values
       @workflow_rule_by_attribute = nil
     end
-    association(:tracker).writer(tracker)
     self.status ||= default_status
     self.tracker
   end
@@ -355,7 +356,7 @@ class Issue < ActiveRecord::Base
       unless valid_parent_project?
         self.parent_issue_id = nil
       end
-      @custom_field_values = nil
+      reassign_custom_field_values
       @workflow_rule_by_attribute = nil
     end
     # Set fixed_version to the project default version if it's valid
index 1cde646e91bb6a437f06e7692e8d6ca23e94f06b..050e442b47433e9d53a800eb400966c42436a3d4 100644 (file)
@@ -151,6 +151,14 @@ module Redmine
           true
         end
 
+        def reassign_custom_field_values
+          if @custom_field_values
+            values = @custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
+            @custom_field_values = nil
+            self.custom_field_values = values
+          end
+        end
+
         def reset_custom_values!
           @custom_field_values = nil
           @custom_field_values_changed = true
index 92ee15c21414801d8293b9e863ed6c0aa3b2052e..3c687c64b699d325e2b1f1ea9c63177a263717d9 100644 (file)
@@ -2982,6 +2982,24 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
   end
 
+  def test_create_as_copy_to_a_different_project_should_copy_subtask_custom_fields
+    issue = Issue.generate! {|i| i.custom_field_values = {'2' => 'Foo'}}
+    child = Issue.generate!(:parent_issue_id => issue.id) {|i| i.custom_field_values = {'2' => 'Bar'}}
+    @request.session[:user_id] = 1
+
+    assert_difference 'Issue.count', 2 do
+      post :create, :project_id => 'ecookbook', :copy_from => issue.id,
+        :issue => {:project_id => '2', :tracker_id => 1, :status_id => '1',
+                   :subject => 'Copy with subtasks', :custom_field_values => {'2' => 'Foo'}},
+        :copy_subtasks => '1'
+    end
+
+    child_copy, issue_copy = Issue.order(:id => :desc).limit(2).to_a
+    assert_equal 2, issue_copy.project_id
+    assert_equal 'Foo', issue_copy.custom_field_value(2)
+    assert_equal 'Bar', child_copy.custom_field_value(2)
+  end
+
   def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
     @request.session[:user_id] = 2
     issue = Issue.generate_with_descendants!