aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test
Commit message (Collapse)AuthorAgeFilesLines
* ActionCable: don't allowlist keys passed to the Redis initializerBlake Stoddard2019-04-221-2/+2
| | | Support all Redis features without needing to maintain a list of valid options that must stay in sync with the upstream client library.
* Output junit format test reportFumiaki MATSUSHIMA2019-04-041-0/+2
|
* Simplify ActionCable.createWebSocketURL and realphabetize exports (#35810)rmacklin2019-04-021-2/+3
| | | | | | | | | | | * Remove unnecessary variable from ActionCable.createWebSocketURL * Improve ActionCable test by creating the Consumer before reassigning URL With this change, the test now actually verifies that the Consumer's url property changes dynamically (from testURL to `${testURL}foo`). * Fix alphabetization of ActionCable exports
* feat(js): Dynamic ActionCable URL (#35579)Ryan Castner2019-03-311-2/+5
| | | | | | | | | | | | | | | | | * Failing test case * feat: Dynamic Url Generation Change createWebSocketURL to be a closure that allows url to be evaluated at the time the webSocket is established * refactor: createWebSocketURL to Consumer, remove need for closure Move initial call to createWebSocketURL in createConsumer * docs: Add documentation for dynamic url and string args to createConsumer Co-Authored-By: rmacklin <rmacklin@users.noreply.github.com> [Ryan Castner, rmacklin]
* feat(js): Dynamic Actioncable WebSocket URLRyan Castner2019-03-071-0/+8
| | | | Allow createWebSocketURL fn to accept a function to generate the websocket URL rather than a string.
* Address uninitialized constant PostgresqlAdapterTest::ChannelPrefixTest ↵Yasuo Honda2019-02-151-0/+1
| | | | | | | | | | | | | | | (NameError) ``` $ bundle exec ruby -w -Itest test/subscription_adapter/postgresql_test.rb Traceback (most recent call last): 1: from test/subscription_adapter/postgresql_test.rb:8:in `<main>' test/subscription_adapter/postgresql_test.rb:10:in `<class:PostgresqlAdapterTest>': uninitialized constant PostgresqlAdapterTest::ChannelPrefixTest (NameError) ``` https://travis-ci.org/rails/rails/jobs/493530508 Follow up #35276
* feat: support channel_prefix in pg subscription adapterVladimir Dementyev2019-02-141-0/+1
|
* Allow passing custom config to ActionCable::Server::BaseVladimir Dementyev2019-02-121-9/+1
| | | | | That allows us to create a separate, isolated Action Cable server instance within the same app.
* Respect ENV variables when finding DBs etc for the test suiteMatthew Draper2019-02-061-2/+6
| | | | | If they're not set we'll still fall back to localhost, but this makes it possible to run the tests against a remote Postgres / Redis / whatever.
* Add Channel#broadcast_toVladimir Dementyev2019-01-221-1/+1
|
* Move `channel_name` to Channel.broadcasting_forVladimir Dementyev2019-01-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That would allow us to test broadcasting made with channel, e.g.: ```ruby class ChatRelayJob < ApplicationJob def perform_later(room, msg) ChatChannel.broadcast_to room, message: msg end end ``` To test this functionality we need to know the underlying stream name (to use `assert_broadcasts`), which relies on `channel_name`. We had to use the following code: ```ruby assert_broadcasts(ChatChannel.broadcasting_for([ChatChannel.channel_name, room]), 1) do ChatRelayJob.perform_now end ``` The problem with this approach is that we use _internal_ API (we shouldn't care about `channel_name` prefix in our code). With this commit we could re-write the test as following: ```ruby assert_broadcasts(ChatChannel.broadcasting_for(room), 1) do ChatRelayJob.perform_now end ```
* Merge pull request #34959 from alkesh26/action-cable-typo-fixesRafael França2019-01-182-2/+2
|\ | | | | Typo fixes in action cable.
| * typo fixes in action cablealkesh262019-01-172-2/+2
| |
* | Replace `window` references in ActionCable with `self`Richard Macklin2019-01-141-4/+4
|/ | | | | | | | | | | | | | Before this change, attempting to use ActionCable inside a web worker would result in an exception being thrown: ``` ReferenceError: window is not defined ``` By replacing the `window` reference with `self`, which is available in both a window context and a worker context, we can avoid this error. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Window/self
* Update Action Cable connection testing.Kasper Timm Hansen2019-01-141-13/+18
| | | | | | | | | | | | | | | * Don't reimplement assert_raises Also test what happens in case there's no explicit rejection. * Avoid OpenStruct. Remove space beneath private. * Simplify verification methods for code under test. * Match documentation with other Rails docs. Also remove mention of the custom path argument for now. Unsure how useful that really is.
* feature: add ActionCable::Connection::TestCaseVladimir Dementyev2019-01-021-0/+192
|
* Merge pull request #34740 from sponomarev/feature/assert_has_streamGeorge Claghorn2018-12-311-2/+28
|\ | | | | Add streams assert methods to ActionCable channel test case
| * Add streams assert methods to ActionCable channel test caseSergey Ponomarev2018-12-181-2/+28
| |
* | Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-212-97/+85
|/ | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Add Missing ActiveSupport::Rescuable to ActionCable::ChannelIlia Kasianenko2018-12-121-1/+17
| | | | [timthez, Ilia Kasianenko]
* Stop trying to reconnect on unauthorized cable connectionsMick Staugaard2018-12-053-4/+7
|
* Replace reference to WebSocket global with ActionCable.adapters.WebSocketRichard Macklin2018-12-012-0/+29
| | | | | | | | | | The WebSocket dependency of ActionCable.Connection was made configurable in 66901c1849efae74c8a58fe0cb36afd487c067cc However, the reference here in Connection#getState was not updated to use the configurable property. This change remedies that and adds a test to verify it. Additionally, it backfills a test to ensure that Connection#open uses the configurable property.
* Remove circular dependency warnings in ActionCable javascript and publish ↵rmacklin2018-12-013-18/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | source modules with fine-grained exports (#34370) * Replace several ActionCable.* references with finer-grained imports This reduces the number of circular dependencies among the module imports from 4: ``` (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection_monitor.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/consumer.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/subscriptions.js -> app/javascript/action_cable/index.js ``` to 2: ``` (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/connection_monitor.js -> app/javascript/action_cable/index.js ``` * Remove tests that only test javascript object property assignment These tests really only assert that you can assign a property to the ActionCable global object. That's true for pretty much any object in javascript (it would only be false if the object has been frozen, or has explicitly set some properties to be nonconfigurable). * Refactor ActionCable to provide individual named exports By providing individual named exports rather than a default export which is an object with all of those properties, we enable applications to only import the functions they need: any unused functions will be removed via tree shaking. Additionally, this restructuring removes the remaining circular dependencies by extracting the separate adapters and logger modules, so there are now no warnings when compiling the ActionCable bundle. Note: This produces two small breaking API changes: - The `ActionCable.WebSocket` getter and setter would be moved to `ActionCable.adapters.WebSocket`. If a user is currently configuring this, when upgrading they'd need to either add a delegated getter/setter themselves, or change it like this: ```diff - ActionCable.WebSocket = MyWebSocket + ActionCable.adapters.WebSocket = MyWebSocket ``` Applications which don't change the WebSocket adapter would not need any changes for this when upgrading. - Similarly, the `ActionCable.logger` getter and setter would be moved to `ActionCable.adapters.logger`. If a user is currently configuring this, when upgrading they'd need to either add a delegated getter/setter themselves, or change it like this: ```diff - ActionCable.logger = myLogger + ActionCable.adapters.logger = myLogger ``` Applications which don't change the logger would not need any changes for this when upgrading. These two aspects of the public API have to change because there's no way to export a property setter for `WebSocket` (or `logger`) such that this: ```js import ActionCable from "actioncable" ActionCable.WebSocket = MyWebSocket ``` would actually update `adapters.WebSocket`. (We can only offer that if we have two separate source files like if `index.js` uses `import * as ActionCable from "./action_cable" and then exports a wrapper which has delegated getters and setters for those properties.) This API change is very minor - it should be easy for applications to add the `adapters.` prefix in their assignments or to patch in delegated setters. And especially because most applications in the wild are not ever changing the default value of `ActionCable.WebSocket` or `ActionCable.logger` (because the default values are perfect), this API breakage is worth the tree-shaking benefits we gain. * Include source code in published actioncable npm package This allows actioncable users to ship smaller javascript bundles to visitors using modern browsers, as demonstrated in this repository: https://github.com/rmacklin/actioncable-es2015-build-example In that example, the bundle shrinks by 2.8K (25.2%) when you simply change the actioncable import to point to the untranspiled src. If you go a step further, like this: ``` diff --git a/app/scripts/main.js b/app/scripts/main.js index 17bc031..1a2b2e0 100644 --- a/app/scripts/main.js +++ b/app/scripts/main.js @@ -1,6 +1,6 @@ -import ActionCable from 'actioncable'; +import * as ActionCable from 'actioncable'; let cable = ActionCable.createConsumer('wss://cable.example.com'); cable.subscriptions.create('AppearanceChannel', { ``` then the bundle shrinks by 3.6K (31.7%)! In addition to allowing smaller bundles for those who ship untranspiled code to modern browsers, including the source code in the published package can be useful in other ways: 1. Users can import individual modules rather than the whole library 2. As a result of (1), users can also monkey patch parts of actioncable by importing the relevant module, modifying the exported object, and then importing the rest of actioncable (which would then use the patched object). Note: This is the same enhancement that we made to activestorage in c0368ad090b79c19300a4aa133bb188b2d9ab611 * Remove unused commonjs & resolve plugins from ActionCable rollup config These were added when we copied the rollup config from ActiveStorage, but ActionCable does not have any commonjs dependencies (it doesn't have any external dependencies at all), so these plugins are unnecessary here * Change ActionCable.startDebugging() -> ActionCable.logger.enabled=true and ActionCable.stopDebugging() -> ActionCable.logger.enabled=false This API is simpler and more clearly describes what it does * Change Travis configuration to run yarn install at the root for ActionCable builds This is necessary now that the repository is using Yarn Workspaces
* Convert ActionCable tests from CoffeeScript to ES2015 and replace Blade with ↵rmacklin2018-11-2615-4713/+232
| | | | | | | | | | | | | | | | | | | | | | | | Karma and Rollup (#34440) * Rename .coffee files in ActionCable test suite in prep for decaffeination * Decaffeinate ActionCable tests * Replace Blade with Karma and Rollup to run ActionCable JS tests - Add karma and qunit devDependencies - Add test script to ActionCable package - Use rollup to bundle ActionCable tests - Use karma as the ActionCable JS test runner * Replace vendored mock-socket with package devDependency in ActionCable * Move ActionCable yarn install to TravisCI before_install config * Clean up decaffeinated ActionCable tests to use consistent formatting
* Fix typosR.T. Lechow2018-10-011-1/+1
| | | | Fixes some typos.
* Add ActionCable::Channel::TestCaseVladimir Dementyev2018-09-261-0/+188
| | | | | | | | | | | 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 #27191
* Remove private defSakshi Jain2018-09-231-9/+10
|
* Fix test case to ensure default connection id is filledRyuta Kamizono2018-09-071-2/+2
| | | | Follow up of #33798.
* ActionCable: add id option to redis adapter configIlia Kasianenko2018-09-051-2/+10
|
* DRY in `assert_broadcasts`bogdanvlviv2018-08-231-0/+10
| | | | Test `assert_no_broadcasts` failure
* Simplify configuring of `ActionCable.server.config.logger` for actioncable testsbogdanvlviv2018-08-231-1/+1
| | | | See `git grep "= Logger.new(nil)"`
* Add Action Cable test case and test helperVladimir Dementyev2018-08-192-0/+110
|
* Add Action Cable test adapterVladimir Dementyev2018-08-191-0/+47
|
* Remove thirdparty FIXMEAlberto Almagro2018-07-251-2/+1
| | | | | | This FIXME belongs to a code example that was imported from the internet. As we aren't going to do anything about it, I prefer to remove it so it stops from appearing on searches.
* Enable `Layout/EmptyLinesAroundBlockBody` to reduce review cost in the futureRyuta Kamizono2018-07-121-1/+0
| | | | | | | We sometimes ask "✂️ extra blank lines" to a contributor in reviews like https://github.com/rails/rails/pull/33337#discussion_r201509738. It is preferable to deal automatically without depending on manpower.
* Remove redundant accessorsutilum2018-06-111-2/+0
| | | | introduced in a0ea528b61.
* Merge pull request #33102 from bogdanvlviv/refactor-actioncable-testsRafael França2018-06-0818-45/+12
|\ | | | | Refactor actioncable's tests
| * Include `ActiveSupport::Testing::MethodCallAssertions` to ↵bogdanvlviv2018-06-0813-36/+3
| | | | | | | | | | | | | | | | | | `ActionCable::TestCase` Remove all `include ActiveSupport::Testing::MethodCallAssertions` in actioncable's tests since we can do it only in `ActionCable::TestCase` in order to prevent code duplication. We use the same approach for other modules of Rails.
| * Inherit all actioncable's test classes from `ActionCable::TestCase`bogdanvlviv2018-06-089-9/+9
| | | | | | | | | | | | We have defined `ActionCable::TestCase` in `actioncable/test/test_helper.rb` that we can use in order to prevent code duplication and build common interface for actioncable's test.
* | Merge pull request #27577 from maclover7/jm-fix-27547Rafael Mendonça França2018-06-081-0/+23
|\ \ | |/ |/| | | Action Cable owns database connection, not Active Record
| * Action Cable owns database connection, not Active RecordJon Moss2017-03-251-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, the database connection used in Action Cable's PostgreSQL adapter was "owned" by `ActiveRecord::Base.connection_pool`. This meant that if, for example, `#clear_reloadable_connections!` was called on the pool, Active Record would "steal" the database connection from Action Cable, and would cause all sorts of issues. This became evident during file reloads; despite Action Cable trying its hardest to return its borrowed database connection to Active Record via `@pubsub.shutdown`, Active Record calls `#clear_reloadable_connections!` on the connection pool, and due to the order of callbacks, Active Record's callback was being executed first. This meant that if you tried to rerender a view after a file was reloaded, you would have to wait through Active Record's timeout and such. Now, Action Cable takes direct ownership of the database connection it uses. It removes the connection from the pool to avoid the situation described above. Action Cable also makes sure to call `#disconnect!` on the connection when appropriate, to match the previous behavior of Active Record. [ Jon Moss & Matthew Draper]
* | Remove mocha from ActionCable testsutilum2018-05-311-1/+0
| | | | | | | | Q.E.D.
* | Use Ruby instead of mochautilum2018-05-313-6/+19
| |
* | Use minitest/mock instead of mochautilum2018-05-318-45/+101
| |
* | Fix actionable test's assertionbogdanvlviv2018-05-281-1/+1
| | | | | | | | | | Pull Request #32727 changed "mocha expects" in favor of `MethodCallAssertions`. This commit fixes assertion that became less strict after the PR.
* | remove unnecessary mocking in ActionCable testsutilum2018-05-225-39/+24
| |
* | assert_called_withutilum2018-04-261-4/+5
| |
* | assert_calledutilum2018-04-268-38/+71
| |
* | assert_not_calledutilum2018-04-262-4/+12
| |
* | Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | | | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.