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

Fix subscriptions not being unsubscribed. #14642

Merged
merged 1 commit into from
Apr 15, 2014
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
12 changes: 7 additions & 5 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def setup_subscriptions
@_templates = Hash.new(0)
@_layouts = Hash.new(0)
@_files = Hash.new(0)
@_subscribers = []

ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload|
@_subscribers << ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload|
path = payload[:layout]
if path
@_layouts[path] += 1
Expand All @@ -28,7 +29,7 @@ def setup_subscriptions
end
end

ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
@_subscribers << ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
path = payload[:virtual_path]
next unless path
partial = path =~ /^.*\/_[^\/]*$/
Expand All @@ -41,7 +42,7 @@ def setup_subscriptions
@_templates[path] += 1
end

ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
@_subscribers << ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
next if payload[:virtual_path] # files don't have virtual path

path = payload[:identifier]
Expand All @@ -53,8 +54,9 @@ def setup_subscriptions
end

def teardown_subscriptions
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
@_subscribers.each do |subscriber|
ActiveSupport::Notifications.unsubscribe(subscriber)
end
end

def process(*args)
Expand Down
3 changes: 2 additions & 1 deletion actionview/lib/action_view/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def view
:@options,
:@test_passed,
:@view,
:@view_context_class
:@view_context_class,
:@_subscribers
]

def _user_defined_ivars
Expand Down