Commit Graph

299 Commits

Author SHA1 Message Date
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
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05: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
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
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
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
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
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
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
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
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
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
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
Ilia Kasianenko
bcd11e07b5 ActionCable: add id option to redis adapter config 2018-09-05 16:54:44 +03:00
bogdanvlviv
86e7de7968
DRY in assert_broadcasts
Test `assert_no_broadcasts` failure
2018-08-23 12:39:03 +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
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
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