Mark bang instrumentations as something that you shuold not be listening to.
This commit is contained in:
parent
21dcbb17de
commit
a6dc227167
@ -13,7 +13,7 @@ module TemplateAssertions
|
||||
def setup_subscriptions
|
||||
@partials = Hash.new(0)
|
||||
@templates = Hash.new(0)
|
||||
ActiveSupport::Notifications.subscribe("action_view.slow_render_template") do |name, start, finish, id, payload|
|
||||
ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload|
|
||||
path = payload[:virtual_path]
|
||||
next unless path
|
||||
partial = path =~ /^.*\/_[^\/]*$/
|
||||
@ -28,7 +28,7 @@ def setup_subscriptions
|
||||
end
|
||||
|
||||
def teardown_subscriptions
|
||||
ActiveSupport::Notifications.unsubscribe("action_view.slow_render_template")
|
||||
ActiveSupport::Notifications.unsubscribe("action_view.render_template!")
|
||||
end
|
||||
|
||||
# Asserts that the request was rendered with the appropriate template file or partials
|
||||
|
@ -23,7 +23,6 @@ def initialize(source, identifier, handler, details)
|
||||
@identifier = identifier
|
||||
@handler = handler
|
||||
|
||||
@partial = details[:partial]
|
||||
@virtual_path = details[:virtual_path]
|
||||
@method_names = {}
|
||||
|
||||
@ -36,9 +35,9 @@ def initialize(source, identifier, handler, details)
|
||||
end
|
||||
|
||||
def render(view, locals, &block)
|
||||
# TODO: Revisit this name
|
||||
# This is only slow if it's being listened to. Do not instrument this in production.
|
||||
ActiveSupport::Notifications.instrument("action_view.slow_render_template", :virtual_path => @virtual_path) do
|
||||
# Notice that we use a bang in this instrumentation because you don't want to
|
||||
# consume this in production. This is only slow if it's being listened to.
|
||||
ActiveSupport::Notifications.instrument("action_view.render_template!", :virtual_path => @virtual_path) do
|
||||
method_name = compile(locals, view)
|
||||
view.send(method_name, locals, &block)
|
||||
end
|
||||
@ -63,10 +62,6 @@ def counter_name
|
||||
@counter_name ||= "#{variable_name}_counter".to_sym
|
||||
end
|
||||
|
||||
def partial?
|
||||
@partial
|
||||
end
|
||||
|
||||
def inspect
|
||||
if defined?(Rails.root)
|
||||
identifier.sub("#{Rails.root}/", '')
|
||||
|
@ -44,7 +44,7 @@ def initialize(queue, pattern)
|
||||
when Regexp, NilClass
|
||||
pattern
|
||||
else
|
||||
/^#{Regexp.escape(pattern.to_s)}/
|
||||
/^#{Regexp.escape(pattern.to_s)}$/
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ def test_publishing_after_a_new_subscribe_works
|
||||
assert_equal [[:foo]] * 4, @events
|
||||
end
|
||||
|
||||
def test_log_subscriber_with_pattern
|
||||
def test_log_subscriber_with_string
|
||||
events = []
|
||||
@notifier.subscribe('1') { |*args| events << args }
|
||||
|
||||
@ -74,10 +74,10 @@ def test_log_subscriber_with_pattern
|
||||
@notifier.publish 'a.1'
|
||||
@notifier.wait
|
||||
|
||||
assert_equal [['1'], ['1.a']], events
|
||||
assert_equal [['1']], events
|
||||
end
|
||||
|
||||
def test_log_subscriber_with_pattern_as_regexp
|
||||
def test_log_subscriber_with_pattern
|
||||
events = []
|
||||
@notifier.subscribe(/\d/) { |*args| events << args }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user