comparison test/unit/custom_field_test.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
207 207
208 assert f.valid_field_value?(['value1', 'value2']) 208 assert f.valid_field_value?(['value1', 'value2'])
209 assert !f.valid_field_value?(['value1', 'abc']) 209 assert !f.valid_field_value?(['value1', 'abc'])
210 end 210 end
211 211
212 def test_changing_multiple_to_false_should_delete_multiple_values
213 field = ProjectCustomField.create!(:name => 'field', :field_format => 'list', :multiple => 'true', :possible_values => ['field1', 'field2'])
214 other = ProjectCustomField.create!(:name => 'other', :field_format => 'list', :multiple => 'true', :possible_values => ['other1', 'other2'])
215
216 item_with_multiple_values = Project.generate!(:custom_field_values => {field.id => ['field1', 'field2'], other.id => ['other1', 'other2']})
217 item_with_single_values = Project.generate!(:custom_field_values => {field.id => ['field1'], other.id => ['other2']})
218
219 assert_difference 'CustomValue.count', -1 do
220 field.multiple = false
221 field.save!
222 end
223
224 item_with_multiple_values = Project.find(item_with_multiple_values.id)
225 assert_kind_of String, item_with_multiple_values.custom_field_value(field)
226 assert_kind_of Array, item_with_multiple_values.custom_field_value(other)
227 assert_equal 2, item_with_multiple_values.custom_field_value(other).size
228 end
229
212 def test_value_class_should_return_the_class_used_for_fields_values 230 def test_value_class_should_return_the_class_used_for_fields_values
213 assert_equal User, CustomField.new(:field_format => 'user').value_class 231 assert_equal User, CustomField.new(:field_format => 'user').value_class
214 assert_equal Version, CustomField.new(:field_format => 'version').value_class 232 assert_equal Version, CustomField.new(:field_format => 'version').value_class
215 end 233 end
216 234