Closes#40482
Prior to this commit it was possible to subscribe with
`ActionCable::Channel::Base` as the subscription class. While it doesn't
seem possible to exploit this in away way, it also doesn't seem like
something we need to allow.
This commit swaps [Module#>=][gte] with [Module#>][gt] to prevent
subscribing to a channel when `ActionCable::Channel::Base` is the
subscription class.
[gte]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E-3D
[gt]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E
Since #37850, `config_for` returns `nil` instead of an empty Hash when
a config file does not contain configuration for the specified
environment. Thus, the return value should be converted to a Hash
before calling `with_indifferent_access`.
Fixes#40548.
The `linguist-vendored` attribute excludes the specified file from the
project's language stats on GitHub. The `linguist-generated` attribute
does the same, and also suppresses that file in diffs on GitHub.
See https://github.com/github/linguist for more information.
Follow up to c07dff7227.
Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.
I've checked all those usage and replaced all safe ones.
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
and update ActionCable guide to describe exception handling usage
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes to be committed:
# modified: actioncable/CHANGELOG.md
# modified: actioncable/lib/action_cable/connection/base.rb
# modified: actioncable/lib/action_cable/connection/subscriptions.rb
# modified: actioncable/test/connection/subscriptions_test.rb
# modified: guides/source/action_cable_overview.md
#
* You can distinguish connection among others with specific `application_name`
```sql
SELECT application_name FROM pg_stat_activity;
/*
application_name
------------------------
psql
ActionCable-PID-42
(2 rows)
*/
```
* It's possible to customize connection identification with `id` option in `cable.yml`
`ActionCable-PID-#{$$}` is the default value
* Related tests refactoring
* `ActionCable::Server#config.cable` is no mutated anymore inside Redis subscription adapter
We have run into issues in the past where the actioncable compiled
javascript bundle got out of sync with the source code. For example, in
30a0c7e040 only the compiled bundle was
modified. This meant that anyone who ran `yarn build` in the actioncable
directory would then see a dirty git status indicating changes to the
compiled bundle, despite not having made any changes to the actioncable
javascript source code. We fixed that particular inconsistency in
a4c27588d5. However, the same problem
could reoccur.
To address this, I've added a new test to enforce that actioncable's
compiled javascript bundle is in sync with the source code. When the
compiled bundle is in sync with the source code, the test will pass:
$ bundle exec ruby -Itest test/javascript_package_test.rb
Run options: --seed 19308
# Running:
yarn run v1.12.3
$ yarn lint && bundle exec rake assets:codegen
$ eslint app/javascript
$ rollup --config rollup.config.js
app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
created app/assets/javascripts/action_cable.js in 762ms
✨ Done in 6.35s.
.
Finished in 7.130345s, 0.1402 runs/s, 0.1402 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
However, if the two are not in sync, the test will fail. For example, if
you were to apply the following patch (which only updates the source
code):
```
diff --git a/actioncable/app/javascript/action_cable/adapters.js b/actioncable/app/javascript/action_cable/adapters.js
index 4de8131438..d38d9a6a0b 100644
--- a/actioncable/app/javascript/action_cable/adapters.js
+++ b/actioncable/app/javascript/action_cable/adapters.js
@@ -1,4 +1,5 @@
export default {
+ foo: self.foo,
logger: self.console,
WebSocket: self.WebSocket
}
```
the test would then fail like this:
$ bundle exec ruby -Itest test/javascript_package_test.rb
Run options: --seed 26377
# Running:
yarn run v1.12.3
$ yarn lint && bundle exec rake assets:codegen
$ eslint app/javascript
$ rollup --config rollup.config.js
app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
created app/assets/javascripts/action_cable.js in 776ms
✨ Done in 5.55s.
F
Failure:
JavascriptPackageTest#test_compiled_code_is_in_sync_with_source_code [test/javascript_package_test.rb:16]:
--- expected
+++ actual
@@ -3,6 +3,7 @@
})(this, function(exports) {
\"use strict\";
var adapters = {
+ foo: self.foo,
logger: self.console,
WebSocket: self.WebSocket
};
rails test test/javascript_package_test.rb:9
Finished in 5.837403s, 0.1713 runs/s, 0.1713 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Thus, the actioncable test suite will now prevent "the compiled bundle
is out of sync" issues going forward.
Action Cable's JavaScript library can optionally be imported as an ES6 module via `import { … } from "@rails/actioncable/src"`, but that module is broken in most of the releases published on npm:
```
ERROR in ./node_modules/@rails/actioncable/src/connection.js
Module not found: Error: Can't resolve './internal' in './node_modules/@rails/actioncable/src'
@ ./node_modules/@rails/actioncable/src/connection.js
@ ./node_modules/@rails/actioncable/src/index.js
```
Because `internal.js` was gitignored, it would only be included if the publisher happened to have it generated locally. Committing it to version control ensures that won't happen, and gives us better visibility into changes over time.
References:
- https://github.com/rails/rails/pull/34370
- c0368ad090
* 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