When converting docs from RDoc to Markdown, some label-lists ended up
not rendering properly. This appears to be due to RDoc's Markdown
parser not recognizing label-list labels if the label has additional
markup around it (in this case, bold markers `**`).
Additionally, the markdown label-list was missing newlines between list
items which also caused the label-list to not render correctly.
This commit fixes both of these issues for cases where the RDoc
originally used <b> tags in a label-list label. Since label-list labels
will already be bolded, there is no reason to also use `**` on the
labels.
Replaced by `#lease_connection` to better reflect what it does.
`ActiveRecord::Base#connection` is deprecated in the same way
but without a removal timeline nor a deprecation warning.
Inside the Active Record test suite, we do remove `Base.connection`
to ensure it's not used internally.
Some callsites have been converted to use `with_connection`,
some other have been more simply migrated to `lease_connection`
and will serve as a list of callsites to convert for
https://github.com/rails/rails/pull/50793
Follow-up to [#48798][]
Reverts [#47837][]
The `capture_broadcasts` helper was introduced in [#48798][] to remove
the return value from the `assert_broadcasts` call. The behavior was
changed, but the corresponding documentation for the `assert_broadcasts`
method did not revert the changes added in [#47837][].
This change should probably also get backported to `7-1-0-stable`.
[#47837]: https://github.com/rails/rails/pull/47837
[#48798]: https://github.com/rails/rails/pull/48798
Co-authored-by: Matheus Richard <matheusrichardt@gmail.com>
Dynamic delegation make sense when there is a long list of methods
etc. But for very simple cases, writing one or two methods by hand
is just clearer and more efficient.
The Rails documentation uses the `:include:` directive to inline the
README of the framework into the main documentation page. As the
README's aren't in the root directory from where SDoc is run we need to
add the framework path to the include:
# :include: activesupport/README.md
This results in a warning when installing the gems as generating the rdoc for the gem is run from the gem/framework root:
Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb
The `:include:` RDoc directive supports includes relative to the current
file as well:
# :include: ../README.md
This makes sure it works for the Rails API docs and the separate gems.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
This is a follow-up to https://github.com/rails/rails/pull/50585.
I propose to provide smoother reading experiences with the two methods
introduced in there, `#assert_not_has_stream` and `#assert_not_has_stream_for`,
by renaming them `#assert_has_no_stream` and `#assert_has_no_stream_for`, respectively.
This adds two new assertion methods for ActionCable test cases:
`assert_not_has_stream` and `assert_not_has_stream_for`. These methods
can be used to assert that a stream has been stopped, e.g. via
`stop_stream` or `stop_stream_for`.
Until now, Rails only droped compatibility with older
rubies on new majors, but I propose to change this policy
because it causes us to either keep compatibility with long
EOLed rubies or to bump the Rails major more often, and to
drop multiple Ruby versions at once when we bump the major.
In my opinion it's a bad alignments of incentives. And we'd
be much better to just drop support in new minors whenever they
go EOL (so 3 years).
Also Ruby being an upstream dependency, it's not even
a semver violation AFAICT.
Since Rails 7.2 isn't planned before a few months, we
can already drop Ruby 3.0 as it will be EOL in March.
This is a continuation of https://github.com/rails/rails/pull/46875
The behavior of looking up the class method when `to: :class` is passed
is a bit error prone because it silently degrades.
By passing the expected owner of the delegated method, we can be more
strict, and also generate a delegator in a module rather than having
to do it at inclusion time.
I made this argument private API because we want it in Rails, but
I'm worried it might be a bit too sharp for public API. I can
be convinced otherwise though.
This adds `linguist-generated` and `linguist-vendored` attributes where
appropriate to suppress the files in diffs and exclude the files from
the project's language stats on GitHub.
See https://github.com/github/linguist for more information.
Prior to this commit, if `app/javascript/action_cable/index.js`
contained a syntax error, `JavascriptPackageTest` would still pass
because `system "yarn build"` would simply return `false` and the
compiled output would not change. This commit adds `exception: true` to
the `system` call so that an error will be raised if `yarn build` fails.
Also, since 4a23cb3415eac03d76623112576559a722d1f23d, Active Storage
compiles additional `app/assets/javascripts/actioncable.js` and
`app/assets/javascripts/actioncable.esm.js` files (with
`app/assets/javascripts/action_cable.js` being deprecated). This commit
adds assertions for those files as well.
It's possible since Rails 6 (3ea2857943dc294d7809930b4cc5b318b9c39577) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.
Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
Ideally we should be able to checkout an Adapter instance without
triggering a connection to the server.
For some adapters like Trilogy that is the case today, but only if
you have a schema cache loaded, otherwise `check_version` will trigger
a query.
I think this check can be delayed to when we actually use the connection.
* Add Bun support to `rails new -j` generator
* Add additional generation consideration for Bun
* Use development gems to test the whole workflow
* Remove custom gems from local testing
* Revert lock
* Revert errant custom gem declaration
* Fix linting errors
* Fix remnants of bad merge
* Always use latest bun
* Update actioncable/lib/rails/generators/channel/channel_generator.rb
Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
* Update guides/source/working_with_javascript_in_rails.md
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
* Only use the latest bun if nothing is specified
* Hardcode known good version
---------
Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
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
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.
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.
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
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.