Add ActionCable::Channel::TestCase#33969
Merged
jeremy merged 1 commit intorails:masterfrom Sep 27, 2018
Merged
Conversation
jeremy
reviewed
Sep 24, 2018
Member
There was a problem hiding this comment.
Backticks around "tests YourChannel" to be clear that it's code to be added to the test case.
Member
There was a problem hiding this comment.
Let's use more precise language for these, e.g. Crazy → NonInferrable
Contributor
Author
There was a problem hiding this comment.
I stole this craziness from action_mailer tests 🙂
Fixed
Member
There was a problem hiding this comment.
Great test coverage and demonstration of the test case.
ActionCable::Channel::TestCase provides an ability to unit-test channel classes. There are several reasons to write unit/functional cable tests: - Access control (who has access to the channel? who can perform action and with which argument? - Frontend-less applications have no system tests at all–and we still need a way to test channels logic. See also rails#27191
2a8f92e to
16e821a
Compare
Contributor
Author
y-yagi
reviewed
Sep 27, 2018
| @subscription.singleton_class.include(ChannelStub) | ||
| @subscription.send(:initialize, connection, CHANNEL_IDENTIFIER, params.with_indifferent_access) | ||
| # Call subscribe_to_channel if it's public (Rails 5.0.1+) | ||
| @subscription.subscribe_to_channel if ActionCable.gem_version >= Gem::Version.new("5.0.1") |
Contributor
Author
There was a problem hiding this comment.
Oops! No, we don't need it in Rails 6.
Will send a follow-up.
Thanks for catching!
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up #33659.
ActionCable::Channel::TestCase provides an ability
to unit-test channel classes.
From #23211 (comment):
See previous discussion here #27191
Summary
Channels Testing
Channels tests are written as follows:
subscribemethod to simulate subscription creation.transmitted messages, subscribed streams, etc.
For example:
You can also perform actions:
You can set up your connection identifiers:
When broadcasting to an object: