Commit Graph

612 Commits

Author SHA1 Message Date
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
Ryuta Kamizono
762e3f05f3 Add Style/EmptyLines in .rubocop.yml and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria
b326e82dc0 applies remaining conventions across the project 2016-08-06 20:20:22 +02:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
411ccbdab2 remove redundant curlies from hash arguments 2016-08-06 19:44:11 +02:00
Xavier Noria
12a70404cd modernizes hash syntax in actioncable 2016-08-06 19:32:32 +02:00
Xavier Noria
e6ab70c439 applies new string literal convention to the rest of the project
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:28:46 +02:00
Xavier Noria
adca8154c6 applies new string literal convention in the gemspecs
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:27:12 +02:00
Xavier Noria
f8477f13bf applies new string literal convention in actioncable/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:15:15 +02:00
Xavier Noria
b678eb57e9 applies new string literal convention in actioncable/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:13:46 +02:00
Santosh Wadghule
e73b5cf51b Give importance to rails command in the comment section. 2016-07-13 19:13:05 +05:30
Matthew Draper
48e8056d4f Correct changelog layout
[ci skip]
2016-07-09 03:17:51 +09:30
Matthew Draper
e995611155 Insert changelog entry for #25615 2016-07-09 02:56:03 +09:30
Matthew Draper
92421ee2d2 Merge pull request #25624 from tinco/actioncable_write_race
Fix race condition in websocket stream write
2016-07-09 02:44:15 +09:30
Matthew Draper
08a9074613 Merge pull request #24988 from mwear/action_cable_broadcast_notifications
Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast
2016-07-04 08:44:14 +09:30
Matthew Draper
550303c05c Merge pull request #25030 from mmmpa/pull_request
ActionCable, sometimes add_channel is not called.
2016-07-04 08:39:02 +09:30
Matthew Draper
a468774cc1 Merge pull request #25293 from y-yagi/remove_needless_comments
remove needless comments
2016-07-03 04:08:30 +09:30
Jon Moss
eff98450ff Standardize Action Cable README.md
All other Rails components feature this section, Action Cable should
have it as well.

[ci skip]
2016-07-02 12:13:33 -04:00
Tinco Andringa
3120b51de7 close hijacked i/o socket after use (fixes #25613) 2016-07-01 23:03:30 +02:00
Tinco Andringa
ce5f9bb2a5 fix race condition in websocket stream write 2016-07-01 15:29:29 +02:00
Jeremy Daer
ba9571e1ac
Periodic timers: delegate async instance_exec to the worker pool 2016-06-29 23:37:07 -07:00
Vipul A M
e5c5b6f2ee Merge pull request #24991 from maclover7/actioncable-npm-docs
Add documentation about Action Cable npm package
2016-06-29 15:29:59 -07:00
Kasper Timm Hansen
754e5bdf87 Make client test run individually.
Require our dependency and forgo the core ext version.
2016-06-28 18:54:30 +02:00
Rafael Mendonça França
e78e0e2a42
Fix Action Cable README [ci skip] 2016-06-26 16:09:36 -03:00
Ryuta Kamizono
e317e5e1e1 Remove conflict line [ci skip] 2016-06-27 02:52:39 +09:00
Vijay Dev
5343626ea8 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	actioncable/README.md
2016-06-26 16:34:23 +00:00
Gaurav Sharma
4db92eed3b client test have not using Pathname and hashwithindifferent access 2016-06-26 01:49:54 +05:30
Michael Dever
0a8584456e Allow actioncable connections from any port in development 2016-06-16 21:04:43 +01:00
Vipul A M
b94b04b1d1
Fix and make example generic in README as well [ci skip] 2016-06-15 22:04:56 -07:00
yuuji.yaginuma
8a5f17e55a remove needless comments
Follow up to #25240.
2016-06-06 15:09:06 +09:00
Prathamesh Sonpatki
7d4b33257b
Added "Download and Installation" section to Action Cable README [ci skip]
- Only Action Cable README did not have this section, all of the other
  READMEs have this section.
2016-06-04 16:06:35 -04:00
Prathamesh Sonpatki
4c192a7fad
Trim Action Cable README [ci skip]
- Remove "Configuration", "Running the server", "Dependencies" and "Deployment"
  sections from the Action Cable README as they are already duplicated in the
  Action Cable overview guide.
2016-06-04 16:01:30 -04:00
Matthew Draper
a8df1bc345 Properly support reloading for Action Cable channels 2016-06-02 04:08:48 +09:30
Jeremy Daer
8932c1b9a4
Merge pull request #25170 from maclover7/add-configuration-cable
[Action Cable] Add `WebSocket` and `logger` configuration options
2016-05-31 11:19:29 -07:00
Javan Makhmali
410a32ffbd Add helper for testing against a mock WebSocket and server 2016-05-31 13:06:11 -04:00
Jon Moss
fb0f0c7f6e Reorganize MockWebSocket 2016-05-31 13:06:11 -04:00
Jon Moss
66901c1849 Add configuration for WebSocket and logger
[Javan Makhmali, Jon Moss]
2016-05-31 13:06:08 -04:00
Jeremy Daer
0419e1b6f3
Merge pull request #25216 from javan/actioncable/tune-sauce-labs-tests
Action Cable: Tune Sauce Labs tests
2016-05-31 08:57:19 -07:00
Javan Makhmali
a051e59fb9 Test single latest browser version
Cuts down the number of concurrent Sauce Labs VMs we need to spin up. Can add specific versions back in to target regressions if need be.
2016-05-31 10:42:18 -04:00
Rajat Bansal
72a0f5e24c fix grammar 2016-05-31 13:31:18 +05:30
Anubhav Saxena
5983226161 Bash markdown syntax
Added 'sh' for markdown formatting as bash.
2016-05-27 08:58:55 +05:30
Jon Moss
1713075a80 Add documentation about Action Cable npm package
Sorry, forgot to include in my main PR :(

[ci skip]

[Jon Moss, Zach Schneider]
2016-05-26 22:22:04 -04:00
mmmpa
711d232f93 Add guard to broadcast. 2016-05-26 05:22:56 +09:00
Jon Moss
8cfce058d9
CI: run Action Cable browser tests in Sauce Labs
Allow failures until test runs are consistently stable, not hanging.

Closes #24943.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-05-25 09:21:28 -07:00
Javan Makhmali
d12209cad2 Remove package:clean task
Introduced in d6f2000a67cc63aa67414c75ce77de671824ec52 and was only used by Action Cable. Now handled by Action Cable’s assets:compile task.
2016-05-24 13:11:28 -04:00
Javan Makhmali
11078dddbb Build action_cable.js with Blade 2016-05-24 13:11:10 -04:00
Vipul A M
61483b18bc
Remove Blade gem dependency
Apps that depend on Action Cable don't need Blade for app development,
so we can remove the gem dependency.

We do need Blade for Action Cable dev, so we bundle it in the Gemfile.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-05-21 12:41:01 -07:00
Sean Griffin
26c0e2cab4 Merge pull request #25076 from jeroenvisser101/keep-to-max-length
Change comments to not exceed 80 characters
2016-05-21 14:56:03 -04:00
Jon Moss
c420bedda7 Pass over Action Cable docs
[ci skip]
2016-05-21 11:55:04 -04:00
Rafael França
db312a9fb0 Merge pull request #24918 from prathamesh-sonpatki/cable-assets
Cable: Generate .js or .coffee files while generating channel as per the javascript engine of the application
2016-05-21 08:52:43 -03:00
Jeroen Visser
ee25897230
Change comments to not exceed 80 characters
Other generated files do keep to this, but action cable doesn't.
2016-05-19 15:37:50 +02:00
Roman Pushkin
a3c4d035f0 Improve method description
Method description improved to reflect little bit more complicated scenario when names are camel-cased.
2016-05-18 14:12:11 -07:00
Prathamesh Sonpatki
63ac6255ba
Cable: Generate .js or .coffee files while generating channel as per the javascript engine of the application
- Now we will detect what javascript engine user is using and based on
  that we will generate either `.js` or `.coffee` version of the channel
  file.
- This also needs a change in coffee-rails to override the `js_template`
  method. Related PR https://github.com/rails/coffee-rails/pull/72.
- Currently coffee-rails gem sets
  `config.app_generators.javascript_engine` to `:coffee` and using this
  information we override the `js_template` to set the extension as
  `.coffee` in coffee-rails gem.
- Using this approach, we can keep the `channel.js` and `channel.coffee`
  files in the Rails repository itself.
- Additionally the `js_template` method can act as public interface for
  coffee-rails gem to hook into and change the extension to `.coffee`
  without maintaining the actual asset files.

[Prathamesh Sonpatki, Matthew Draper]
2016-05-17 18:12:19 +05:30
Vijay Dev
83ecf3fe56 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/configuring.md
2016-05-14 09:54:23 +00:00
Matthew Wear
f3ba0c1dd3 Add ActiveSupport::Notifications hook to Broadcaster#broadcast
This addition of this notification hook will give users better visibility
into the messages being sent over the PubSub adapter.
2016-05-12 10:56:35 -07:00