Commit Graph

725 Commits

Author SHA1 Message Date
Hartley McGuire
c3c844ef3a
Add Rack::Lint to ActionCable::Server health tests
This adds additional coverage to ActionCable::Server to validate that
its output follow the Rack SPEC.

In addition to using Rack::CONTENT_TYPE for the Content-Type header,
there was another change required: the Content-Type header cannot be
specified when the Response status is 204, so the default health check
status was updated to 200
2023-08-16 22:49:32 -04:00
Alex Ghiculescu
455e922b49
Introduce capture_emails and capture_broadcasts (#48798) 2023-07-25 06:42:54 +02:00
Marcin Henryk Bartkowiak
bcf9e3de0c Do not inspect transmit data if logger is not debug-enabled 2023-07-20 18:52:26 +02:00
Marcin Henryk Bartkowiak
99d7dc88ae Add block support to TaggedLoggerProxy 2023-07-20 18:26:10 +02:00
julianfssen
9c5175e067 Delegate StubConnection#pubsub and StubConnection#config to ActionCable.server
Previously, `ActionCable::Channel::ConnectionStub` would
throw a `NoMethodError` when the channel under test calls
`stop_stream_for`, as shown in the example below:

```ruby
class ChatChannel < ActionCable::Channel::Base
  def subscribed
    stream_from "test"
  end

  def unsubscribed
    stop_stream_from "test"
  end
end

class ChatChannelTest < ActionCable::Channel::TestCase
  test "unsubscribe" do
    stub_connection

    subscribe

    # `unsubscribe` raises `NoMethodError` as `pubsub` does not
      exist on `ActionCable::Channel::ConnectionStub`
    unsubscribe

    assert_no_streams
  end
end
```

Calling `unsubscribe` causes an exception as `stop_stream_from` calls
`pubsub` when unsubscribing, which is not implemented in
`ActionCable::Channel::ConnectionStub`.

This commit fixes this issue by assigning the `ActionCable.server`
singleton to a `@server` instance variable in
`ActionCable::Channel::ConnectionStub`. This lets us delegate
the `config` and `pubsub` method calls to it.
2023-07-15 13:04:46 +08:00
zzak
dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
Rafael Mendonça França
74b8a3798b
Merge pull request #48222 from JoeDupuis/health-check-standalone-cable
Add health check on standalone Action Cable
2023-05-30 16:35:12 -04:00
Jean Boussier
d381d249d7
Merge pull request #48321 from moofkit/fix-sentinels-config-with-strings-arguments
Fix ActionCable Redis configuration with sentinels
2023-05-29 09:55:31 +02:00
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
Dmitriy Ivliev
f1ace63973 Fix ActionCable Redis configuration with sentinels
This commit resolves an integration bug between ActionCable and Redis >= 5.0 when using sentinels configuration.
The issue arises from the fact that the sentinels configuration is a nested array of hashes, while the Redis client expects keys to be symbols.
This fix modifies the preparation of the Redis configuration to ensure that all keys are represented as symbols.
2023-05-28 11:57:23 +00:00
Joé Dupuis
32e7028aa1 Add health check on standalone Action Cable
Action Cable can be mounted standalone, but it loses the health check
route provided by the railties.
This change adds configuration for a health check rack app and a
health check route to "mount" the rack app.

Fixes #48185
2023-05-27 16:59:34 -07:00
zzak
38bef29064
Replace all occurrences of '<tt>(\w+::\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>Rails::Command::NotesCommand</tt> -> +Rails::Command::NotesCommand+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-25 06:56:17 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Petrik
c4f0c10157 Clean up Action Cable documentation headers [ci skip] 2023-04-22 20:40:55 +02:00
Petrik
ba40945fe5 Add missing headers to Action Cable docs [ci-skip] 2023-04-02 10:20:50 +02:00
sampatbadhe
bcda8dbfad update assert_broadcasts example to include changes introduced in PR #47793 by @ghiculescu - Action Cable's assert_broadcasts return the messages that were broadcast to analyse further. 2023-04-01 15:46:42 +05:30
Jean Boussier
6879f89892
Merge pull request #47793 from ghiculescu/assert_broadcasts-return-messages
`assert_broadcasts`: return the messages that were broadcast
2023-03-31 11:52:07 +02:00
Petrik de Heus
dc0f20595d
Merge pull request #47717 from p8/docs/include-readmes
Include READMEs in main framework pages of the API documentation
2023-03-30 16:43:14 +02:00
Alex Ghiculescu
c3c8abfbd7 assert_broadcasts: return the messages that were broadcast
This PR is similar to https://github.com/rails/rails/pull/47025, it makes Action Cable's `assert_broadcasts` return the messages that were broadast. This way you can do more analysis on them:

```ruby
    messages = assert_broadcasts("test", 2) do
      ActionCable.server.broadcast "test", { message: "one" }
      ActionCable.server.broadcast "test", { message: "two" }
    end
    assert_equal 2, messages.length
    assert_equal({ "message" => "one" }, messages.first)
    assert_equal({ "message" => "two" }, messages.last)
```

This is helpful if you expect lots of messages to be broadcast or if you want to only match on some element of the data; `assert_broadcast_on` doesn't work well in either of those scenarios.
2023-03-28 11:49:28 -06:00
Vladimir Dementyev
5c4c794ab1
fix(ac-redis): rescue BaseConnectionError in redis <5 2023-03-27 17:21:46 -04:00
Simon Schmid
a9d191997b set charset in content type response headers 2023-03-24 10:17:04 +01:00
Petrik
7c94708d24 Include READMEs in main framework pages of the API documentation
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.

By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.

[ci-skip]

Co-authored-by: zzak <zzakscott@gmail.com>
2023-03-21 21:16:28 +01:00
Rafael Mendonça França
1bc9db4a06
Merge pull request #47483 from palkan/fix/channel-test-case-test-server
Fix using TestServer in ConnectionStub
2023-03-03 18:23:21 -05:00
Haroon Ahmed
627322eff4 Add a fake configuration with the ability to override the
subscription_adapter, so we no longer have to use openstruct.
2023-02-23 23:23:19 +00:00
Vladimir Dementyev
8fff6d609c
fix: do not use TestServer in ConnectionStub
It's an internal testing entity, we cannot use it in a test case class
2023-02-23 15:31:58 -05:00
zzak
d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Yasuo Honda
f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Rafael Mendonça França
177b9494e3
[Action Cable] Stop logging filtered params
Co-Autored-By: Kartikey Tanna <tannakartikey@gmail.com>
2023-02-08 17:22:39 +00:00
Haroon Ahmed
df00a4ebc7 Update the ActionCable::Connection::Base to no longer output env data and other stuff by overriding the inspect method and displaying a simpler output. 2023-02-06 11:02:34 +00:00
Jean Boussier
3d0d027bfd
Merge pull request #47204 from StephaneRob/feat-improve-assert-broadcast-on-message
feat: improve `assert_broadcast_on` error message
2023-02-05 00:24:46 +01:00
StephaneRob
1333260e11 feat: improve assert_broadcast_on error message 2023-02-04 19:48:41 +01:00
Matthew Draper
4b560ab00c Increase redis subscription timeout in Action Cable test 2023-02-04 21:58:17 +10:30
zzak
f8544410a2 Use stable guides link for package READMEs
E.g.: These show up here:
https://api.rubyonrails.org/files/actioncable/README_md.html
2023-02-04 09:01:00 +09:00
zzak
b1f605471d Add changelog for #41415 2023-01-27 19:10:23 +09:00
Rafael Mendonça França
847cc9f8cb
Merge pull request #41415 from zedtux/features/actioncable/token
Allows passing sub protocols with ActionCable
2023-01-18 16:37:55 -05:00
Akira Matsuda
4c23742a13
delegate to: :class has to be defined after the target method
in order to derive the arity from the target class method.
2023-01-11 04:32:08 +09:00
Ghouse Mohamed
e0559d2c1c Change 2022 -> 2023 2023-01-03 13:22:00 +05:30
Akira Matsuda
9f141a423d
Module name typo in documentation 2022-12-26 23:13:04 +09:00
Akira Matsuda
4732c91d14
Trivial fix on CHANGELOG 2022-12-26 19:53:17 +09:00
Hartley McGuire
a07f2ace03
Fix lots of code highlighting issues
The most common is replacing back-ticks with either pluses or tt tags.
There were also a few instances of code blocks not being indented.
2022-11-29 00:51:02 -05:00
Étienne Barrié
3d6a7b2faa Initialize deprecators before configuring them
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.

This ensures they're all registered before the environments are loaded.
2022-11-28 10:47:26 +01:00
Vladimir Dementyev
ae649b152e
feat: restore Action Cable Redis pub/sub listener on connection failure
Closes #27659
2022-11-23 21:53:10 -05:00
Jonathan Hefner
1edc5ea918
Merge pull request #46427 from cpb/cpb-fix-clear-reloadable-connections-deprecation-warning
Fix clear_reloadable_connections! deprecation warning
2022-11-04 18:31:59 -05:00
Caleb Buxton
598e9f36cb Fix clear_reloadable_connections! deprecation warning
This fixes the following warning when running Action Cable tests:

  ```
  DEPRECATION WARNING: Calling `ActiveRecord::Base.clear_reloadable_connections! is deprecated. Please call the method directly on the connection handler; for example: `ActiveRecord::Base.connection_handler.clear_reloadable_connections!`.
  ```
2022-11-04 15:50:48 -07:00
Caleb Buxton
6e9675c6bf Fix clear_all_connections! NoMethodError
This fixes the following error when running Action Cable tests:

  ```
  NoMethodError: undefined method `clear_all_connections!' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  actioncable/test/subscription_adapter/postgresql_test.rb:38:in `teardown'
  ```
2022-11-04 15:30:33 -07:00
Jonathan Hefner
5a4eadd51c Add ActionCable.deprecator
This commit adds `ActionCable.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
2022-11-01 17:39:39 -05:00
Jonathan Hefner
25ae059d16 Fix clear_all_connections! deprecation warning
This fixes the following warning when running Action Cable tests:

  ```
  DEPRECATION WARNING: Calling `ActiveRecord::Base.clear_all_connections! is deprecated. Please call the method directly on the connection handler; for example: `ActiveRecord::Base.connection_handler.clear_all_connections!`.
  ```
2022-10-25 15:01:42 -05:00
Guillaume Hain
6edb465bcf
Allows adding more protocols to the WebSocket sub protocols 2022-10-19 09:00:15 +02:00
Petrik de Heus
cf2be23577
Merge pull request #45469 from skryukov/docs-for-action-cable-channel-callbacks [ci-skip]
Document Action Cable Callbacks
2022-10-18 21:28:52 +02:00
Jean Boussier
d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00