Project

General

Profile

« Previous | Next » 

Revision 14670

List custom fields with multiple values set as required by workflow can be blank (#20677).

Patch by Pavel Rosický.

View differences:

trunk/app/models/issue.rb
660 660
      if attribute =~ /^\d+$/
661 661
        attribute = attribute.to_i
662 662
        v = custom_field_values.detect {|v| v.custom_field_id == attribute }
663
        if v && v.value.blank?
663
        if v && Array(v.value).detect(&:present?).nil?
664 664
          errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
665 665
        end
666 666
      else
trunk/test/functional/issues_controller_test.rb
2169 2169
    assert_select_error /Bar cannot be blank/i
2170 2170
  end
2171 2171

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

  
2180
    assert_no_difference 'Issue.count' do
2181
      post :create, :project_id => 1, :issue => {
2182
        :tracker_id => 2,
2183
        :status_id => 1,
2184
        :subject => 'Test',
2185
        :start_date => '',
2186
        :due_date => '',
2187
        :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
2188
      }
2189
      assert_response :success
2190
      assert_template 'new'
2191
    end
2192

  
2193
    assert_select_error /Foo cannot be blank/i
2194
    assert_select_error /Bar cannot be blank/i
2195
  end
2196

  
2172 2197
  def test_create_should_ignore_readonly_fields
2173 2198
    cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2174 2199
    cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])

Also available in: Unified diff