]> source.dussan.org Git - redmine.git/commitdiff
Tests for #29674.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 28 Nov 2018 18:15:56 +0000 (18:15 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 28 Nov 2018 18:15:56 +0000 (18:15 +0000)
Patch by Takenori TAKAKI.

git-svn-id: http://svn.redmine.org/redmine/trunk@17646 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/unit/lib/redmine/field_format/list_format_test.rb
test/unit/lib/redmine/field_format/user_field_format_test.rb
test/unit/lib/redmine/field_format/version_field_format_test.rb

index fc2459d4a5c58fddf0423b904953bb0d929eb87c..8a19e3527e320b14f6955e6695ec5e5e30cd1675 100644 (file)
@@ -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)
index 802fa7a34f7dad5ed6ef423f519e1ff5e8d7f990..7c726957f2b160912cbb103fbe6f971166b03a8c 100644 (file)
@@ -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)
index 12de01479177ff9f10bd4f6a43201d670a05e829..34e492b28e968a82292c5de1808d9917208f5fb7 100644 (file)
@@ -49,6 +49,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)