mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
fix: Locale-aware currency formatting (#677)
* fix: Locale-aware currency formatting Add locale-specific formatting for money display: - French (fr): symbol after number with non-breaking space (1 000,12 €) - German (de): symbol after number (1.000,12 €) - Spanish (es): symbol after number (1.000,12 €) - Italian (it): symbol after number (1.000,12 €) - Portuguese-Brazil (pt-BR): symbol before with space (R$ 1.000,12) This follows international conventions where most European languages place the currency symbol after the number, unlike English. * fix: Address CodeRabbit review comments - Use non-breaking spaces (NBSP) for French locale formatting - Add nil guard in locale_options to prevent NoMethodError - Add test coverage for Portuguese (Brazil) locale Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,29 @@ class MoneyTest < ActiveSupport::TestCase
|
||||
assert_equal "€ 1.000,12", Money.new(1000.12, :eur).format(locale: :nl)
|
||||
end
|
||||
|
||||
test "formats correctly for French locale" do
|
||||
# French uses non-breaking spaces (NBSP = \u00A0) between thousands and before currency symbol
|
||||
assert_equal "1\u00A0000,12\u00A0€", Money.new(1000.12, :eur).format(locale: :fr)
|
||||
assert_equal "1\u00A0000,12\u00A0$", Money.new(1000.12, :usd).format(locale: :fr)
|
||||
end
|
||||
|
||||
test "formats correctly for German locale" do
|
||||
assert_equal "1.000,12 €", Money.new(1000.12, :eur).format(locale: :de)
|
||||
assert_equal "1.000,12 $", Money.new(1000.12, :usd).format(locale: :de)
|
||||
end
|
||||
|
||||
test "formats correctly for Spanish locale" do
|
||||
assert_equal "1.000,12 €", Money.new(1000.12, :eur).format(locale: :es)
|
||||
end
|
||||
|
||||
test "formats correctly for Italian locale" do
|
||||
assert_equal "1.000,12 €", Money.new(1000.12, :eur).format(locale: :it)
|
||||
end
|
||||
|
||||
test "formats correctly for Portuguese (Brazil) locale" do
|
||||
assert_equal "R$ 1.000,12", Money.new(1000.12, :brl).format(locale: :"pt-BR")
|
||||
end
|
||||
|
||||
test "converts currency when rate available" do
|
||||
ExchangeRate.expects(:find_or_fetch_rate).returns(OpenStruct.new(rate: 1.2))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user