Commit Graph

766 Commits

Author SHA1 Message Date
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
Richard Macklin
739f88e52e Simplify this.isActive() && this.webSocket into this.isActive()
in Connection#close. We can do this because `isActive()` can only
return `true` if `this.webSocket` is truthy. (We can't have an active
connection without having instantiated a WebSocket. This is confirmed
in the code: Connection#isActive calls Connection#isState which calls
Connection#getState, which checks if `this.webSocket` is truthy and
returns `null` otherwise.)
2019-01-14 11:52:46 -08:00
Richard Macklin
6320916513 Simplify ActionCable.getConfig, Connection#getProtocol, and Connection#close
by relying on the implicit undefined return value
2019-01-14 11:35:04 -08:00
Richard Macklin
dbe073aebf Simplify ActionCable.createConsumer by using default argument 2019-01-14 11:33:24 -08:00
Vladimir Dementyev
a4099debcf
Add Action Cable Testing guides 2019-01-14 11:16:59 -05:00
Vladimir Dementyev
0f41aa30d3
Add channel test generator 2019-01-13 21:54:31 -05:00
Kasper Timm Hansen
3631d7eee4
Update Action Cable connection testing.
* 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.
2019-01-14 01:19:56 +01:00
Ryuta Kamizono
66ab843a66
Merge pull request #34930 from bogdanvlviv/merge-actioncable-README.md-to-the-guide
Merge `actioncable/README.md` to the Action Cable Overview guide [ci skip]
2019-01-14 05:48:39 +09:00
bogdanvlviv
8e7d9ce8cb
Merge actioncable/README.md to the Action Cable Overview guide [ci skip]
In #34709 we updated the guide, but `actioncable/README.md` is still
outdated. Instead of fixing content in the file. I suggest
not duplicate the info that is already in the guide and instead remove
the info from the file and just add a message:
"You can read more about Action Cable in the
[Action Cable Overview](https://edgeguides.rubyonrails.org/action_cable_overview.html) guide."

The same approach is being used for Action Mailbox and Action Text,
see #34812 and #34878.
2019-01-13 19:45:04 +00:00
Kasper Timm Hansen
907b528854
Merge pull request #34845 from palkan/feature/action-cable-connection-testing
Add ActionCable::Connection::TestCase
2019-01-13 18:30:47 +01:00
Javan Makhmali
86b489e3d6 Move all npm packages to @rails scope
Fixes #33083
2019-01-10 11:01:57 -05:00
Kasper Timm Hansen
647d7e6167
Revert "Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json""
I reverted the wrong commit. Damn it.

This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
2019-01-08 22:19:22 +01:00
Kasper Timm Hansen
f66a977fc7
Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"
We had a discussion on the Core team and we don't want to expose this information
as a JSON endpoint and not by default.

It doesn't make sense to expose this JSON locally and this controller is only
accessible in dev, so the proposed access from a production app seems off.

This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing
changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
2019-01-08 22:16:58 +01:00
Vladimir Dementyev
90296674b1
feature: add ActionCable::Connection::TestCase 2019-01-02 19:47:38 -05:00
Arun Agrawal
472a0d7e40
Merge pull request #34831 from arunagw/bump-year-to-2019
Bump license years for 2019
2018-12-31 23:08:43 +05:30
George Claghorn
c45e3e74ed
Merge pull request #34740 from sponomarev/feature/assert_has_stream
Add streams assert methods to ActionCable channel test case
2018-12-31 11:12:01 -05:00
Arun Agrawal
50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
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.
2018-12-21 06:12:42 +09:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Sergey Ponomarev
9c8d4850f1
Add streams assert methods to ActionCable channel test case 2018-12-18 17:37:53 -05:00
Ilia Kasianenko
87f407db3e Add Missing ActiveSupport::Rescuable to ActionCable::Channel
[timthez, Ilia Kasianenko]
2018-12-12 15:48:55 +02:00
Mick Staugaard
58dbc1c2ed Stop trying to reconnect on unauthorized cable connections 2018-12-05 10:40:29 -08:00
Richard Macklin
fced64062f Add missing authorship to ActionCable changelog entry
I accidentally forgot to add the author line to my changelog entry from
2bb4fdef5efc70327c018e982ff809a29ac6708b
2018-12-02 17:16:02 -08:00
Javan Makhmali
985557b533
Merge pull request #34590 from rmacklin/use-websocket-adapter-in-getState
Replace reference to WebSocket global with ActionCable.adapters.WebSocket
2018-12-02 14:50:05 -05:00
Richard Macklin
fb0c81d349 Remove obsolete yarn.lock files and check in root yarn.lock file 2018-12-02 10:02:14 -08:00
Richard Macklin
2bb4fdef5e Replace reference to WebSocket global with ActionCable.adapters.WebSocket
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.
2018-12-01 14:49:43 -08:00
rmacklin
aa1ba9cb24 Remove circular dependency warnings in ActionCable javascript and publish 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
2018-12-01 16:25:02 -05:00
rmacklin
85b0803653 Convert ActionCable tests from CoffeeScript to ES2015 and replace Blade with 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
2018-11-26 17:16:02 -05:00
Richard Macklin
a4c27588d5 Synchronize ActionCable JS source code with compiled bundle
30a0c7e04093add0b14be6da17c7496e7dd40e10 commited changes to the
compiled bundle but not to the corresponding source files. This meant
that running `yarn build` was producing untracked changes to the
compiled bundle. The fix is to commit the changes to the source files
so that they are in sync.
2018-11-16 20:00:45 -08:00
Husam Bilal
30a0c7e040 Allow patching polling interval logarithmic multiplier 2018-11-14 11:30:47 +02:00
Gannon McGibbon
e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon
1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -05:00
Richard Macklin
c96139af71 Convert ActionCable javascript to ES2015 modules with modern build environment
We've replaced the sprockets `//= require` directives with ES2015
imports. As a result, the ActionCable javascript can now be compiled
with rollup (like ActiveStorage already is).

- Rename action_cable/index.js.erb -> action_cable/index.js

- Add rake task to generate a javascript module of the ActionCable::INTERNAL ruby hash

  This will allow us to get rid of ERB from the actioncable javascript,
  since it is only used to interpolate ActionCable::INTERNAL.to_json.

- Import INTERNAL directly in ActionCable Connection module

  This is necessary to remove a load-order dependency conflict in the
  rollup-compiled build. Using ActionCable.INTERNAL would result in a
  runtime error:
  ```
  TypeError: Cannot read property 'INTERNAL' of undefined
  ```
  because ActionCable.INTERNAL is not set before the Connection module
  is executed.

  All other ActionCable.* references are executed inside of the body of a
  function, so there is no load-order dependency there.

- Add eslint and eslint-plugin-import devDependencies to actioncable

  These will be used to add a linting setup to actioncable like the one
  in activestorage.

- Add .eslintrc to actioncable

  This lint configuration was copied from activestorage

- Add lint script to actioncable

  This is the same as the lint script in activestorage

- Add babel-core, babel-plugin-external-helpers, and babel-preset-env devDependencies to actioncable

  These will be used to add ES2015 transpilation support to actioncable
  like we have in activestorage.

- Add .babelrc to actioncable

  This configuration was copied from activestorage

- Enable loose mode in ActionCable's babel config

  This generates a smaller bundle when compiled

- Add rollup devDependencies to actioncable

  These will be used to add a modern build pipeline to actioncable like
  the one in activestorage.

- Add rollup config to actioncable

  This is essentially the same as the rollup config from activestorage

- Add prebuild and build scripts to actioncable package

  These scripts were copied from activestorage

- Invoke code generation task as part of actioncable's prebuild script

  This will guarantee that the action_cable/internal.js module is
  available at build time (which is important, because two other modules
  now depend on it).

- Update actioncable package to reference the rollup-compiled files

  Now that we have a fully functional rollup pipeline in actioncable, we
  can use the compiled output in our npm package.

- Remove build section from ActionCable blade config

  Now that rollup is responsible for building ActionCable, we can remove
  that responsibility from Blade.

- Remove assets:compile and assets:verify tasks from ActionCable

  Now that we've added a compiled ActionCable bundle to version control,
  we don't need to compile and verify it at publish-time.

  (We're following the pattern set in ActiveStorage.)

- Include compiled ActionCable javascript bundle in published gem

  This is necessary to maintain support for depending on the ActionCable
  javascript through the Sprockets asset pipeline.

- Add compiled ActionCable bundle to version control

  This mirrors what we do in ActiveStorage, and allows ActionCable to
  continue to be consumed via the sprockets-based asset pipeline when
  using a git source instead of a published version of the gem.
2018-11-02 08:41:05 -07:00
Richard Macklin
0eb6b86e96 Refactor decaffeinate output to more natural/idiomatic javascript
- Remove unnecessary Array.from usages from subscriptions.js

  These were all Arrays before, so Array.from is a no-op

- Remove unnecessary IIFEs from subscriptions.js

- Manually decaffeinate sample ActionCable code in comments

  Here the coffeescript -> ES2015 conversion was done by hand rather than
  using decaffeinate, because these code samples were simple enough.

- Refactor ActionCable.Subscription to avoid initClass

- Refactor ActionCable.Subscription to use ES2015 default parameters

- Refactor ActionCable.ConnectionMonitor to avoid initClass

- Refactor ActionCable.ConnectionMonitor to use shorter variations of null checks

- Remove unnecessary code created because of implicit returns in ConnectionMonitor

  This removes the `return` statements that were returning the value of
  console.log and those from private methods whose return value was not
  being used.

- Refactor ActionCable.Connection to avoid initClass

- Refactor Connection#isProtocolSupported and #isState

  This addresses these three decaffeinate cleanup suggestions:
  - DS101: Remove unnecessary use of Array.from
  - DS104: Avoid inline assignments
  - DS204: Change includes calls to have a more natural evaluation order

  It also removes the use of Array.prototype.includes, which means we
  don't have to worry about providing a polyfill or requiring that end
  users provide one.

- Refactor ActionCable.Connection to use ES2015 default parameters

- Refactor ActionCable.Connection to use shorter variations of null checks

- Remove return statements that return the value of console.log() in ActionCable.Connection

- Simplify complex destructure assignment in connection.js

  decaffeinate had inserted
  ```
  adjustedLength = Math.max(protocols.length, 1)
  ```
  to be safe, but we know that there has to always be at least one
  protocol, so we don't have to worry about protocols.length being 0 here.

- Refactor Connection#getState

  The decaffeinate translation of this method was not very clear, so we've
  rewritten it to be more natural.

- Simplify destructure assignment in connection.js

- Remove unnecessary use of Array.from from action_cable.js.erb

- Refactor ActionCable#createConsumer and #getConfig

  This addresses these two decaffeinate cleanup suggestions:
  - DS104: Avoid inline assignments
  - DS207: Consider shorter variations of null checks

- Remove unnecessary code created because of implicit returns in action_cable.js.erb

  This removes the `return` statements that were returning the value of
  console.log and those from methods that just set and unset the
  `debugging` flag.

- Remove decaffeinate suggestion about avoiding top-level this

  In this case, the top-level `this` is intentional, so it's okay to
  ignore this suggestion.

- Remove decaffeinate suggestions about removing unnecessary returns

  I did remove some of the return statements in previous commits, where
  it seemed appropriate. However, the rest of these should probably remain
  because the return values have been exposed through the public API. If
  we want to break that contract, we can do so, but I think it should be
  done deliberately as part of a breaking-API change (separate from this
  coffeescript -> ES2015 conversion)

- Remove unused `unsupportedProtocol` variable from connection.js

  Leaving this would cause eslint to fail

- Refactor Subscriptions methods to avoid `for` ... `of` syntax

  Babel transpiles `for` ... `of` syntax to use `Symbol.iterator`, which
  would require a polyfill in applications that support older browsers.

  The `for` ... `of` syntax was produced by running `decaffeinate`, but in
  these instances a simpler `map` should be sufficient and avoid any
  `Symbol` issues.
2018-11-02 08:40:59 -07:00
Richard Macklin
403c001c56 Run decaffeinate on action_cable/*.js
Using [decaffeinate], we have converted these files from coffeescript
syntax to ES2015 syntax. Decaffeinate is very conservative in the
conversion process to ensure exact coffeescript semantics are preserved.
Most of the time, it's safe to clean up the code, and decaffeinate has
left suggestions regarding potential cleanups we can take. I'll tackle
those cleanups separately.

After running decaffeinate, I ran:
```
eslint --fix app/javascript
```
using the eslint configuration from ActiveStorage to automatically
correct lint violations in the decaffeinated output. This removed 189
extra semicolons and changed one instance of single quotes to double
quotes.

Note: decaffeinate and eslint can't parse ERB syntax. So I worked around
that by temporarily quoting the ERB:
```diff
 @ActionCable =
-  INTERNAL: <%= ActionCable::INTERNAL.to_json %>
+  INTERNAL: "<%= ActionCable::INTERNAL.to_json %>"
   WebSocket: window.WebSocket
   logger: window.console
```
and then removing those quotes after running decaffeinate and eslint.

[decaffeinate]: https://github.com/decaffeinate/decaffeinate
2018-11-02 08:40:35 -07:00
Richard Macklin
7b0b37240a Move actioncable javascript to app/javascript and change .coffee -> .js
- Rename action_cable/*.coffee -> *.js

- Move app/assets/javascripts/* -> app/javascript/*

- Rename action_cable.js.erb -> action_cable/index.js.erb

Renaming the extension to .js is in preparation for converting these
files from coffeescript to ES2015.

Moving the files to app/javascript and putting the entry point in
index.js.erb changes the structure of ActionCable's javascript to match
the structure of ActiveStorage's javascript.

(We are doing the file moving and renaming in a separate commit to
ensure that the git history of the files will be preserved - i.e. git
will track these as file renames rather than unrelated file
additions/deletions. In particular, git blame will still trace back to
the original authorship.)
2018-11-02 08:40:10 -07:00
Esquith Allen
3b4939abda
Update authorization.rb 2018-10-30 16:57:42 -04:00
Francesco Rodríguez
0f7655c325 Remove unnecessary escape character 2018-10-19 15:59:20 +02:00
Greg Molnar
d1a32f314c fix broken link in Action Cable guides and readme [ci skip] 2018-10-08 17:07:03 +02:00
R.T. Lechow
badb910b54 Fix typos
Fixes some typos.
2018-10-01 19:56:50 -04:00
David Heinemeier Hansson
4838c1716a
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps

* Stop including coffee-rails by default

* Drop using a js_compressor by default

* Drop extra test for coffeescript inclusion by default

* Stick with skip_javascript to signify skipping webpack

* Don't install a JS runtime by default any more

* app/javascript will be the new default directory for JS

* Make it clear that this is just for configuring the default Webpack framework setup now

* Start using the Webpack tag in the default layout

* Irrelevant test

* jQuery is long gone

* Stop having asset pipeline compile default application.js

* Add rails-ujs by default to the Webpack setup

* Add Active Storage JavaScript to application.js pack by default

* Consistent quoting

* Add Turbolinks to default pack

* Add Action Cable to default pack

Need some work on how to set the global consumer that channels will
work with. @javan?

* Require all channels by default and use a separate consumer stub

* Channel generator now targets Webpack style

* Update task docs to match new generator style

* Use uniform import style

* Drop the JS assets generator

It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!

* Add app/javascript to the stats directories

* Simpler import style

Which match the other imports.

* Address test failures from dropping JS compilation (and compression)

* webpacker-default: Modify `AssetsGeneratorTest`

Before:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201

F

Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10

.

Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571

..

Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

* webpacker-default: Modify `ChannelGeneratorTest`

Before:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986

.F

Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34

.F

Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22

E

Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60

F

Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80

F

Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68

Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```

After:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857

.......

Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```

* Fix shared generator tests.

* webpacker-default: Modify `ControllerGeneratorTest`

The JS assets generator was dropped. ref. 46215b1794

* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.

This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.

* require webpacker in test app

* Add webpacker without making the build hang/timeout. (#33640)

* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required

* no longer need to have webpacker in env templates as webpacker moved this config to yml file

* Fix rubocop violation

* Got the test passing for the running scaffold

* update expected lines of code

* update middleware tests to account for webpacker

* disable js in plugins be default to get the tests passing (#34009)

* clear codeclimate report issues

* Anything newer than currently released is good

* Use Webpacker development version during development of Rails

* Edge should get development webpacker as well

* Add changelog entry for Webpacker change
2018-09-30 22:31:21 -07:00
Yasuo Honda
aa3dcabd87 Add Style/RedundantFreeze to remove redudant .freeze
Since Rails 6.0 will support Ruby 2.4.1 or higher
`# frozen_string_literal: true` magic comment is enough to make string object frozen.
This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.

* Exclude these files not to auto correct false positive `Regexp#freeze`
 - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
 - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'

It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.

* Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required

 - 'actionpack/test/controller/test_case_test.rb'
 - 'activemodel/test/cases/type/string_test.rb'
 - 'activesupport/lib/active_support/core_ext/string/strip.rb'
 - 'activesupport/test/core_ext/string_ext_test.rb'
 - 'railties/test/generators/actions_test.rb'
2018-09-29 07:18:44 +00:00
Vladimir Dementyev
e229346c9e
Remove Rails 5.0 workaround from ActionCable::Channel::TestCase
The hack was merged from action-cable-testing gem by mistake.
We don't need it in Rails 6.

(cherry picked from commit 92030ec4b4309835ed0e792229984a1f0a044cef)
2018-09-27 11:17:52 -04:00
Vladimir Dementyev
8541394e71 Add ActionCable::Channel::TestCase
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
2018-09-26 22:06:14 -07:00
Kasper Timm Hansen
22dc2b3db8
Merge pull request #33949 from sjain1107/no-private-def
Remove private def
2018-09-23 19:39:15 +02:00
Sakshi Jain
0fe2bb816f Remove private def 2018-09-23 21:27:44 +05:30
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
Ryuta Kamizono
abfc1db01f Fix test case to ensure default connection id is filled
Follow up of #33798.
2018-09-07 04:00:00 +09:00
Ilia Kasianenko
bcd11e07b5 ActionCable: add id option to redis adapter config 2018-09-05 16:54:44 +03:00
nisusam
c9fd722851 Update link for Rack socket hijacking API
- Use valid `fragment identifier` in the URL
- Use `https`
2018-09-04 14:49:49 +05:30
bogdanvlviv
86e7de7968
DRY in assert_broadcasts
Test `assert_no_broadcasts` failure
2018-08-23 12:39:03 +03:00
bogdanvlviv
d2ccf0c6f7
Simplify configuring of ActionCable.server.config.logger for actioncable tests
See `git grep "= Logger.new(nil)"`
2018-08-23 12:36:19 +03:00
bogdanvlviv
0e42d3db59
Clarify api docs of ActionCable::SubscriptionAdapter::Test
Remove extra `:nodoc:` comment since private methods doesn't require that.
2018-08-23 12:30:16 +03:00
Vladimir Dementyev
c11ca09962
Add Action Cable test case and test helper 2018-08-19 19:23:33 -04:00
Vladimir Dementyev
f7dd2d67d6
Add Action Cable test adapter 2018-08-19 19:06:30 -04:00
Bart de Water
eb5fea40a4 Enable Start/EndWith and RegexpMatch cops
In cases where the MatchData object is not used, this provides a speed-up:
https://github.com/JuanitoFatas/fast-ruby/#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end
2018-07-28 17:37:17 -04:00
Alberto Almagro
e42af97345 Remove thirdparty FIXME
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.
2018-07-25 22:59:11 +02:00
Ryuta Kamizono
6f58b2cfc9 Enable Layout/EmptyLinesAroundBlockBody to reduce review cost in the future
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.
2018-07-12 21:29:48 +09:00
Samuel Williams
93e185e1d4
Better compatibility with SPEC.
If `env` is duped or otherwise not the same as the original `env` that was
generated at the top of rack middleware, it is impossible for the server hijack
proc to update the right `env` instance. Therefore, capturing the return value
is more reliable. This is the recommendation of the rack SPEC.
2018-07-04 12:45:35 +12:00
utilum
436ec799a4 Remove redundant accessors
introduced in a0ea528b61.
2018-06-11 16:39:50 +02:00
Rafael França
9204c0c5fa
Merge pull request #33102 from bogdanvlviv/refactor-actioncable-tests
Refactor actioncable's tests
2018-06-08 18:54:57 -04:00
Rafael Mendonça França
c07c708cf6
Merge pull request #27577 from maclover7/jm-fix-27547
Action Cable owns database connection, not Active Record
2018-06-08 18:21:05 -04:00
bogdanvlviv
74a9a29277
Include ActiveSupport::Testing::MethodCallAssertions to 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.
2018-06-08 23:29:05 +03:00
bogdanvlviv
d97f1670bd
Inherit all actioncable's test classes from ActionCable::TestCase
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.
2018-06-08 23:23:06 +03:00
utilum
76f1404303 Remove mocha from ActionCable tests
Q.E.D.
2018-05-31 17:53:55 +02:00
utilum
a0ea528b61 Use Ruby instead of mocha 2018-05-31 17:48:20 +02:00
utilum
84854d9d05 Use minitest/mock instead of mocha 2018-05-31 17:48:20 +02:00
bogdanvlviv
d66d3a4bd1
Fix actionable test's assertion
Pull Request #32727 changed "mocha expects" in favor of `MethodCallAssertions`.
This commit fixes assertion that became less strict after the PR.
2018-05-28 09:20:24 +00:00
utilum
78288f75e1 remove unnecessary mocking in ActionCable tests 2018-05-22 02:29:18 +02:00
utilum
d1f58e9922 assert_called_with 2018-04-26 08:02:08 +02:00
utilum
94ceda00b9 assert_called 2018-04-26 08:02:08 +02:00
utilum
e4e25cc8dc assert_not_called 2018-04-26 08:02:08 +02:00
Ryuta Kamizono
e4a0a04883 Strip duplicated suffixes more strictly
In the previous code incorrectly removes intermediate words.
2018-04-22 14:30:07 +09:00
Daniel Colson
a1ac18671a Replace assert ! with assert_not
This autocorrects the violations after adding a custom cop in
3305c78dcd.
2018-04-19 08:11:33 -04:00
utilum
86cafe7c9d 2.6 warning: passing splat keyword arguments as a single Hash
Ruby 2.6.0 warns about this.

``` ruby -v
ruby 2.6.0dev (2018-04-04 trunk 63085) [x86_64-linux]
```

Before, see:
https://travis-ci.org/rails/rails/jobs/365740163#L1262-L1264
https://travis-ci.org/rails/rails/jobs/365944863#L2121-L2174
2018-04-15 10:09:38 +02:00
James Mead
30735ab726 Make Mocha setup explcitly Minitest-specific
This has been possible since Mocha v1.0 and makes it clear that we want
Mocha to integrate with Minitest, not Test::Unit.
2018-04-07 12:23:40 +01:00
Ryuta Kamizono
a07d068078 Class methods in the class_methods blocks are wrongly appeared in the doc
It is wrongly appeared as instance public methods in the doc.

http://api.rubyonrails.org/v5.1.6/classes/ActionCable/Channel/Callbacks.html
http://api.rubyonrails.org/v5.1.6/classes/ActiveRecord/Timestamp.html
2018-04-04 09:04:15 +09:00
Rafael Mendonça França
ba0ae542ca
Remove changelog header for unreleased version
We only add the header when releasing to avoid some conflicts.

[ci skip]
2018-03-13 15:20:57 -04:00
Jeremy Daer
d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
bogdanvlviv
0f98954a83
Clean up and consolidate .gitignores
* Global ignores at toplevel .gitignore
* Component-specific ignores in each toplevel directory
* Remove `actionview/test/tmp/.keep` for JRuby

```
rm actionview/test/tmp/ -fr
cd actionview/
bundle exec jruby -Itest test/template/digestor_test.rb
```

Related to #11743, #30392.

Closes #29978.
2018-02-17 14:26:19 -08:00
Jeremy Daer
1e526788e6 Rails 6 requires Ruby 2.3+ 2018-02-17 10:03:37 -08:00
Rafael Mendonça França
0ea8e7db1a Remove support to Ruby 2.2
Rails 6 will only support Ruby >= 2.3.
2018-02-16 18:52:10 -05:00
Rafael Mendonça França
1c383df324 Start Rails 6.0 development!!!
🎉🎉🎉
2018-01-30 18:51:17 -05:00
Daniel Colson
82c39e1a0b Use assert_empty and assert_not_empty 2018-01-25 23:32:59 -05:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Daniel Colson
211adb47e7 Change refute to assert_not 2018-01-25 23:32:58 -05:00
Matthew Draper
acbcef6094
Merge pull request #31732 from koic/enable_autocorrect_for_lint_end_alignment_cop
Enable autocorrect for `Lint/EndAlignment` cop
2018-01-19 17:49:21 +10:30
Jared Beck
e1473e0cbf Testing actioncable against websocket-driver 0.7.0 (#30711)
* Depend on websocket-driver >= 0.6.1
2018-01-18 15:32:26 -06:00
Koichi ITO
5ac6ec54a6 Enable autocorrect for Lint/EndAlignment cop
### Summary

This PR changes .rubocop.yml.

Regarding the code using `if ... else ... end`, I think the coding style
that Rails expects is as follows.

```ruby
var = if cond
  a
else
  b
end
```

However, the current .rubocop.yml setting does not offense for the
following code.

```ruby
var = if cond
        a
      else
        b
      end
```

I think that the above code expects offense to be warned.
Moreover, the layout by autocorrect is unnatural.

```ruby
var = if cond
  a
      else
        b
      end
```

This PR adds a setting to .rubocop.yml to make an offense warning and
autocorrect as expected by the coding style.
And this change also fixes `case ... when ... end` together.

Also this PR itself is an example that arranges the layout using
`rubocop -a`.

### Other Information

Autocorrect of `Lint/EndAlignment` cop is `false` by default.
https://github.com/bbatsov/rubocop/blob/v0.51.0/config/default.yml#L1443

This PR changes this value to `true`.

Also this PR has changed it together as it is necessary to enable
`Layout/ElseAlignment` cop to make this behavior.
2018-01-18 17:19:13 +09:00
Lars Kanis
f820dc2dea PostgreSQL: Allow pg-1.0 gem to be used with ActiveRecord
pg-1.0.0 is just released and most Gemfiles don't restrict
it's version. But the version is checked when connecting to
the database, which leads to the following error:

Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0

See also this pg issue:
https://bitbucket.org/ged/ruby-pg/issues/270/pg-100-x64-mingw32-rails-server-not-start

Preparation for pg-1.0 was done in commit f28a331023fab,
but the pg version constraint was not yet relaxed.
2018-01-10 21:55:43 +01:00
Yoshiyuki Hirano
b20354afcc Bump license years for 2018 2017-12-31 22:36:55 +09:00
Rafael Mendonça França
2837d0f334
Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
Fatos Morina
37cf9b3466 Fix typos and add a few suggestions 2017-11-28 19:27:43 +01:00
Rafael Mendonça França
cceeeb6e57
Preparing for 5.2.0.beta1 release 2017-11-27 14:50:03 -05:00
Fumiaki MATSUSHIMA
788c908577 Fix unstable test test_delegate_socket_errors_to_on_error_handler
I often face the following error when running test/connection/client_socket_test.rb:

```
$ bin/test test/connection/client_socket_test.rb:38
Run options: --seed 44035

# Running:

F

Failure:
ActionCable::Connection::ClientSocketTest#test_delegate_socket_errors_to_on_error_handler
[/app/actioncable/test/connection/client_socket_test.rb:47]:
--- expected
+++ actual
@@ -1 +1 @@
-["foo"]
+["Broken pipe", "Broken pipe", "Broken pipe", "foo"]
```

It can be reproduced easily by applying the following patch:

```
diff --git a/actioncable/test/connection/client_socket_test.rb b/actioncable/test/connection/client_socket_test.rb
index 2051216010..6bb9f13ea7 100644
--- a/actioncable/test/connection/client_socket_test.rb
+++ b/actioncable/test/connection/client_socket_test.rb
@@ -34,7 +34,8 @@ def on_error(message)
     @server.config.allowed_request_origins = %w( http://rubyonrails.com )
   end

-  test "delegate socket errors to on_error handler" do
+  1000.times do |i|
+  test "delegate socket errors to on_error handler #{i}" do
     run_in_eventmachine do
       connection = open_connection

@@ -47,6 +48,7 @@ def on_error(message)
       assert_equal %w[ foo ], connection.errors
     end
   end
+  end

   test "closes hijacked i/o socket at shutdown" do
     run_in_eventmachine do
```

The cause is writing io from different thread at the same time.

`connection.process` sends handshake message from [StreamEventLoop's thread][] whereas
`connection.handle_open` sends welcome message from current thread.

[StreamEventLoop's thread]: 067fc779c4/actioncable/lib/action_cable/connection/stream_event_loop.rb (L75)
2017-11-23 14:37:06 +09:00
Rafael Mendonça França
8dd76a7a6f
Use .tt extension to all the template files
Make clear that the files are not to be run for interpreters.

Fixes #23847.
Fixes #30690.
Closes #23878.
2017-11-13 15:23:28 -05:00
Jeremy Daer
8f2490b57f Action Cable: run Redis tests against a default config without a password
Simplify our dev testing and CI story since we're also testing against
Redis for the Active Support cache store.

Directly test whether db, host, password, etc are passed through as
config instead of spinning up a Redis server with a password set on it.
2017-11-13 01:34:59 -07:00
Ryuta Kamizono
146b1c2e33 Enable Style/RedundantReturn rubocop rule, and fixed a couple more
Follow up of #31004.
2017-11-01 07:32:04 +09:00
प्रथमेश Sonpatki
55fdb125db Remove CHANGELOG entry that was backported to Rails 5.1.3. [ci skip] (#30986)
- Backport commit: 7122a2cdc3
2017-10-25 22:56:38 +05:30
Rafael Mendonça França
48766e32d3
Removed deprected evented redis adapter 2017-10-23 12:50:45 -04:00
Akira Matsuda
40a8db6329 [Action Cable] require_relative => require
This basically reverts f851e1f705f26d8f92f0fc1b265b20bc389d23cb
2017-10-21 22:48:29 +09:00
Jeremy Daer
5fb282239d Merge pull request #30748 from jeremy/redis-rb-4.0.1
redis-rb 4.0 support
2017-10-08 16:14:55 -07:00
Jeremy Daer
53c516d88d
redis-rb 4.0 support
* Use `gem 'redis', '~> 4.0'` for new app Gemfiles
* Loosen Action Cable redis-rb dep to `>= 3.3, < 5`
* Bump redis-namespace for looser Redis version dep
* Avoid using the underlying `redis.client` directly
* Use `Redis.new` instead of `Redis.connect`
2017-10-08 15:37:54 -07:00
Jeremy Daer
55a2c101b2
Distinguish missing adapter gems from load errors within the adapter
* When the adapter is missing, raise an exception that points out config
  typos and missing Gemfile entries. (We can assume that a non-builtin
  adapter was used since these are always available.)
* When loading an adapter raises a LoadError, prefix its error message
  to indicate that the adapter is likely missing an optional dependency.
2017-10-08 14:47:51 -07:00
Richard Machielse
4b629eca21
ActionCable: use find method when unsubscribing
If a frontend for some reason tries to unsubscribe from a non existing subscription, the following error is logged:

Could not execute command from ({"command"=>"unsubscribe", "identifier"=>"{\"channel\":\"SomeChannel\"}"}) [NoMethodError - undefined method `unsubscribe_from_channel' for nil:NilClass]

Instead, it will now properly log:

Could not execute command from ({"command"=>"unsubscribe", "identifier"=>"{\"channel\":\"SomeChannel\"}"}) [RuntimeError - Unable to find subscription with identifier: {"channel":"SomeChannel"}]
2017-09-26 11:47:55 +02:00
Yauheni Dakuka
c9527652c7 Fix quotes [ci skip] 2017-09-18 09:38:47 +03:00
Matthew Draper
2e6658ae51 Clarify intentions around method redefinitions
Don't use remove_method or remove_possible_method just before a new
definition: at best the purpose is unclear, and at worst it creates a
race condition.

Instead, prefer redefine_method when practical, and
silence_redefinition_of_method otherwise.
2017-09-01 14:27:13 +09:30
Yoshiyuki Hirano
5eb831d3f2 Use typewriter in doc for Action Cable [ci skip] 2017-08-26 07:56:46 +09:00
Yoshiyuki Hirano
3a11e0586e Update MIT licenses link [ci skip] 2017-08-22 08:46:02 +09:00
Matthew Draper
1da7fa8728 Attributes are protected, not private, to avoid the warning 2017-08-20 01:07:05 +09:30
Jon Moss
f84019cd63 Capitalize Redis
[ci skip]
2017-08-17 10:55:10 -04:00
Koichi ITO
7c260ae201 Fix RuboCop offenses
And enable `context_dependent` of Style/BracesAroundHashParameters cop.
2017-08-16 17:55:25 +09:00
Ryuta Kamizono
67f1b51f85 Remove unused close_connection in Action Cable tests (#30195) 2017-08-11 14:09:53 -04:00
Claudio B
af954ddd54 [ci skip] Prefer cookies.encrypted over signed (#30129)
In some examples and guides we are recommending to use code like:

```ruby
verified_user = User.find_by(id: cookies.signed[:user_id])
```

My suggestion is to use instead:

```ruby
verified_user = User.find_by(id: cookies.encrypted[:user_id])
```

which invites users to prefer the "newer" encrypted cookies over the
"legacy" signed cookies.
2017-08-07 22:32:03 -05:00
Jon Moss
5e222f3d91 Lint actioncable/CHANGELOG.md
Postgres --> PostgreSQL
ActionCable --> Action Cable

[ci skip]
2017-08-06 22:14:10 -04:00
Kir Shatrov
385825fb70 Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
Kir Shatrov
87bf94d1ce Make actioncable ready for frozen strings 2017-07-23 23:20:40 +03:00
palkan
be806d8696 Fix postgresql adapter setup for ActionCable tests
(cherry picked from commit e2093c1f678175bde7c37c848686d979427346e1)
(cherry picked from commit d7dbe48273bd9e0adb1de5b52e3cdaeb4a65630b)
2017-07-11 16:38:30 +03:00
palkan
2bce7777b7 [Fix #28751] Hash stream long stream identifiers when using Postgres adapter 2017-07-06 17:34:05 +03:00
Xavier Noria
92c29d82eb Merge branch 'master' into require_relative_2017 2017-07-02 13:50:25 -07:00
Ryuta Kamizono
6aa658e329 Remove redundant assert_respond_to
It is covered by following assertion.
2017-07-03 00:16:53 +09:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Akira Matsuda
f851e1f705 [Action Cable] require => require_relative 2017-07-01 18:38:05 +09:00
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Rafael França
cf8c46938b Merge pull request #29588 from greysteil/add-gemspec-links
Add source code and changelog links to gemspecs
2017-06-28 11:24:02 -04:00
Grey Baker
3e6ce1cd69 Add source code and changelog links to gemspecs 2017-06-28 10:06:01 +01:00
Marc Rendl Ignacio
d7252786f4 Adds CHANGELOG for f55ecc6 [ci skip] 2017-06-27 09:34:37 +08:00
Marc Ignacio
f55ecc6a7c Allows for other common redis options to be in cable.yml, by default
- Adds RedisAdapterTest::AlternateConfiguration to account
  for a relatively common alternative setup, as it’s used
  as the first example in the
  [Redis rubygem](https://github.com/redis/redis-rb#getting-started)

- Supplies original RedisAdapterTest with more complete
  redis:// url format by adding a ‘userinfo’ (blank user),
  so that it resembles the alternate configuration

- Supplies original EventedRedisAdapterTest with more complete
  redis:// url as well

- Adds before_script to start redis-server with password as a daemon
  and with explicit defaults copied from the default redis.conf
  (Instead of using Travis' default init/upstart scripts for `redis` service)
2017-06-22 16:15:47 +08:00
T.J. Schuck
2f8dc184fc nodoc AC::Connection::WebSocket
Users should never publicly be interacting with an instance of this.  The instance that comes along with an `AC::Connection::Base` instance (the only thing a user should be working with) is [itself intended to be private](https://github.com/tjschuck/rails/blob/master/actioncable/lib/action_cable/connection/base.rb#L137-L140).

[ci skip]
2017-06-16 18:36:04 -04:00
bogdanvlviv
6673cf7071
Use require_relative instead of require with full path 2017-06-14 12:10:17 +03:00
Genadi Samokovarov
b6b0c99ff3 Use mattr_accessor default: option throughout the project 2017-06-03 13:52:48 +03:00
David Heinemeier Hansson
1c275d812f Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute

* Convert to using class_attribute default rather than explicit setter

* Removed instance_accessor option by mistake

* False is a valid default value

* Documentation
2017-05-29 18:01:50 +02:00
bogdanvlviv
40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df003a96f0e490c43559747618d10f5f
2017-05-23 00:53:51 +03:00
Akira Matsuda
f31ad74f7b identifiers is already defined via Connection::Identification module 2017-05-21 12:37:18 +09:00
Koichi ITO
89e097fa46 Suppress warning: assigned but unused variable - stdout 2017-05-12 15:37:42 +09:00
Ryuta Kamizono
89389428b5 Cleanup CHANGELOGs [ci skip]
* Remove trailing spaces.
* Add backticks around method and command.
* Fix indentation.
2017-04-30 02:41:44 +09:00
edwardmp
fc416d3721 Log any errors originating from the socket 2017-04-16 20:14:28 +02:00
Matthew Draper
fd097cff79 Work around all the things 2017-04-06 07:19:58 +09:30
Matthew Draper
c866cf9df8 Avoid "can't modify frozen IOError" failures
https://bugs.ruby-lang.org/issues/13239
2017-04-05 06:27:52 +09:30
Jon Moss
686f6a762f Action Cable owns database connection, not Active Record
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]
2017-03-25 12:44:20 -04:00
Ryuta Kamizono
bdbee0b8e5 Rename local variable name current_user to verified_user [ci skip]
Assigning local variable named `current_user` in the condition is
confusing.
2017-03-25 20:48:34 +09:00
Kasper Timm Hansen
b242796765 Revert "Merge pull request #28569 from HarryCollins/patch-1"
This reverts commit 296d024b4e91c4891ae0b010249193513e63b921, reversing
changes made to e341d835070c7ef9990f41e02bbf46536be0aee7.

We aren't trying to compare to current_user, we're assigning that variable.
2017-03-25 12:40:53 +01:00
HarryCollins
591891e51e Update Action Cable README.md - typo fix 2017-03-25 10:45:31 +00:00
T.J. Schuck
11a09dbe53 Document AC::Connection::Authorization#reject_unauthorized_connection
This method is repeatedly used throughout the docs (in the [AC::Connection docs](12b6849858/actioncable/lib/action_cable/connection/base.rb (L28)), the [AC README](12b6849858/actioncable/README.md (a-full-stack-example)), the [AC Guides](12b6849858/guides/source/action_cable_overview.md (connection-setup))), but not actually documented itself and seemingly not supported for public use based on its current `private` status.

This actually makes the method public and documents it.  The actual behavior that’s documented here is implemented [here](12b6849858/actioncable/lib/action_cable/connection/base.rb (L213-L219)), via [this rescuing of the UnauthorizedError](3dd1de8ba4/actioncable/lib/action_cable/connection/base.rb (L172)).

The method is [already tested here](25473baf40/actioncable/test/connection/authorization_test.rb (L17-L29)).
2017-03-22 19:30:49 -04:00
Matthew Draper
62a8e838e0 Fix a race in ActionCable stream tests
These tests double-stub connection.pubsub, so we need to ensure the
first call's completed before we set up for the second.
2017-03-23 05:52:38 +10:30
Matthew Draper
6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
Javan Makhmali
2d2b3025ec Restore action_cable.js UMD module support. Fixes #28366 2017-03-11 16:12:36 -05:00
Rafael Mendonça França
8bb0b99a4a
Update package.json 2017-02-23 15:03:20 -05:00
Rafael Mendonça França
f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
Matthew Draper
3721b859b6 Deprecate the EventedRedis subscription adapter
Unlike Faye support, it seems a bit too documented to remove without
warning. So, here's a warning.
2017-02-23 10:48:30 +10:30
Martijn Storck
963572b2a4 Move some ActionCable logs to debug level 2017-02-06 12:05:54 +01:00
Akira Matsuda
c684f4f3da bin/test for Active Job and Action Cable tests
According to the commit comment on 54d84cbb77a7fbc6359eda4eb40cc7da29c426e1, AJ/bin/test was intentionally not added,
but AJ tests doesn't actually do anything special other than specifying ENV['AJ_ADAPTER'],
which can be easily done via command line environment variable.
2017-02-02 16:27:42 +09:00
yuuji.yaginuma
c42bd31977 correctly check error message
`assert_raise` does not check error message. However, in some tests,
it seems like expecting error message checking with `assert_raise`.
Instead of specifying an error message in `assert_raise`, modify to use
another assert to check the error message.
2017-01-25 09:58:15 +09:00
Chad Ingram
36a80b41dc Add changelog entry for #27425 [ci skip] 2017-01-21 22:04:03 -05:00
Chad Ingram
a9c4dcee8d Add channel_prefix support to ActionCable redis/evented_redis adapters. 2017-01-17 23:21:39 -05:00
Eugene
39c739161d Fix missing bracket.
Fix missing left bracket in exception message.
2017-01-14 01:52:27 +03:00
Akira Matsuda
b70fc698e1 Reduce string objects by using \ instead of + or << for concatenating strings
(I personally prefer writing one string in one line no matter how long it is, though)
2017-01-12 17:45:37 +09:00
Duncan Grazier
23e3e2bc2b ActionCable should not raise when a connection is already open
ActionCable was throwing a "Existing connection must be closed before
opening" exception which was being picked up as a production issue in
our error monitoring software. Since this happens pretty often on any
device that allows the browser to sleep (mobile) this error was getting
triggered often.

This change removes the exception, but keeps logging the occurrence. We
now return `false` to let the caller now that `open` failed.
2017-01-06 12:49:58 -05:00
Akira Matsuda
5473e390d3 self. is not needed when calling its own instance method
Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
2017-01-05 19:58:52 +09:00
Rafael França
a27c040cc3 Merge pull request #25626 from maclover7/jm-standardize-ac-readme
Standardize Action Cable README.md
2017-01-03 19:35:39 -05:00
Jon Moss
37d956f45f Bump license years for 2017
Per https://www.timeanddate.com/counters/firstnewyear.html, it's already
2017 in a lot of places, so we should bump the Rails license years to
2017.

[ci skip]
2016-12-31 08:34:08 -05:00
Tony Arcieri
c434b97628 Upgrade to nio4r 2.0.0
nio4r 2.0.0 primarily includes new features and bugfixes, with few breaking
changes. The primary reason for bumping the major version is dropping support
for all Ruby versions prior to 2.2.2, so as to match Rails 5.

Full release announcement here:

https://groups.google.com/forum/#!topic/socketry/ZDIUj1ufiJ8
2016-12-28 19:45:39 -08:00
Jon Moss
d99c772da0 Small edits to actioncable/CHANGELOG.md
[ci skip]

- capitalize WebSocket
2016-12-27 08:41:28 -05:00
Akira Matsuda
91fa2b71c3 Privatize unneededly protected methods in Action Cable 2016-12-24 22:16:43 +09:00
Akira Matsuda
79c17a2d91 Privatize unneededly protected methods in Action Cable tests 2016-12-24 00:15:24 +09:00
Akira Matsuda
21e5fd4a2a Describe what we are protecting 2016-12-23 23:48:54 +09:00
Carlos Eduardo Monti
2b39b5bfa1 Fix typo in channel generator usage message 2016-12-19 12:31:42 -03:00
MSP-Greg
7257306623 ActionCable::Connection::Base doc code sample syntax error 2016-12-06 10:35:36 -06:00
Matthew Draper
162e889f16 Prevent race condition when launching EventMachine reactor
reactor_running? will be true just after the thread enters
EventMachine.run; reactor_thread only gets set after the internal
initialize_event_machine method has been called, the C extension is set
up, and it is entering its run loop.
2016-11-30 22:55:04 +10:30
Javan Makhmali
7083fa27a4 Add more Action Cable JavaScript tests 2016-11-21 09:50:00 -05:00
yuuji.yaginuma
7c7f4f96df use correct value in example [ci skip]
Need to specify `reload` from turbolinks 5.
Ref: 7225f0bb9fd1d71a7a37b53815c90178cc7319bd
2016-11-14 09:45:28 +09:00
Vipul A M
7e7d6ccf34
Changelog edits 2016-11-12 13:14:49 -05:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Charles Oliver Nutter
51de32b2ec Lazy-load blade for actioncable tests; no blade on JRuby. 2016-10-21 17:19:44 -05:00
Matthew Draper
dae4044734 Permit same-origin connections by default
WebSocket always defers the decision to the server, because it didn't
have to deal with legacy compatibility... but the same-origin policy is
still a reasonable default.

Origin checks do not protect against a directly connecting attacker --
they can lie about their host, but can also lie about their origin.
Origin checks protect against a connection from 3rd-party controlled
script in a context where a victim browser's cookies will be passed
along. And if an attacker has breached that protection, they've already
compromised the HTTP session, so treating the WebSocket connection in
the same way seems reasonable.

In case this logic proves incorrect (or anyone just wants to be more
paranoid), we retain a config option to disable it.
2016-10-11 12:51:10 +10:30
Matthew Draper
f8c53eff7b Merge pull request #26568 from skateman/cable-sameorigin-as-host
Optionally allow ActionCable requests from the same host as origin
2016-10-11 12:28:38 +10:30
Matthew Draper
3a11c5b626 Merge pull request #26714 from matthewd/close-race
Work around read/close race (x2)
2016-10-07 04:30:08 +10:30
Matthew Draper
1fe967d0c9 Wait for the socket to be closed asynchronously 2016-10-06 13:12:35 +10:30
Matthew Draper
acd7ba795e Use a branch of websocket-client-simple, to work around read/close race 2016-10-06 12:51:26 +10:30
Matthew Draper
4a7c5685c8 Close the IO from the read loop thread
IO#close and IO#read across threads don't get along so well:

After T1 enters #read and releases the GVL, T2 can call #close on the
IO, thereby both closing the fd and freeing the buffer while T1 is using
them.
2016-10-06 10:31:14 +10:30
kenta-s
a0f871f95a Change page:change to turbolinks:load in README.md [ci skip] 2016-10-05 19:41:27 +09:00
Matthew Draper
39fb3069f8 Don't shut down adapters that haven't been set
We hit when we skip the PostgreSQL adapter.
2016-10-04 06:40:38 +10:30
Matthew Draper
a92fa72600 Shut down the worker pool - don't kill it
Different parts of concurrent-ruby's documentation make inconsistent
claims about how kill will behave. It doesn't do the thing we want.
2016-10-03 05:38:25 +10:30
Jon Moss
d1cc11a360 Add tests for Server::Base#restart 2016-10-02 09:02:01 -04:00
Jon Moss
35a497dc29 Move behavior to Server::Base, and flush pubsub 2016-10-02 08:45:38 -04:00
Jon Moss
a5dfba4135 Shutdown pubsub connection before classes are reloaded
Before this patch, if you were to make a file edit in your Rails
application and you tried to load up the page, it would hang
indefinitely. The issue is that Active Record is trying to cleanup after
itself and clear all active connection, but Action Cable is still
holding onto a connection from the pool. To resolve this, we are now
shutting down the pubsub adapter before classes are reloaded, to avoid
this altogether (connection is being returned to the pool).

Credits to @skateman for discovering this bug. :)
2016-10-02 08:45:38 -04:00
Matthew Draper
7c812c2401 Use websocket-client-simple instead of Faye as a websockets client
Mostly, this is just to avoid EventMachine. But there's also an argument
to be made that we're better off using a different protocol library for
our test suite than the one we use to implement the server.
2016-10-02 12:25:33 +10:30
Matthew Draper
a5abc310cd Shut down EventMachine before re-enabling warnings 2016-10-02 12:25:33 +10:30
Matthew Draper
3e779d3c67 In-line the configuration points that only existed for Faye support 2016-10-01 15:36:26 +09:30
Matthew Draper
d44177d45e Remove Faye mode
No deprecation, because it was never documented.
2016-10-01 15:35:59 +09:30
Matthew Draper
9588a3d66d Merge pull request #26547 from palkan/fix/actioncable-confirmation-race-condition
Avoid race condition on subscription confirmation
2016-10-01 15:18:39 +09:30
Matthew Draper
5d92089bca Buffer writes to the cable sockets
Otherwise, they can sometimes block, leading to reduced system
throughput.
2016-09-28 06:44:23 +09:30
palkan
3e68d8b872 Add Channel#ensure_confirmation_sent; call #subscribe_to_channel after initializing 2016-09-22 20:25:09 +03:00
Dávid Halász
268c340b09 Optionally allow ActionCable requests from the same host as origin
When the `allow_same_origin_as_host` is set to `true`, the request
forgery protection permits `HTTP_ORIGIN` values starting with the
corresponding `proto://` prefix followed by `HTTP_HOST`. This way
it is not required to specify the list of allowed URLs.
2016-09-21 16:10:46 +02:00
palkan
03a209e92a [Fix #25381] Avoid race condition on subscription confirmation 2016-09-20 19:42:24 +03:00
Prathamesh Sonpatki
f838c213be
[ci skip] Fix formatting of documentation of worker_pool method from AC::Server::Base 2016-09-07 12:05:36 +05:30
Prathamesh Sonpatki
0c9ef8d943
[ci skip] Fix formatting in Action Cable Connection::Base module docs 2016-09-07 08:04:52 +05:30
Prathamesh Sonpatki
c683ac4fe0
[ci fix] Fix API documentation for Streams module from Action Cable 2016-09-06 23:10:15 +05:30
Xavier Noria
bb1ecdcc67 fixes remaining RuboCop issues [Vipul A M, Xavier Noria] 2016-09-01 23:41:49 +02:00
Jon Moss
831e2c8d1b Prevent invocation of channel action if rejected connection
Fixes #23757.

Before this commit, even if `reject` was called in the `subscribe`
method for an Action Cable channel, all actions on that channel could
still be invoked. This calls a `return` if a rejected connection tries
to invoke any actions on the channel.
2016-08-19 13:00:39 -04:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Vipul A M
8b984161d6
Pass over changelogs [ci skip] 2016-08-10 09:33:13 +05:30
Xavier Noria
46f511685c revises more Lint/EndAlignment offenses 2016-08-08 18:25:11 +02:00
Xavier Noria
cf082927ef copy-edits an exception message
Inserted spaces in the name of Rails components.

Since I was on it, also used PostgreSQL instead of Postgres
because albeit Postgres is an accepted alias, PostgreSQL is
the official name and the actual name of the adapter.

See

    https://wiki.postgresql.org/wiki/ProjectName

with regard to PostgreSQL vs Postgres.
2016-08-07 22:58:20 +02:00