diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-08-11 00:55:01 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-08-11 00:55:52 -0300 |
commit | 56627b619cd72c862097c4622e2c9419be2a8a80 (patch) | |
tree | d30cfb8970d63e53ecf745f54687395803915507 /activesupport/test/number_helper_i18n_test.rb | |
parent | b6e00c67647b523e21dd5c8886859d92c0d6c5fb (diff) | |
parent | 47b4d13c8d7602fc19229dd8cb70974e401b13b2 (diff) | |
download | rails-56627b619cd72c862097c4622e2c9419be2a8a80.tar.gz rails-56627b619cd72c862097c4622e2c9419be2a8a80.tar.bz2 rails-56627b619cd72c862097c4622e2c9419be2a8a80.zip |
Merge branch 'number-helpers-defaults'
Closes #6290
Diffstat (limited to 'activesupport/test/number_helper_i18n_test.rb')
-rw-r--r-- | activesupport/test/number_helper_i18n_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index e07198027b..65aecece71 100644 --- a/activesupport/test/number_helper_i18n_test.rb +++ b/activesupport/test/number_helper_i18n_test.rb @@ -56,6 +56,13 @@ module ActiveSupport assert_equal("-$10.00", number_to_currency(-10, :locale => 'empty')) end + def test_locale_default_format_has_precedence_over_helper_defaults + I18n.backend.store_translations 'ts', + { :number => { :format => { :separator => ";" } } } + + assert_equal("&$ - 10;00", number_to_currency(10, :locale => 'ts')) + end + def test_number_to_currency_without_currency_negative_format I18n.backend.store_translations 'no_negative_format', :number => { :currency => { :format => { :unit => '@', :format => '%n %u' } } @@ -72,11 +79,24 @@ module ActiveSupport assert_equal("1.00", number_to_rounded(1.0, :locale => 'ts')) end + def test_number_with_i18n_precision_and_empty_i18n_store + I18n.backend.store_translations 'empty', {} + + assert_equal("123456789.123", number_to_rounded(123456789.123456789, :locale => 'empty')) + assert_equal("1.000", number_to_rounded(1.0000, :locale => 'empty')) + end + def test_number_with_i18n_delimiter #Delimiter "," and separator "." assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'ts')) end + def test_number_with_i18n_delimiter_and_empty_i18n_store + I18n.backend.store_translations 'empty', {} + + assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'empty')) + end + def test_number_to_i18n_percentage # to see if strip_insignificant_zeros is true assert_equal("1%", number_to_percentage(1, :locale => 'ts')) @@ -86,12 +106,27 @@ module ActiveSupport assert_equal("12434%", number_to_percentage(12434, :locale => 'ts')) end + def test_number_to_i18n_percentage_and_empty_i18n_store + I18n.backend.store_translations 'empty', {} + + assert_equal("1.000%", number_to_percentage(1, :locale => 'empty')) + assert_equal("1.243%", number_to_percentage(1.2434, :locale => 'empty')) + assert_equal("12434.000%", number_to_percentage(12434, :locale => 'empty')) + end + def test_number_to_i18n_human_size #b for bytes and k for kbytes assert_equal("2 k", number_to_human_size(2048, :locale => 'ts')) assert_equal("42 b", number_to_human_size(42, :locale => 'ts')) end + def test_number_to_i18n_human_size_with_empty_i18n_store + I18n.backend.store_translations 'empty', {} + + assert_equal("2 KB", number_to_human_size(2048, :locale => 'empty')) + assert_equal("42 Bytes", number_to_human_size(42, :locale => 'empty')) + end + def test_number_to_human_with_default_translation_scope #Using t for thousand assert_equal "2 t", number_to_human(2000, :locale => 'ts') @@ -106,6 +141,13 @@ module ActiveSupport assert_equal "2 Tens", number_to_human(20, :locale => 'ts') end + def test_number_to_human_with_empty_i18n_store + I18n.backend.store_translations 'empty', {} + + assert_equal "2 Thousand", number_to_human(2000, :locale => 'empty') + assert_equal "1.23 Billion", number_to_human(1234567890, :locale => 'empty') + end + def test_number_to_human_with_custom_translation_scope #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) |