Commit Graph

769 Commits

Author SHA1 Message Date
Jean Boussier
71c24aa0bc Refactor Action Cable's Redis adapter to isolate the layer breach 2022-08-22 09:01:27 +02:00
Jean Boussier
7559957ba2 Require redis 4+ in Action Cable
RedisCacheStore already does, no point keeping compatiblity
with 3.x.

Redis 4+ always responds to `_client` so we can simplify the code.
2022-08-22 09:01:27 +02:00
Jean Boussier
f2ab66da73 Stop testing hiredis
The driver being used is an implementation detail of `redis-rb`.
If somehow something break on one driver but not the other, it should
be reported to redis-rb and fixed there.

Also `redis-rb` `5.0` has a totally new client and hiredis binding
so all this code no longer works with redis-rb 5.0.
2022-08-22 09:01:27 +02:00
Erol Fornoles
69c8b6b3d1
Correct the description for reject_unauthorized_connection 2022-08-08 09:23:01 +08:00
Alex Ghiculescu
1ee984dfe4 Anchor the Action Cable server's route
Fixes https://github.com/rails/rails/issues/45489

- Adds `anchor: true` to the Action Cable server mount, so that it only strictly matches `/cable` rather than anything that starts with that.
- Uses `reverse_merge` instead of `merge` in `Mapper#mount`, so that you can override these options if you need to.
2022-06-29 13:26:49 -05:00
Svyatoslav Kryukov
080f9b4c98
Document Action Cable Connection Callbacks 2022-06-28 15:36:52 +03:00
Svyatoslav Kryukov
b66df44f1f
Document Action Cable Channel Callbacks 2022-06-27 10:34:48 +03:00
Gannon McGibbon
19875bedd7 Improve channel generator usage docs
- Makes heading styles consistent with other generators
- Adds backticks to code snippets
- Adds more examples
2022-06-21 00:30:37 -05:00
Dominik Malis
cef3342e40
Connections Map changed to Each in ping task
No need to make new array containing all connections because returned value of map is not used
2022-06-16 13:20:14 +02:00
Xavier Noria
3bcd48f6d8 Require Zeitwerk 2.6 2022-06-13 23:43:42 +02:00
Jean Boussier
115be62709 Wrap rails runner in executor
The main reason is to automatically report uncaught exceptions
since `rails runner` is often used for cron tasks and such.
2022-06-10 14:16:49 +02:00
Gannon McGibbon
3dad2919d5 Rename behaviour to behavior in documentation 2022-05-26 17:14:18 -04:00
Jeremy Daer
df88a42e5f Merge branch 'main' into feat/ac-remote-disconnect-notice
* main: (21 commits)
  feat: action cable connection callbacks
  fix: action cable stream_test errors
  Adds test coverage for #attach method behaviour in activestorage
  Address QueryCacheTest#test_query_cache_does_not_allow_sql_key_mutation failure
  Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services
  Fixes development Action Mailbox new mail form
  Squash commits
  Include the unexpected class in InvalidParameterKey message
  Support unbounded time ranges for PostgreSQL
  Fix CHANGELOG alignment [ci-skip]
  Add ability to ignore tables by regexp for SQL schema dumps
  Improve `rails s` error message when no server could be found.
  Fix MySQL warning when creating Active Record's test databases
  Add `--js` and --skip-javascript` options to `rails new`
  Fix parsing operator classes for index columns in PostgreSQL
  Fix rails test command to handle leading dot slash
  Document that url_for can take classes
  Don't change the encoding of frozen parameters
  Update working_with_javascript_in_rails.md
  Avoid query from calculations on contradictory relation
  ...
2022-05-16 12:40:31 -07:00
Vladimir Dementyev
5d6c1f64ea feat: action cable connection callbacks 2022-05-16 12:24:38 -07:00
Vladimir Dementyev
c5423e9a9c fix: action cable stream_test errors 2022-05-16 12:22:09 -07:00
Vladimir Dementyev
2d0f9c5844 Send disconnect message during remote disconnect
Send {type: :disconnect} message to a client before closing the connection when initiated by server.remote_connections.where(...).disconnect
2022-05-11 13:59:23 -04:00
Ghouse Mohamed
6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Xavier Noria
645239817d Refactor Zeitwerk setup in Action Cable
I am trying to find a sweet spot here.

Personally, not quite satisfied by having lib/action_cable/zeitwerk.rb. At the
same time, trying to avoid too taking much space in lib/action_cable.rb.

This patch also moves

    require_relative "action_cable/version"

within ActionCable. Why? In a project, I like that the entrypoint defines the
namespace. That is the main file for that namespace.

Then, files below have it already created, and reopen it.

I just find this deliberate order of execution to be natural, hierarchical,
matching the project structure.
2022-03-06 19:52:36 +01:00
Xavier Noria
61bbcb71d5 Add missing magic comment (linting) 2022-03-05 14:25:52 +01:00
Xavier Noria
a0e75d76ab Setup Zeitwerk in a dedicated file 2022-03-05 14:05:34 +01:00
Xavier Noria
a3f4ae9a2d Remove require "thread" from Action Cable
Not needed since Ruby 2.1.
2022-03-05 08:56:09 +01:00
Xavier Noria
b7ae3cba6d Load with Zeitwerk 2022-03-05 08:19:49 +01:00
Jonathan Hefner
a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner
e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
0d3effc97e Replace "overwrite" with "override" [ci-skip]
"Overwrite" means "destructively replace", and is more suitable when,
for example, talking about writing data to a location.

"Override" means "supersede", and is more suitable when, for example,
talking about redifining methods in a subclass.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Jorge Manrubia
ed8e767218
Only close websockets when connection is open (#44304)
This addresses a problem where Safari's websockets gets permanently broken
when closing them in a "connecting" state.

See https://github.com/rails/rails/issues/43835#issuecomment-1002288478
2022-02-02 15:50:34 +01:00
jlestavel
2197814074
Allow app to opt out of precompiling activestorage js assets (#43967) 2022-01-18 18:19:30 +01:00
Ryuta Kamizono
65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
Rafael Mendonça França
83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Rafael Mendonça França
8160e25de0
Merge pull request #43591 from SkipKayhil/fix-actioncable-js-module
fix actioncable module field in package.json
2021-12-03 15:32:32 -05:00
Rafael Mendonça França
1fde031e89 Fix gemspec 2021-11-15 21:06:21 +00:00
Rafael Mendonça França
9195b7fd0a
Require MFA to release rails 2021-11-15 20:37:42 +00:00
Tanaka
6fee8be7fd
Add actioncable assets to gemspec.
actioncable.js and actioncable.esm.js is not included to gem package. It prevented us from using the action cable when using importmaps.

This adds the missing asset files to gem package.
2021-11-12 05:56:16 +09:00
Hartley McGuire
9dcd7099fa fix actioncable module field in package.json
The current module field points to a file that isn't included in the
files field of actioncable's package.json. This leads to errors when
trying to use actioncable in bundlers that use esm modules natively
(like Vite)
2021-11-03 21:24:20 -04:00
George Claghorn
426c69fd39 Action Cable: use non-deprecated entrypoint for JS package 2021-10-27 21:34:23 -04:00
Dan Spinosa
6d7c12274e
Client ensures subscribe command is confirmed. (#41581)
A SubscriptionGuarantor maintains a set of pending subscriptions,
resending the subscribe command unless and until the subscription
is confirmed or rejected by the server or cancelled client-side.

A race condition in the ActionCable server - where an unsubscribe
is sent, followed rapidly by a subscribe, but handled in the reverse
order - necessitates this enhancement.  Indeed, the subscriptions created
and torn down by Turbo Streams amplifies the existence of this race
condition.
2021-09-26 10:06:27 -07:00
Rafael Mendonça França
386ab893f6
Use regular memoization
`connection_gid` always return something so we don't need to use
`defined?`.
2021-09-23 19:23:27 -04:00
Rafael França
ddaf3b2cb3
Merge pull request #42574 from leastbad/connection_identifier
add connection_identifier to ConnectionStub
2021-09-23 19:19:07 -04:00
Rafael Mendonça França
d177551c30
Preparing for 7.0.0.alpha2 release 2021-09-15 18:22:51 -04:00
Rafael Mendonça França
9b7be48212
Preparing for 7.0.0.alpha1 release 2021-09-15 17:55:08 -04:00
luizkowalski
868a63c695 Update guide and actioncable tests to use appropriate concurrent-ruby class 2021-09-15 17:50:49 +02:00
Xavier Noria
89801b2a43 Depend on ruby/debug, replacing Byebug
ruby/debug is a new debugger that is going to ship with CRuby.

It makes sense for Rails to switch to this one because that is
where the language is heading, and because Byebug is not fully
compatible with Zeitwerk. See

    https://github.com/deivid-rodriguez/byebug/issues/564

While ruby/debug has not been heavily tested with Zeitwerk,
casual usage seems to suggest it works without issues, including
explicit namespaces, which is where Byebug and Zeitwerk conflict.

Byebug is terrific, thanks a lot for all these years. ❤️
2021-09-08 17:35:41 +02:00
Jean Boussier
c91c266872 Enable Style/ExplicitBlockArgument cop
This reduce the stack size which is beneficial for
exceptions performance.

See: https://gist.github.com/byroot/cb3bcadcc3701c2518d002fb8d3a4e7a

However the cop is unsafe because it might change the block arity,
so it can run into some false positives.
2021-09-05 17:06:19 +02:00
Jose Galisteo
86ee45477c Fix rubocop offense 2021-09-04 20:48:35 +02:00
David Heinemeier Hansson
abc042cf9e Fix trailing whitespace 2021-09-04 19:47:32 +02:00
David Heinemeier Hansson
82e4432058
Javascript generator option with choices (#43160)
* Switch to a single controller option for choosing JavaScript approach

* Remove remnants of webpacker specific work within Rails

* No longer used

* Missing space

* Raise if unknown option is passed

* Style

* Use latest versions

* Make channels setup generic to all node setups

* Make Action Text installer work with any node package manager

* Explaining variables are not useless

* Rubocop pleasing

* Don't rely on Rails.root

Tests don't like it!

* Rubocopping

* Assume importmap

* No longer relevant

* Another cop

* Style

* Correct installation notice

* Add dependencies for action cable when adding a channel

* Fix paths to be relative to generator

* Just go straight to yarn, forget about binstub

* Fix tests

* Fixup installer, only yarn once

* Test generically with run

* Style

* Fix reference and reversibility

* Style

* Fix test

* Test pinning dependencies

* Remove extra space

* Add more tests

* Use latest dependencies

* Relegated this to controllers

* Refactor ChannelGenerator + more tests

Use a uniform level of abstraction
2021-09-04 11:53:57 +02:00
David Heinemeier Hansson
af7428c4ac
Replace webpack with importmapped Hotwire as default js (#42999)
* Turbolinks is being replaced with Hotwire

* Make --webpack opt-in

* Don't use specific webpacker installers any more in preparation for next Webpacker

* Update railties/lib/rails/app_updater.rb

Co-authored-by: Alex Ghiculescu <alex@tanda.co>

* Trailing whitespace

* Convert to Turbo data attribute for tracking

* Default is no webpack, no hotwire

* Swap out turbolinks references for hotwire

* Drop explicit return

* Only generate package.json if using webpack

* Only create package.json in webpack mode

* Only create app/javascript in webpack mode

* Generate correct style/js links based on js mode

* Fix tests from changed output format

Not sure why these are showing up in this PR, though.

* Rubocopping

* Stick with webpack for the test app for now

* Adjust tests

* Replace minitest-reporters with minitest-ci (#43016)

minitest-reporters is used to create junit xml reports on CI.

But when it loads before rails minitest plugin makes
`Rails::TestUnitReporter` not being added as a reporter.

minitest-ci is now only loaded at ci and does not interferes with
rails minitest plugins. And keeps junit reports workings

* Too heavy handed to actually run bundle

Just like we don't auto-migrate

* Pin js frameworks in importmap

Instead of having importmap preconfigure it.

* Match updated app/javascript path

* No need for the explaining comment

* Fixes test cases for replace webpack with importmapped Hotwire as default js (#42999)

* Fix rubocop issues

* Fix more railities test cases

* Fix plugin generator railties shared test cases

* Fix Action Text install generator asset pipeline spec

* They're modules, not files

* Let dev use the latest release as well

So we don't have to replace unexisting dev releases with latest release

* Make Webpack responsible for generating all the JS files it needs

Webpacker 6 has already moved from app/javascript to app/packs.

* Don't add rails/ujs by default any longer

All the ajax/form functionality has been superseded by Turbo. The rest lives in a weird inbetween land we need to address through other means.

* Use new importmap location

* Switch to using turbo-rails and stimulus-rails directly

The hotwire-rails gem does not offer enough value for its indirection

* Use latest Webpacker

* Prevent version resolution requests from getting swallowed

* Use ESM syntax for imports

* Move management of yarn, package.json, etc to Webpacker 6

* Update for Webpacker 6

* Move bin/setup addition to Webpacker as well

* Remove dead tests

* Bump to Webpacker 6.0.0.rc.2

* No longer relevant given the new default is no webpacker

* Rely on Webpacker 6

* No longer relevant

* No longer relevant

* Make cable channel generator work for both webpacker and importmap setups

* Fix tests

* For tests testing importmap way

* Use Webpacker 6 dummy

* RuboCopping

* One more bump to fix webpack-dev-server

* Another bump. Hopefully the last one!

* Also enough to not want turbo tracking on

* Fix tests

* Latest

* Fix tests

* Fix more tests

* Fix tests

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2021-08-26 10:39:36 +02:00
David Heinemeier Hansson
4a23cb3415
Output Action Cable JS without transpiling and as ESM (#42856)
* Output Action Cable JS without transpiling and as ESM

* Retain umd version under the old name, generate ESM version + duplicate under new name

* Precompile JavaScripts for direct asset pipeline use

* We've dropped support for IE11

* Include deprecation notice for the old file reference

Thanks @rafaelfranca 👍

* Allow app to opt out of precompiling actioncable js assets

cc @rafaelfranca

* Add changelog entries
2021-08-06 14:00:43 +02:00
Rafael Mendonça França
90868dab14
Allow testing action cable with a different redis port 2021-08-04 18:17:47 -04:00
Rafael Mendonça França
18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
Ryuta Kamizono
e50b0e3ab3 Fixup CHANGELOGs [ci skip] 2021-07-21 10:08:08 +09:00
Jean Boussier
cce46f8db1
Merge pull request #42459 from ghiculescu/patch-2
Log a warning when assertions are incorrectly nested and errors are raised
2021-07-12 19:05:39 +02:00
Alex Ghiculescu
4b42beb3b8 Log a warning when assertions are incorrectly nested and errors are raised
Follow up to https://github.com/rails/rails/pull/37313

- Adds regression tests
- Logs a warning in cases where assertions are nested in a way that's likely to be confusing
2021-07-12 10:37:43 -05:00
J Smith
460735e03f Truncate more ActionCable broadcast messages to 300 chars
Truncation to ActionCable logging was added way back in 2016, but here's
another location where the logging messages can get out of hand.
2021-07-07 14:52:29 -03:00
Dirkjan Bussink
0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
leastbad
b18e6ba6bd add connection_identifier assertion to ConnectionStub test 2021-06-24 07:53:02 -04:00
leastbad
5d61773812 ConnectionStub identifiers are methods, not ivars 2021-06-24 04:48:52 -04:00
leastbad
d573fb11d7 add connection_identifier to ConnectionStub 2021-06-23 06:19:07 -04:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
John Bachir
267e1d25dc Add name to ActionCable threads
To assist in various debugging scenarios, such as [tracking which types of threads are using db connections][0]

Thread names will now be "ActionCable-worker-N" instead of "worker-N".

This is safe for all ruby versions. In versions which do not have thread names, [concurrent-ruby does not attempt to add the name][1]

In the environment I happened to be testing in:

```ruby
e = Concurrent::ThreadPoolExecutor.new(name: 'ActionCable', min_threads: 2, max_threads: 2)
e.post{sleep 100}
e.post{sleep 100}
Thread.list.map(&:name)
```

[0] https://github.com/puma/puma/issues/1512#issuecomment-756760388
[1] https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb#L312
2021-04-14 11:24:37 -07:00
Vladislav
d264276288 RemoteConnection#disconnect: fix ArgumentError on ruby 3.0 2021-04-02 12:24:54 -04:00
Carlos Antonio da Silva
ca06a9ff41 Refactor to use model instead of record as argument in Action Cable
We refer to `model` elsewhere in Action Cable's  implementation, so use
the same in `stream_or_reject_for` as well to keep the consistency.

Simplify the docs for the method to remove the usage "intention"
(that's not up to us) and mention it rejects the "subscription", not
the "connection".
2021-02-25 11:21:19 -03:00
Jonathan Hefner
167f5c8065 Fix inline code markup [ci-skip]
RDoc Markup does not support backticks the way Markdown does to mark up
inline code.  Additionally, `<tt>` must be used to mark up inline code
that includes spaces or certain punctuation characters (e.g. quotes).
2021-02-14 11:20:35 -06:00
Rafael Mendonça França
1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Rafael Mendonça França
6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +00:00
Jonathan Hefner
cc9a9e8503 Prevent thundering herd of Action Cable clients
This commit makes a few changes to the Action Cable client to prevent a
"thundering herd" of client reconnects after server connectivity loss:

* The client will wait a random amount between 1x and 3x of the stale
  threshold after the server's last ping before making the first
  reconnection attempt.
* Subsequent reconnection attempts now use exponential backoff instead
  of logarithmic backoff.  To allow the delay between reconnection
  attempts to increase slowly at first, the default exponentiation base
  is < 2.
* Random jitter is applied to each delay between reconnection attempts.

Co-authored-by: John Williams <john@veloshots.com>
2021-02-02 10:43:05 -06:00
alea12
4858c9fa2d Update ActionCable docs [ci skip] 2021-01-08 19:08:55 +09:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Daniel Colson
d092c133c7
Do not allow subscribing to Base channel
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
2020-11-24 22:30:03 -05:00
Jonathan Hefner
949e4587d5 Allow missing Action Cable config
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.
2020-11-06 11:45:51 -06:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Jonathan Hefner
fd3fd618f4 Add gitattributes for vendored and generated files [ci-skip]
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.
2020-10-04 16:44:37 -05:00
Rafael França
1eade80dd6
Merge pull request #39123 from tannakartikey/actioncable_logger_docs
Added docs for client-side logger
2020-07-06 14:28:43 -04:00
Kartikey Tanna
e0ec24e3c0 Added an example of logging 2020-07-06 23:32:55 +05:30
Ryuta Kamizono
528b62e386 Address to false negative for Performance/DeletePrefix,DeleteSuffix
Follow up to c07dff72278fb7f2a3c4c71212a0773a2b25c790.

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.
2020-06-14 13:04:47 +09:00
Tim Craft
7f41ab2b0e Use indifferent access for config hash in actioncable postgresql test 2020-06-10 13:52:43 +01:00
Étienne Barrié
f1cef4c9ca Remove invalid autoloads in top-level Rails modules 2020-06-08 17:21:26 -04:00
Petrik
2b09948637 Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
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.
2020-06-03 08:51:47 +02:00
Kartikey Tanna
c25b77fb6b Added docs for client-side logger 2020-05-03 11:52:06 +05:30
Ryuta Kamizono
592358e182 Update pg gem required version to 1.1
This is required for #39063 to use `PG::TextDecoder::Numeric`.

Ref https://github.com/ged/ruby-pg/pull/25.

The pg gem 1.1.0 was released at August 24, 2018, so I think it is good
timing to bump the required version for improving and cleaning up the
code base.

https://rubygems.org/gems/pg/versions
2020-04-27 16:27:40 +09:00
Liroy Leshed
801716395c
Convert CoffeeScript to ES6 syntax 2020-04-17 14:41:40 +03:00
Abhay Nikam
bdfffd1355 Update the Rails mailing list URLs to new discuss discourse URL [ci skip] 2020-04-02 22:00:28 +05:30
justin talbott
d2571e560c add rescue_with support to ActionCable::Connection::Base
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
#
2020-03-20 14:49:38 -07:00
Atul Bhosale
ec69083cf3
Add method ActionCable::Channel#stream_or_reject_for to stream if record is present, otherwise reject the connection (#38375) 2020-03-07 10:09:08 -08:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Zhang Kang
96b74fe433 Introduce ActionCable::Channel#stop_stream_from/for to unsubscribe specific streams (#37171)
* Like `ActionCable::Channel#stop_all_streams`, but for specific streams
2020-01-17 13:39:06 -08:00
alkeshghorpade
aed448cc50 Typo fix of visbility. 2020-01-10 18:59:48 +05:30
Abhay Nikam
d8beb77252 Bump license years from 2019 to 2020 [ci skip] 2020-01-01 15:10:31 +05:30
Carlos Antonio da Silva
3c28e79b61 Fix indent in Action Cable changelog entry [ci skip] 2019-12-31 10:18:55 -03:00
Sergey Ponomarev
723375147b Add ActionCable subscription connection identificator to PostgreSQL adapter
* 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
2019-12-31 13:23:01 +03:00
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
Eugene Kenny
ee525ff663 Load framework test files in deterministic order
`Dir.glob` doesn't guarantee the order of its results:

https://ruby-doc.org/core-2.6.5/Dir.html#method-c-glob

> Case sensitivity depends on your system (File::FNM_CASEFOLD is
> ignored), as does the order in which the results are returned.

Minitest stores a list of all test cases in the order that they were
defined; it shuffles them before they're run, but doesn't sort them:

https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L1048
https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L156

This means that the order in which framework tests run is platform
dependent, and running a test command that failed in CI locally won't
necessarily reproduce the error, even when the same seed is provided.

`Rake::FileList` resolves glob patterns to a sorted list of files:

https://github.com/ruby/rake/blob/v13.0.1/lib/rake/file_list.rb#L408

By using `Rake::FileList` instead of `Dir.glob`, framework tests will
always run in the same order when given the same seed, and reproducing
order dependent CI failures will be easier.
2019-12-16 16:55:06 +00:00
Ryuta Kamizono
214f439343 Fixup CHANGELOGs [ci skip] 2019-11-24 09:20:00 +09:00
Dino Maric
966d3a7bf2 Fix typo in ACa documentation [ci skip] 2019-10-28 11:09:22 -04:00
Richard Macklin
fefc304199
Enforce that actioncable compiled JS bundle is in sync with source code
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
30a0c7e04093add0b14be6da17c7496e7dd40e10 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
a4c27588d5a1e6f270df42b7a305f03a9aee54f2. 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.
2019-10-19 02:26:31 +02:00
Orien Madgwick
493edf044f Add bug tracker/documentation/mailing list URIs to the gemspecs 2019-10-11 20:47:19 -04:00
Jean Boussier
a707072ffa Implicitly assert no exception is raised in block assertions 2019-10-07 11:01:24 +02:00
Juanjo Bazán
e4b5a3eb77 update package.json files to use https homepage value 2019-10-02 12:00:11 +02:00
meganemura
3b23c64497 List activesupport as a direct dependency 2019-10-01 13:28:52 -04:00
Narendra Rajput
66a44b1710 Fixed typo in comment in ActionCable::Connection::TestCase [ci skip] 2019-09-24 14:46:36 +05:30
Thomas Fankhauser
66c4861aff Renamed method in documentation string assert_broadcasts_on to the
correct `assert_broadcast_on` to close #37272
2019-09-23 15:30:55 +02:00
Akira Matsuda
8cc1bf9e2b Passing in a Hash instance as non-kwargs parameters has to be curly braced 2019-09-07 03:21:45 +09:00
Akira Matsuda
9a15149dab Keyword arguments is not a Hash 2019-09-07 03:20:07 +09:00
Akira Matsuda
438e93f7fd Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 03:19:51 +09:00
David Heinemeier Hansson
6315a11b90 Logging at info level should be reserved for top-level concerns
Information about partials and cable connection notices are too low level.
2019-08-26 16:43:45 -04:00
Javan Makhmali
55311b1596 Ensure @rails/actioncable package contains complete source
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
- c0368ad090b79c19300a4aa133bb188b2d9ab611
2019-08-15 09:19:59 -04:00
Rafael Mendonça França
967beb7229
Revert "MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now"
This reverts commit 98d0f7ebd34b858f12a12dcf37ae54fdbb5cab64.
2019-08-02 00:24:21 -04:00
Akira Matsuda
98d0f7ebd3 MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now
It's used everywhere, clean and mature enough
2019-08-02 05:36:15 +09:00
Akira Matsuda
0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
Alex Emelyanov
99c98c8034 ActionCable: optimize logger.debug calling 2019-06-08 19:23:47 +05:00
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Blake Stoddard
70d64169ae ActionCable: don't allowlist keys passed to the Redis initializer
Support all Redis features without needing to maintain a list of valid options that must stay in sync with the upstream client library.
2019-04-22 09:59:53 -04:00
Matthew Draper
e485c14a3e s/Travis/Buildkite/ 2019-04-09 11:28:49 +09:30
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
rmacklin
d03177ffbc Simplify ActionCable.createWebSocketURL and realphabetize exports (#35810)
* 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
2019-04-02 23:04:43 +02:00
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Ryan Castner
6d488a22d3 feat(js): Dynamic ActionCable URL (#35579)
* 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]
2019-03-31 19:41:12 +02:00
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Kasper Timm Hansen
5f7e01c84c
Fix style issues and build source after #35525
Ran `cd actioncable && yarn build`.

[ Kasper Timm Hansen & Ryan Castner ]
2019-03-11 14:32:43 +01:00
Kasper Timm Hansen
33800d2330
Merge pull request #35525 from audiolion/feature/dynamic-actioncable-websocket-url
feat(js): Dynamic Actioncable WebSocket URL
2019-03-11 13:54:28 +01:00
Ryan Castner
9333f86adb
address pr feedback
change if statement to ternary, use const for consistency, add spacing after ternary expression
2019-03-09 14:55:54 -05:00
Abhay Nikam
476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Ryan Castner
c7ca85ef31 feat(js): Dynamic Actioncable WebSocket URL
Allow createWebSocketURL fn to accept a function to generate the websocket URL rather than a string.
2019-03-07 22:14:20 -05:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Yasuo Honda
15e37b1fad Address uninitialized constant PostgresqlAdapterTest::ChannelPrefixTest (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
2019-02-15 02:10:38 +00:00
Vladimir Dementyev
c43c839847 feat: support channel_prefix in pg subscription adapter 2019-02-14 16:22:03 -08:00
Vladimir Dementyev
3cd69fa2c0
Allow passing custom config to ActionCable::Server::Base
That allows us to create a separate, isolated Action Cable server
instance within the same app.
2019-02-12 17:17:46 -05:00
Matthew Draper
287920ca7d Respect ENV variables when finding DBs etc for the test suite
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.
2019-02-06 01:20:06 +10:30
David Heinemeier Hansson
5588fb4802 Use ES6 short style 2019-02-04 16:22:12 -08:00
David Heinemeier Hansson
1fc3a2cc1b Match rails generator output 2019-02-04 16:22:00 -08:00
Vladimir Dementyev
8ed276b2f7
Add ActionCable channel/connection load hooks 2019-01-29 22:07:49 -05:00
Javan Makhmali
e3d43333db Add CHANGELOG entries for npm package renames [ci skip] 2019-01-28 06:29:26 -05:00
Kasper Timm Hansen
36c840057f
Merge pull request #35021 from palkan/refactor/broadcasting-for-testing
Action Cable: move channel_name to Channel.broadcasting_for
2019-01-24 23:40:33 +01:00
Sergey Ponomarev
c125990c7c
Fix attribute typo in ActionCable connection test request 2019-01-23 09:35:48 -05:00
Vladimir Dementyev
cfe65cb478
fix fixture syntax in cable docs and guides 2019-01-22 16:53:01 -05:00
Vladimir Dementyev
513dd2cfdb
Add note about broadcast_to/broadcasting_for to change log 2019-01-22 15:29:12 -05:00
Vladimir Dementyev
35bef64718
Add Channel#broadcast_to 2019-01-22 15:14:35 -05:00
Vladimir Dementyev
dc80459a9e
Move channel_name to Channel.broadcasting_for
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
```
2019-01-22 15:14:20 -05:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
Rafael França
92cc996a09
Merge pull request #34959 from alkesh26/action-cable-typo-fixes
Typo fixes in action cable.
2019-01-18 08:49:27 -05:00
alkesh26
393566c250 typo fixes in action cable 2019-01-17 22:02:35 +05:30
Javan Makhmali
481192171e
Merge pull request #34941 from rmacklin/allow-actioncable-to-run-in-web-workers
Avoid ReferenceError exceptions if ActionCable is used in a web worker
2019-01-16 17:10:57 -05:00
bogdanvlviv
a43052cbbc
Remove frozen_string_literal from Action Cable's template files
Related to 837f602fa1b3281113dac965a8ef96de3cac8b02

Fix the testing guide.
2019-01-16 15:14:35 +00:00
Richard Macklin
39493185d3 Remove explicit document receiver from add/removeEventListener calls
This allows ActionCable to be used in a web worker, where the `document`
global is undefined. Previously, attempting to use ActionCable inside a
web worker would result in this exception after you try to open a
connection:
```
ReferenceError: document is not defined
```

The visibilitychange event won't ever get triggered in a worker, so
adding the listener is effectively a no-op there. But the listener is
mainly a convenience, rather than a critical piece of the javascript
interface, so using ActionCable in a worker will still work. (And you
could listen for visibilitychange yourself in a window script, then tell
the worker to reconnect if you still want that behavior.)
2019-01-15 22:14:33 -08:00
Richard Macklin
ac8ffbe76a Replace window references in ActionCable with self
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
2019-01-14 17:44:35 -08:00
Rafael França
0ffafd475b
Merge pull request #34934 from rmacklin/simplify-actioncable-methods-after-decaffeination
Clean up ActionCable JS a bit more after the CoffeeScript conversion
2019-01-14 15:24:26 -05:00