assert_equal ["V1", "V3"], issue.custom_field_value(field).sort
end
+ test "POST /issues.json with omitted custom field should set default value" do
+ field = IssueCustomField.generate!(:default_value => "Default")
+
+ issue = new_record(Issue) do
+ post '/issues.json',
+ {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}},
+ credentials('jsmith')
+ end
+ assert_equal "Default", issue.custom_field_value(field)
+ end
+
+ test "POST /issues.json with custom field set to blank should not set default value" do
+ field = IssueCustomField.generate!(:default_value => "Default")
+
+ issue = new_record(Issue) do
+ post '/issues.json',
+ {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}},
+ credentials('jsmith')
+ end
+ assert_equal "", 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')
assert_equal "Notes only", journal.notes
end
+ test "PUT /issues/:id.json with omitted custom field should not change blank value to default value" do
+ field = IssueCustomField.generate!(:default_value => "Default")
+ issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""})
+ assert_equal "", issue.reload.custom_field_value(field)
+
+ assert_difference('Journal.count') do
+ put "/issues/#{issue.id}.json",
+ {:issue => {:custom_field_values => {}, :notes => 'API'}},
+ credentials('jsmith')
+ end
+
+ assert_equal "", issue.reload.custom_field_value(field)
+ end
+
+ test "PUT /issues/:id.json with custom field set to blank should not change blank value to default value" do
+ field = IssueCustomField.generate!(:default_value => "Default")
+ issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""})
+ assert_equal "", issue.reload.custom_field_value(field)
+
+ assert_difference('Journal.count') do
+ put "/issues/#{issue.id}.json",
+ {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
+ credentials('jsmith')
+ end
+
+ assert_equal "", issue.reload.custom_field_value(field)
+ end
+
+ test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker does not set default value" do
+ field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2])
+ issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
+
+ assert_difference('Journal.count') do
+ put "/issues/#{issue.id}.json",
+ {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}},
+ credentials('jsmith')
+ end
+
+ assert_equal 2, issue.reload.tracker_id
+ assert_nil issue.reload.custom_field_value(field)
+ end
+
+ test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do
+ field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2])
+ issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
+
+ assert_difference('Journal.count') do
+ put "/issues/#{issue.id}.json",
+ {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
+ credentials('jsmith')
+ end
+
+ assert_equal 2, issue.reload.tracker_id
+ assert_equal "", issue.reload.custom_field_value(field)
+ end
+
test "PUT /issues/:id.xml with failed update" do
put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')