summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-07 08:16:50 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-07 08:16:50 +0000
commitf85ddd022ea0f4b0610824805c3c035d9d1a6838 (patch)
tree00116386c2888fc0ea0e0eb607f61688a6a2ec23
parentc78a95576c8efd0c8d7bb2d763b1fb747840e498 (diff)
downloadredmine-f85ddd022ea0f4b0610824805c3c035d9d1a6838.tar.gz
redmine-f85ddd022ea0f4b0610824805c3c035d9d1a6838.zip
Backported r14670 (#20677).
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14801 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue.rb2
-rw-r--r--test/functional/issues_controller_test.rb25
2 files changed, 26 insertions, 1 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 3d9627c1f..0d52c8f0e 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -637,7 +637,7 @@ class Issue < ActiveRecord::Base
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
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 5c5960401..5df62cd92 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -2021,6 +2021,31 @@ class IssuesControllerTest < ActionController::TestCase
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])