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
Fix subscriptions not being unsubscribed. #14642
Conversation
@senny Please review. Came across it while working on actionpack. Thanks :) |
I just noticed the failing test, will fix soon |
@senny Fixed :) |
@tgxworld the docs mention:
Can we rename the instance variables to |
@tgxworld yea that's fine. Just went through the docs and saw that we usually call it |
@@ -53,8 +53,9 @@ def setup_subscriptions | |||
end | |||
|
|||
def teardown_subscriptions | |||
ActiveSupport::Notifications.unsubscribe("render_template.action_view") | |||
ActiveSupport::Notifications.unsubscribe("!render_template.action_view") | |||
[@layouts_subscriber, @partials_subscriber, @files_subscriber].each do |subscriber| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fact that one subscription was added but forgotten in the removal process is a smell. Let's go one step further and refactor this to:
@_subscribers = []
# ...
@_subscribers << ActiveSupport::Notifications.subscribe("A")
@_subscribers << ActiveSupport::Notifications.subscribe("B")
@_subscribers << ActiveSupport::Notifications.subscribe("C")
# loop over @_subscribers to remove them.
This should be easier to keep in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@senny Updated per your comments :) |
…ribing Fix subscriptions not being unsubscribed.
@tgxworld looking good 💛 |
See https://github.com/rails/rails/blob/master/activesupport/lib/active_support/notifications.rb