Merged r23495 from trunk to 6.0-stable (#42233).

git-svn-id: https://svn.redmine.org/redmine/branches/6.0-stable@23501 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2025-02-09 21:59:52 +00:00
parent 700183b68b
commit e284a57fd6
3 changed files with 16 additions and 7 deletions

View File

@@ -130,6 +130,8 @@ module Redmine
if value.empty?
value << ''
end
elsif custom_field.field_format == 'float'
value = normalize_float(value)
else
value = value.to_s
end
@@ -540,7 +542,6 @@ module Redmine
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

View File

@@ -111,7 +111,7 @@ module Redmine
# 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)

View File

@@ -33,13 +33,21 @@ class Redmine::NumericFieldFormatTest < ActionView::TestCase
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