diff options
Diffstat (limited to 'activesupport')
7 files changed, 55 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/core_ext/numeric/conversions.rb b/activesupport/lib/active_support/core_ext/numeric/conversions.rb index 2666387623..2bbfa78639 100644 --- a/activesupport/lib/active_support/core_ext/numeric/conversions.rb +++ b/activesupport/lib/active_support/core_ext/numeric/conversions.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/big_decimal/conversions' require 'active_support/number_helper' class Numeric - + # Provides options for converting numbers into formatted strings. # Options are provided for phone numbers, currency, percentage, # precision, positional notation, file size and pretty printing. @@ -97,7 +97,7 @@ class Numeric # 1234567.to_s(:human, :precision => 1, # :separator => ',', # :significant => false) # => "1,2 Million" - def to_formatted_s(format = :default, options = {}) + def to_formatted_s(format = :default, options = {}) case format when :phone return ActiveSupport::NumberHelper.number_to_phone(self, options) @@ -117,19 +117,19 @@ class Numeric self.to_default_s end end - + [Float, Fixnum, Bignum, BigDecimal].each do |klass| klass.send(:alias_method, :to_default_s, :to_s) - + klass.send(:define_method, :to_s) do |*args| if args[0].is_a?(Symbol) format = args[0] options = args[1] || {} - + self.to_formatted_s(format, options) else to_default_s(*args) end end end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 5c32a2453d..8fa8157d65 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -1,5 +1,3 @@ -require 'active_support/multibyte' - class String # If you pass a single Fixnum, returns a substring of one character at that # position. The first character of the string is at position 0, the next at diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index 70f2dcb562..8644529806 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/string/multibyte' - class String # Returns the string, first removing all whitespace on both ends of # the string, and then changing remaining consecutive whitespace diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 4fe925f7f4..87b1d76026 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -76,7 +76,7 @@ module ActiveSupport #:nodoc: # # 'Café périferôl'.mb_chars.split(/é/).map { |part| part.upcase.to_s } # => ["CAF", " P", "RIFERÔL"] def split(*args) - @wrapped_string.split(*args).map { |i| i.mb_chars } + @wrapped_string.split(*args).map { |i| self.class.new(i) } end # Works like like <tt>String#slice!</tt>, but returns an instance of Chars, or nil if the string was not diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 981ab0cb36..fc97782697 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -498,14 +498,13 @@ module ActiveSupport formatted_number = self.number_to_rounded(number, options) decimal_format.gsub(/%n/, formatted_number).gsub(/%u/, unit).strip end - - + def self.private_module_and_instance_method(method_name) private method_name private_class_method method_name end private_class_method :private_module_and_instance_method - + def format_translations(namespace, locale) defaults_translations(locale).merge(translations_for(namespace, locale)) end @@ -527,6 +526,6 @@ module ActiveSupport false end private_module_and_instance_method :valid_float? - + end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 2bea0f991a..517926c74d 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -3,7 +3,8 @@ require 'rails/version' require 'active_support/concern' require 'active_support/core_ext/class/delegating_attributes' require 'active_support/core_ext/string/inflections' -require 'action_view/helpers/number_helper' +require 'active_support/core_ext/module/delegation' +require 'active_support/number_helper' module ActiveSupport module Testing @@ -195,8 +196,7 @@ module ActiveSupport end class Base - include ActionView::Helpers::NumberHelper - include ActionView::Helpers::OutputSafetyHelper + include ActiveSupport::NumberHelper attr_reader :total @@ -240,7 +240,7 @@ module ActiveSupport class Amount < Base def format(measurement) - number_with_delimiter(measurement.floor) + number_to_delimited(measurement.floor) end end diff --git a/activesupport/test/testing/performance_test.rb b/activesupport/test/testing/performance_test.rb new file mode 100644 index 0000000000..74d7dae9e7 --- /dev/null +++ b/activesupport/test/testing/performance_test.rb @@ -0,0 +1,40 @@ +require 'abstract_unit' +require 'active_support/testing/performance' + + +module ActiveSupport + module Testing + class PerformanceTest < ActiveSupport::TestCase + def test_amount_format + amount_metric = ActiveSupport::Testing::Performance::Metrics[:amount].new + assert_equal "0", amount_metric.format(0) + assert_equal "1", amount_metric.format(1.23) + assert_equal "40,000,000", amount_metric.format(40000000) + end + + def test_time_format + time_metric = ActiveSupport::Testing::Performance::Metrics[:time].new + assert_equal "0 ms", time_metric.format(0) + assert_equal "40 ms", time_metric.format(0.04) + assert_equal "41 ms", time_metric.format(0.0415) + assert_equal "1.23 sec", time_metric.format(1.23) + assert_equal "40000.00 sec", time_metric.format(40000) + assert_equal "-5000 ms", time_metric.format(-5) + end + + def test_space_format + space_metric = ActiveSupport::Testing::Performance::Metrics[:digital_information_unit].new + assert_equal "0 Bytes", space_metric.format(0) + assert_equal "0 Bytes", space_metric.format(0.4) + assert_equal "1 Byte", space_metric.format(1.23) + assert_equal "123 Bytes", space_metric.format(123) + assert_equal "123 Bytes", space_metric.format(123.45) + assert_equal "12 KB", space_metric.format(12345) + assert_equal "1.2 MB", space_metric.format(1234567) + assert_equal "9.3 GB", space_metric.format(10**10) + assert_equal "91 TB", space_metric.format(10**14) + assert_equal "910000 TB", space_metric.format(10**18) + end + end + end +end
\ No newline at end of file |