Skip to content

Commit 598f8bd

Browse files
committed
decoupling activesupport performance testing from actionview and adding tests
1 parent 3d4ede2 commit 598f8bd

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

activesupport/lib/active_support/testing/performance.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
require 'active_support/concern'
44
require 'active_support/core_ext/class/delegating_attributes'
55
require 'active_support/core_ext/string/inflections'
6-
require 'action_view/helpers/number_helper'
6+
require 'active_support/core_ext/module/delegation'
7+
require 'active_support/number_helper'
78

89
module ActiveSupport
910
module Testing
@@ -195,8 +196,7 @@ def self.[](name)
195196
end
196197

197198
class Base
198-
include ActionView::Helpers::NumberHelper
199-
include ActionView::Helpers::OutputSafetyHelper
199+
include ActiveSupport::NumberHelper
200200

201201
attr_reader :total
202202

@@ -240,7 +240,7 @@ def format(measurement)
240240

241241
class Amount < Base
242242
def format(measurement)
243-
number_with_delimiter(measurement.floor)
243+
number_to_delimited(measurement.floor)
244244
end
245245
end
246246

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'abstract_unit'
2+
require 'active_support/testing/performance'
3+
4+
5+
module ActiveSupport
6+
module Testing
7+
class PerformanceTest < ActiveSupport::TestCase
8+
def test_amount_format
9+
amount_metric = ActiveSupport::Testing::Performance::Metrics[:amount].new
10+
assert_equal "0", amount_metric.format(0)
11+
assert_equal "1", amount_metric.format(1.23)
12+
assert_equal "40,000,000", amount_metric.format(40000000)
13+
end
14+
15+
def test_time_format
16+
time_metric = ActiveSupport::Testing::Performance::Metrics[:time].new
17+
assert_equal "0 ms", time_metric.format(0)
18+
assert_equal "40 ms", time_metric.format(0.04)
19+
assert_equal "41 ms", time_metric.format(0.0415)
20+
assert_equal "1.23 sec", time_metric.format(1.23)
21+
assert_equal "40000.00 sec", time_metric.format(40000)
22+
assert_equal "-5000 ms", time_metric.format(-5)
23+
end
24+
25+
def test_space_format
26+
space_metric = ActiveSupport::Testing::Performance::Metrics[:digital_information_unit].new
27+
assert_equal "0 Bytes", space_metric.format(0)
28+
assert_equal "0 Bytes", space_metric.format(0.4)
29+
assert_equal "1 Byte", space_metric.format(1.23)
30+
assert_equal "123 Bytes", space_metric.format(123)
31+
assert_equal "123 Bytes", space_metric.format(123.45)
32+
assert_equal "12 KB", space_metric.format(12345)
33+
assert_equal "1.2 MB", space_metric.format(1234567)
34+
assert_equal "9.3 GB", space_metric.format(10**10)
35+
assert_equal "91 TB", space_metric.format(10**14)
36+
assert_equal "910000 TB", space_metric.format(10**18)
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)