]> source.dussan.org Git - redmine.git/commitdiff
Fixed that creating an issue without tracker_id attribute ignores custom field values...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Mar 2015 09:53:36 +0000 (09:53 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Mar 2015 09:53:36 +0000 (09:53 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14083 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/integration/api_test/issues_test.rb

index 8df0082d03b610b32723a8b2489fc2a94490cc23..57bfa41e079c042ef5a1f28d9548cb84d25b16b8 100644 (file)
@@ -447,6 +447,11 @@ class Issue < ActiveRecord::Base
     if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
       self.tracker_id = t
     end
+    if project
+      # Set the default tracker to accept custom field values
+      # even if tracker is not specified
+      self.tracker ||= project.trackers.first
+    end
 
     if (s = attrs.delete('status_id')) && safe_attribute?('status_id')
       if new_statuses_allowed_to(user).collect(&:id).include?(s.to_i)
index 89550f1cf83d9dce74bd9e136f136cb8e7d8cff9..344962a5b24c1d3b5ff6e1afb7e4dffb8d1cbcde 100644 (file)
@@ -406,6 +406,35 @@ JSON
     assert_equal 'API test', issue.subject
   end
 
+  test "POST /issues.json without tracker_id should accept custom fields" do
+    field = IssueCustomField.generate!(
+      :field_format => 'list',
+      :multiple => true,
+      :possible_values => ["V1", "V2", "V3"],
+      :default_value => "V2",
+      :is_for_all => true,
+      :trackers => Tracker.all.to_a
+    )
+
+payload = <<-JSON
+{
+  "issue": {
+    "project_id": "1",
+    "subject": "Multivalued custom field",
+    "custom_field_values":{"#{field.id}":["V1","V3"]}
+  }
+}
+JSON
+
+    assert_difference('Issue.count') do
+      post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
+    end
+
+    assert_response :created
+    issue = Issue.order('id DESC').first
+    assert_equal ["V1", "V3"], issue.custom_field_value(field)
+  end
+
   test "POST /issues.json with failure should return errors" do
     assert_no_difference('Issue.count') do
       post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')