summaryrefslogtreecommitdiffstats
path: root/test/integration
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-30 12:59:48 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-30 12:59:48 +0000
commitfac0f7f38b1d32a82c2e6789819e349c9d313d44 (patch)
tree33b292fde9e3325a455e6636fd120d10d30e5843 /test/integration
parent27b65d53ac66e67692edcc4ec591c2da92ad4d66 (diff)
downloadredmine-fac0f7f38b1d32a82c2e6789819e349c9d313d44.tar.gz
redmine-fac0f7f38b1d32a82c2e6789819e349c9d313d44.zip
Adds tests for default custom field value (#21074).
git-svn-id: http://svn.redmine.org/redmine/trunk@14768 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/api_test/issues_test.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb
index 08543ab15..18dbfaad9 100644
--- a/test/integration/api_test/issues_test.rb
+++ b/test/integration/api_test/issues_test.rb
@@ -435,6 +435,28 @@ JSON
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')
@@ -512,6 +534,62 @@ JSON
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')