diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-05-16 18:00:08 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-17 17:39:33 +0200 |
commit | c7e6777961239224e28171a46c9768db881c5506 (patch) | |
tree | e917f95140c6ddfd6a00ca4f00737643bfb4531d | |
parent | 107c6381a0a3403461f1dc00e140565028af73e1 (diff) | |
download | rails-c7e6777961239224e28171a46c9768db881c5506.tar.gz rails-c7e6777961239224e28171a46c9768db881c5506.tar.bz2 rails-c7e6777961239224e28171a46c9768db881c5506.zip |
Added default currency values to NumberHelper and pass them to I18n.translate
[#4604 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 7 | ||||
-rw-r--r-- | actionpack/test/template/number_helper_i18n_test.rb | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 01fecc0f23..fccf004adf 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -13,6 +13,9 @@ module ActionView # unchanged if can't be converted into a valid number. module NumberHelper + DEFAULT_CURRENCY_VALUES = { :format => "%u%n", :unit => "$", :separator => ".", :delimiter => ",", + :precision => 2, :significant => false, :strip_insignificant_zeros => false } + # Raised when argument +number+ param given to the helpers is invalid and # the option :raise is set to +true+. class InvalidNumberError < StandardError @@ -104,9 +107,9 @@ module ActionView defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :default => {}) - defaults = defaults.merge(currency) - options = options.reverse_merge(defaults) + defaults = DEFAULT_CURRENCY_VALUES.merge(defaults).merge!(currency) + options = defaults.merge!(options) unit = options.delete(:unit) format = options.delete(:format) diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index f730a0d7f5..8561019461 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -45,6 +45,12 @@ class NumberHelperTest < ActionView::TestCase assert_equal("&$ - 10.00", number_to_currency(10, :locale => 'ts')) end + def test_number_to_currency_with_clean_i18n_settings + clean_i18n do + assert_equal("$10.00", number_to_currency(10)) + end + end + def test_number_with_precision #Delimiter was set to "" assert_equal("10000", number_with_precision(10000, :locale => 'ts')) @@ -92,4 +98,15 @@ class NumberHelperTest < ActionView::TestCase #Significant was set to true with precision 2, with custom translated units assert_equal "4.3 cm", number_to_human(0.0432, :locale => 'ts', :units => :custom_units_for_number_to_human) end + + private + def clean_i18n + load_path = I18n.load_path.dup + I18n.load_path.clear + I18n.reload! + yield + ensure + I18n.load_path = load_path + I18n.reload! + end end |