Skip to content

Commit

Permalink
Backported r14670 (#20677).
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14801 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Nov 7, 2015
1 parent c78a955 commit f85ddd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def validate_required_fields
if attribute =~ /^\d+$/
attribute = attribute.to_i
v = custom_field_values.detect {|v| v.custom_field_id == attribute }
if v && v.value.blank?
if v && Array(v.value).detect(&:present?).nil?
errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
end
else
Expand Down
25 changes: 25 additions & 0 deletions test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,31 @@ def test_create_should_validate_required_fields
assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i
end

def test_create_should_validate_required_list_fields
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
WorkflowPermission.delete_all
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
@request.session[:user_id] = 2

assert_no_difference 'Issue.count' do
post :create, :project_id => 1, :issue => {
:tracker_id => 2,
:status_id => 1,
:subject => 'Test',
:start_date => '',
:due_date => '',
:custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
}
assert_response :success
assert_template 'new'
end

assert_error_tag :content => /Foo #{ESCAPED_CANT} be blank/i
assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i
end

def test_create_should_ignore_readonly_fields
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Expand Down

0 comments on commit f85ddd0

Please sign in to comment.