From 532627452d0e581eb263499ccf84cf92f27de4d8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 5 Jul 2006 01:04:32 +0000 Subject: Added special case for "1 Byte" in NumberHelper#number_to_human_size (closes #5593) [murpyh@rubychan.de] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4537 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/number_helper.rb | 2 +- actionpack/test/template/number_helper_test.rb | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 8ae50f09be..47616301a0 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added special case for "1 Byte" in NumberHelper#number_to_human_size #5593 [murpyh@rubychan.de] + * Fixed proper form-encoded parameter parsing for requests with "Content-Type: application/x-www-form-urlencoded; charset=utf-8" (note the presence of a charset directive) [DHH] * Add route_name_path method to generate only the path for a named routes. For example, map.person will add person_path. [Nicholas Seckar] diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 9098dd8c33..cb312320ef 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -3,7 +3,6 @@ module ActionView # Provides methods for converting a number into a formatted string that currently represents # one of the following forms: phone number, percentage, money, or precision level. module NumberHelper - # Formats a +number+ into a US phone number string. The +options+ can be a hash used to customize the format of the output. # The area code can be surrounded by parentheses by setting +:area_code+ to true; default is false # The delimiter can be set using +:delimiter+; default is "-" @@ -86,6 +85,7 @@ module ActionView # human_size(1234567890) => 1.1 GB def number_to_human_size(size) case + when size == 1 : '1 Byte' when size < 1.kilobyte: '%d Bytes' % size when size < 1.megabyte: '%.1f KB' % (size / 1.0.kilobyte) when size < 1.gigabyte: '%.1f MB' % (size / 1.0.megabyte) diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index d77156af40..fd418d1e06 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -35,6 +35,7 @@ class NumberHelperTest < Test::Unit::TestCase def test_number_to_human_size assert_equal '0 Bytes', human_size(0) + assert_equal '1 Byte', human_size(1) assert_equal '3 Bytes', human_size(3.14159265) assert_equal '123 Bytes', human_size(123.0) assert_equal '123 Bytes', human_size(123) -- cgit v1.2.3