Commit 9cbb0914 authored by jplang's avatar jplang

Adds tests for default custom field value (#21074).

git-svn-id: https://svn.redmine.org/redmine/trunk@14768 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent d77806c3
......@@ -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')
......
......@@ -190,6 +190,13 @@ module ObjectHelpers
field
end
def IssueCustomField.generate!(attributes={})
super do |field|
field.is_for_all = true unless attributes.key?(:is_for_all)
field.tracker_ids = Tracker.all.ids unless attributes.key?(:tracker_ids) || attributes.key?(:trackers)
end
end
def Changeset.generate!(attributes={})
@generated_changeset_rev ||= '123456'
@generated_changeset_rev.succ!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment