]> source.dussan.org Git - redmine.git/commitdiff
Adding a subtask should default to a tracker without disabled parent field (#16260).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 8 Mar 2017 21:22:08 +0000 (21:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 8 Mar 2017 21:22:08 +0000 (21:22 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16383 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index d96f61e15bccb3fd8f9afd4cfffb566374ba26bc..a8b68ccbb380ce614284f70b940792be45d2eef9 100644 (file)
@@ -530,10 +530,17 @@ class Issue < ActiveRecord::Base
         self.tracker_id = t
       end
     end
-    if project
+    if project && tracker.nil?
       # Set a default tracker to accept custom field values
       # even if tracker is not specified
-      self.tracker ||= allowed_target_trackers(user).first
+      allowed_trackers = allowed_target_trackers(user)
+
+      if attrs['parent_issue_id'].present?
+        # If parent_issue_id is present, the first tracker for which this field
+        # is not disabled is chosen as default
+        self.tracker = allowed_trackers.detect {|t| t.core_fields.include?('parent_issue_id')}
+      end
+      self.tracker ||= allowed_trackers.first
     end
 
     statuses_allowed = new_statuses_allowed_to(user)
index f120baba2451db413d1eefb33751e74a3482202d..24ec49a709a8d8e5d7746e62095b0381146692b4 100644 (file)
@@ -1920,6 +1920,32 @@ class IssuesControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_new_should_default_to_first_tracker
+    @request.session[:user_id] = 2
+
+    get :new, :project_id => 1
+    assert_response :success
+    assert_select 'select[name=?]', 'issue[tracker_id]' do
+      assert_select 'option', 3
+      assert_select 'option[value="1"][selected=selected]'
+    end
+  end
+
+  def test_new_with_parent_issue_id_should_default_to_first_tracker_without_disabled_parent_field
+    tracker = Tracker.find(1)
+    tracker.core_fields -= ['parent_issue_id']
+    tracker.save!
+    @request.session[:user_id] = 2
+
+    get :new, :project_id => 1, :issue => {:parent_issue_id => 1}
+    assert_response :success
+    assert_select 'select[name=?]', 'issue[tracker_id]' do
+      assert_select 'option', 2
+      assert_select 'option[value="2"][selected=selected]'
+      assert_select 'option[value="1"]', 0
+    end
+  end
+
   def test_new_without_allowed_trackers_should_respond_with_403
     role = Role.find(1)
     role.set_permission_trackers 'add_issues', []