Project

General

Profile

Defect #42233 ยป 42233.patch

Go MAEDA, 2025-02-07 06:55

View differences:

lib/redmine/field_format.rb
if value.empty?
value << ''
end
elsif custom_field.field_format == 'float'
value = normalize_float(value)
else
value = value.to_s
end
......
end
def validate_single_value(custom_field, value, customized=nil)
value = normalize_float(value)
errs = super
errs << ::I18n.t('activerecord.errors.messages.invalid') unless Kernel.Float(value, exception: false)
errs
lib/redmine/i18n.rb
# will clash with the dot separator.
def normalize_float(value)
separator = ::I18n.t('number.format.separator')
value.gsub(/[#{separator}]/, separator => '.')
value.to_s.gsub(/[#{separator}]/, separator => '.')
end
def day_name(day)
test/unit/lib/redmine/field_format/numeric_format_test.rb
assert_equal '<a href="http://foo/3" class="external">3</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_float_field_value_should_validate_when_given_with_various_separator
def test_float_field_should_normalize_decimal_separator
field = IssueCustomField.generate!(field_format: 'float')
issue = Issue.generate!(tracker: Tracker.find(1), status: IssueStatus.find(1), priority: IssuePriority.find(6))
to_test = {'en' => '3.33', 'de' => '3,33'}
to_test.each do |locale, expected|
with_locale locale do
assert field.format.validate_single_value(field, expected, issue)
with_locale 'de' do
issue.custom_field_values = { field.id => '3,33' }
assert issue.save!
assert_equal '3.33', issue.reload.custom_field_values.last.value
end
# Comma decimal separator is not allowed in English locale
with_locale 'en' do
issue.custom_field_values = { field.id => '3,33' }
assert_raise ActiveRecord::RecordInvalid do
issue.save!
end
end
end
    (1-1/1)