summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-12 09:12:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-12 09:12:09 +0000
commit5c1039a69e93fe815d4254a8d0edb4f073692b42 (patch)
tree3c7ab664cb254cf008354e717922cdf4fdaacad8 /test/unit
parent44ceb513ed1707eef2d3f66d4639207df5585e1f (diff)
downloadredmine-5c1039a69e93fe815d4254a8d0edb4f073692b42.tar.gz
redmine-5c1039a69e93fe815d4254a8d0edb4f073692b42.zip
Ability to uncheck "Multiple values" for existing custom fields (#12251).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11167 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/custom_field_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb
index c3e9962f2..ee78fb23f 100644
--- a/test/unit/custom_field_test.rb
+++ b/test/unit/custom_field_test.rb
@@ -209,6 +209,24 @@ class CustomFieldTest < ActiveSupport::TestCase
assert !f.valid_field_value?(['value1', 'abc'])
end
+ def test_changing_multiple_to_false_should_delete_multiple_values
+ field = ProjectCustomField.create!(:name => 'field', :field_format => 'list', :multiple => 'true', :possible_values => ['field1', 'field2'])
+ other = ProjectCustomField.create!(:name => 'other', :field_format => 'list', :multiple => 'true', :possible_values => ['other1', 'other2'])
+
+ item_with_multiple_values = Project.generate!(:custom_field_values => {field.id => ['field1', 'field2'], other.id => ['other1', 'other2']})
+ item_with_single_values = Project.generate!(:custom_field_values => {field.id => ['field1'], other.id => ['other2']})
+
+ assert_difference 'CustomValue.count', -1 do
+ field.multiple = false
+ field.save!
+ end
+
+ item_with_multiple_values = Project.find(item_with_multiple_values.id)
+ assert_kind_of String, item_with_multiple_values.custom_field_value(field)
+ assert_kind_of Array, item_with_multiple_values.custom_field_value(other)
+ assert_equal 2, item_with_multiple_values.custom_field_value(other).size
+ end
+
def test_value_class_should_return_the_class_used_for_fields_values
assert_equal User, CustomField.new(:field_format => 'user').value_class
assert_equal Version, CustomField.new(:field_format => 'version').value_class