summaryrefslogtreecommitdiffstats
path: root/test/unit/custom_field_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/custom_field_test.rb')
-rw-r--r--test/unit/custom_field_test.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb
index b99fb4353..0da6f8ba8 100644
--- a/test/unit/custom_field_test.rb
+++ b/test/unit/custom_field_test.rb
@@ -63,12 +63,12 @@ class CustomFieldTest < ActiveSupport::TestCase
end
def test_field_format_validation_should_accept_formats_added_at_runtime
- Redmine::CustomFieldFormat.register 'foobar'
+ Redmine::FieldFormat.add 'foobar', Class.new(Redmine::FieldFormat::Base)
field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar')
assert field.valid?, 'field should be valid'
ensure
- Redmine::CustomFieldFormat.delete 'foobar'
+ Redmine::FieldFormat.delete 'foobar'
end
def test_should_not_change_field_format_of_existing_custom_field
@@ -293,4 +293,18 @@ class CustomFieldTest < ActiveSupport::TestCase
assert_equal [fields[0]], CustomField.visible(User.anonymous).order("id").to_a
end
+
+ def test_float_cast_blank_value_should_return_nil
+ field = CustomField.new(:field_format => 'float')
+ assert_equal nil, field.cast_value(nil)
+ assert_equal nil, field.cast_value('')
+ end
+
+ def test_float_cast_valid_value_should_return_float
+ field = CustomField.new(:field_format => 'float')
+ assert_equal 12.0, field.cast_value('12')
+ assert_equal 12.5, field.cast_value('12.5')
+ assert_equal 12.5, field.cast_value('+12.5')
+ assert_equal -12.5, field.cast_value('-12.5')
+ end
end