Skip to content

Commit

Permalink
Fix format helpers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Feb 28, 2024
1 parent 6d6fddb commit 304df93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions app/helpers/format_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def f(value)
case value
when Float, BigDecimal
number_with_precision(value, precision: t('number.format.precision'),
delimiter: t('number.format.delimiter'))
delimiter: t('number.format.delimiter').html_safe)
when Integer
number_with_delimiter(value, delimiter: t('number.format.delimiter'))
number_with_delimiter(value, delimiter: t('number.format.delimiter').html_safe)
when Date then l(value, format: :long)
when Time then "#{l(value.to_date)} #{l(value, format: :time)}"
when true then t('global.yes')
Expand All @@ -43,7 +43,8 @@ def format_attr(obj, attr)
end

def format_number(number, precision = 2)
number_with_precision(number, precision:, delimiter: '\'')
delimiter = t('number.format.delimiter').html_safe
number_with_precision(number, precision:, delimiter:)
end

def format_hour(hour, precision = 2)
Expand Down Expand Up @@ -173,7 +174,7 @@ def format_type(obj, attr)
when :decimal
number_with_precision(val.to_s.to_f,
precision: column_property(obj, attr, :scale),
delimiter: t('number.format.delimiter'))
delimiter: t('number.format.delimiter').html_safe)
else f(val)
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/helpers/format_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def format_string_size(obj)
assert_equal '0.00', format_number(0.0001)
assert_equal '0.50', format_number(0.5)
assert_equal '8.33', format_number(8.33333)
assert_equal '1'234.56', format_number(1234.56)
assert_equal "1'234.56", format_number(1234.56)
end

test 'format hour' do
assert_nil format_hour(nil)
assert_equal '0.00 h', format_hour(0.0001)
assert_equal '0.50 h', format_hour(0.5)
assert_equal '8.33 h', format_hour(8.33333)
assert_equal '1'234.56 h', format_hour(1234.56)
assert_equal "1'234.56 h", format_hour(1234.56)
end

test 'format day' do
Expand Down Expand Up @@ -131,7 +131,7 @@ def format_string_size(obj)

m.children = 10_000

assert_equal '10'000', format_type(m, :children)
assert_equal "10'000", format_type(m, :children)
end

unless ENV['NON_LOCALIZED'] # localization dependent tests
Expand All @@ -148,7 +148,7 @@ def format_string_size(obj)
test 'format decimal column' do
m = crud_test_models(:AAAAA)

assert_equal '10'000'000.1111', format_type(m, :income)
assert_equal "10'000'000.1111", format_type(m, :income)
end

test 'format date column' do
Expand Down

0 comments on commit 304df93

Please sign in to comment.