diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-11-29 15:44:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-11-29 15:44:32 +0000 |
commit | f2b0e224a1aa80c8c2442890678239629395bae4 (patch) | |
tree | ff0aca9de6c53fdb5b9fd0c0aca4845c9cd15c46 | |
parent | edd27a3216657ceda278e2f61d1aa76d8ca920f4 (diff) | |
download | redmine-f2b0e224a1aa80c8c2442890678239629395bae4.tar.gz redmine-f2b0e224a1aa80c8c2442890678239629395bae4.zip |
Merged r17645 to 3.3-stable (#29674).
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@17655 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/field_format.rb | 10 | ||||
-rw-r--r-- | test/unit/lib/redmine/field_format/list_format_test.rb | 10 | ||||
-rw-r--r-- | test/unit/lib/redmine/field_format/user_field_format_test.rb | 15 | ||||
-rw-r--r-- | test/unit/lib/redmine/field_format/version_field_format_test.rb | 14 |
4 files changed, 49 insertions, 0 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index bdc0d1a98..e5591284b 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -674,6 +674,16 @@ module Redmine options end + def validate_custom_value(custom_value) + values = Array.wrap(custom_value.value).reject {|value| value.to_s == ''} + invalid_values = values - possible_custom_value_options(custom_value).map(&:last) + if invalid_values.any? + [::I18n.t('activerecord.errors.messages.inclusion')] + else + [] + end + end + def order_statement(custom_field) if target_class.respond_to?(:fields_for_order_statement) target_class.fields_for_order_statement(value_join_alias(custom_field)) diff --git a/test/unit/lib/redmine/field_format/list_format_test.rb b/test/unit/lib/redmine/field_format/list_format_test.rb index af44cc59f..c6d72435e 100644 --- a/test/unit/lib/redmine/field_format/list_format_test.rb +++ b/test/unit/lib/redmine/field_format/list_format_test.rb @@ -37,6 +37,16 @@ class Redmine::ListFieldFormatTest < ActionView::TestCase assert group.valid? end + def test_non_existing_value_should_be_invalid + field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar']) + group = Group.new(:name => 'Group') + group.custom_field_values = {field.id => 'Baz'} + + assert_not_include 'Baz', field.possible_custom_value_options(group.custom_value_for(field)) + assert_equal false, group.valid? + assert_include "List #{::I18n.t('activerecord.errors.messages.inclusion')}", group.errors.full_messages.first + end + def test_edit_tag_should_have_id_and_name field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false) value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) diff --git a/test/unit/lib/redmine/field_format/user_field_format_test.rb b/test/unit/lib/redmine/field_format/user_field_format_test.rb index 6aa751be8..97f5d2d14 100644 --- a/test/unit/lib/redmine/field_format/user_field_format_test.rb +++ b/test/unit/lib/redmine/field_format/user_field_format_test.rb @@ -45,6 +45,21 @@ class Redmine::UserFieldFormatTest < ActionView::TestCase assert issue.valid? end + def test_non_existing_values_should_be_invalid + field = IssueCustomField.create!(:name => 'Foo', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all) + project = Project.generate! + user = User.generate! + User.add_to_project(user, project, Role.find_by_name('Developer')) + + field.user_role = [Role.find_by_name('Manager').id] + field.save! + + issue = Issue.new(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => user.id}) + assert_not_include [user.name, user.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field)) + assert_equal false, issue.valid? + assert_include "Foo #{::I18n.t('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first + end + def test_possible_values_options_should_return_project_members field = IssueCustomField.new(:field_format => 'user') project = Project.find(1) diff --git a/test/unit/lib/redmine/field_format/version_field_format_test.rb b/test/unit/lib/redmine/field_format/version_field_format_test.rb index 0b3006c65..fca4e95fd 100644 --- a/test/unit/lib/redmine/field_format/version_field_format_test.rb +++ b/test/unit/lib/redmine/field_format/version_field_format_test.rb @@ -44,6 +44,20 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase assert issue.valid? end + def test_not_existing_values_should_be_invalid + field = IssueCustomField.create!(:name => 'Foo', :field_format => 'version', :is_for_all => true, :trackers => Tracker.all) + project = Project.generate! + version = Version.generate!(:project => project, :status => 'closed') + + field.version_status = ["open"] + field.save! + + issue = Issue.new(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => version.id}) + assert_not_include [version.name, version.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field)) + assert_equal false, issue.valid? + assert_include "Foo #{::I18n.t('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first + end + def test_possible_values_options_should_return_project_versions field = IssueCustomField.new(:field_format => 'version') project = Project.find(1) |