From a9dccda936cbd3ead6d43997e6c7990f8bd92055 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 23 Jun 2012 20:05:42 -0300 Subject: Fallback to :en locale instead of handling a constant with defaults Action Pack already comes with a default locale fine for :en, that is always loaded. We can just fallback to this locale for defaults, if values for the current locale cannot be found. Closes #4420, #2802, #2890. --- activesupport/test/number_helper_i18n_test.rb | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'activesupport/test/number_helper_i18n_test.rb') diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index e07198027b..4d0d5e8631 100644 --- a/activesupport/test/number_helper_i18n_test.rb +++ b/activesupport/test/number_helper_i18n_test.rb @@ -72,11 +72,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 +99,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 +134,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) -- cgit v1.2.3 From 47b4d13c8d7602fc19229dd8cb70974e401b13b2 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 24 Jun 2012 20:02:52 -0300 Subject: Ensure I18n format values always have precedence over defaults Always merge I18n format values, namespaced or not, over the default ones, to ensure I18n format defaults will have precedence over our namespaced values. Precedence should happen like this: default :format default :namespace :format i18n :format i18n :namespace :format Because we cannot allow our namespaced default to override a I18n :format config - ie precision in I18n :format should always have higher precedence than our default precision for a particular :namespace. Also simplify default format options logic. --- activesupport/test/number_helper_i18n_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/test/number_helper_i18n_test.rb') diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index 4d0d5e8631..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' } } -- cgit v1.2.3