Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupling ActiveSupport from ActionView #6526

Merged
merged 1 commit into from May 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions activesupport/lib/active_support/testing/performance.rb
Expand Up @@ -3,7 +3,8 @@
require 'active_support/concern' require 'active_support/concern'
require 'active_support/core_ext/class/delegating_attributes' require 'active_support/core_ext/class/delegating_attributes'
require 'active_support/core_ext/string/inflections' 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 ActiveSupport
module Testing module Testing
Expand Down Expand Up @@ -195,8 +196,7 @@ def self.[](name)
end end


class Base class Base
include ActionView::Helpers::NumberHelper include ActiveSupport::NumberHelper
include ActionView::Helpers::OutputSafetyHelper


attr_reader :total attr_reader :total


Expand Down Expand Up @@ -240,7 +240,7 @@ def format(measurement)


class Amount < Base class Amount < Base
def format(measurement) def format(measurement)
number_with_delimiter(measurement.floor) number_to_delimited(measurement.floor)
end end
end end


Expand Down
40 changes: 40 additions & 0 deletions 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