Decoupling ActiveSupport from ActionView #5675

Closed
wants to merge 2 commits into
from
@@ -1,4 +1,15 @@
require 'active_support/testing/performance'
+require 'action_view/helpers/number_helper'
+
+ActiveSupport::Testing::Performance::Metrics::Amount.formatter = Proc.new() do |measurement|
+ include ActionView::Helpers::NumberHelper
+ number_with_delimiter(measurement.floor)
+end
+
+ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit.formatter = Proc.new() do |measurement|
+ include ActionView::Helpers::NumberHelper
+ number_to_human_size(measurement, :precision => 2)
+end
module ActionDispatch
# An integration test that runs a code profiler on your test methods.
@@ -3,7 +3,7 @@
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/class/attribute'
module ActiveSupport
module Testing
@@ -195,9 +195,8 @@ def self.[](name)
end
class Base
- include ActionView::Helpers::NumberHelper
-
attr_reader :total
+ class_attribute :formatter
def initialize
@total = 0
@@ -239,13 +238,21 @@ def format(measurement)
class Amount < Base
def format(measurement)
- number_with_delimiter(measurement.floor)
+ if self.class.formatter.present?
+ self.class.formatter.call(measurement.floor)
+ else
+ measurement.floor
+ end
end
end
class DigitalInformationUnit < Base
def format(measurement)
- number_to_human_size(measurement, :precision => 2)
+ if self.class.formatter.present?
+ self.class.formatter.call(measurement)
+ else
+ "#{measurement} Bytes"
+ end
end
end