Remove channels from default app/ structure (#52344)

* Remove channels from default app/ structure

Now that Hotwire is the default, the majority of apps won't need custom
channels. And those that do can get the files back via the generator.

* Remove trailing space

* Remove additional needless elements

* No longer to be generated

* No longer generated
This commit is contained in:
David Heinemeier Hansson 2024-07-16 16:55:00 +02:00 committed by GitHub
parent f805b35c1b
commit 3ce3a4e94c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 3 additions and 38 deletions

@ -183,7 +183,8 @@ unsubscribing, or performing an action:
A *channel* encapsulates a logical unit of work, similar to what a controller does in a A *channel* encapsulates a logical unit of work, similar to what a controller does in a
typical MVC setup. By default, Rails creates a parent `ApplicationCable::Channel` class typical MVC setup. By default, Rails creates a parent `ApplicationCable::Channel` class
(which extends [`ActionCable::Channel::Base`][]) for encapsulating shared logic between your channels. (which extends [`ActionCable::Channel::Base`][]) for encapsulating shared logic between your channels,
when you use the channel generator for the first time.
#### Parent Channel Setup #### Parent Channel Setup
@ -195,8 +196,7 @@ module ApplicationCable
end end
``` ```
Then you would create your own channel classes. For example, you could have a Your own channel classes could then look like these examples:
`ChatChannel` and an `AppearanceChannel`:
```ruby ```ruby
# app/channels/chat_channel.rb # app/channels/chat_channel.rb

@ -244,7 +244,6 @@ def test
empty_directory_with_keep_file "test/helpers" empty_directory_with_keep_file "test/helpers"
empty_directory_with_keep_file "test/integration" empty_directory_with_keep_file "test/integration"
template "test/channels/application_cable/connection_test.rb"
template "test/test_helper.rb" template "test/test_helper.rb"
end end
@ -546,8 +545,6 @@ def delete_action_mailer_files_skipping_action_mailer
def delete_action_cable_files_skipping_action_cable def delete_action_cable_files_skipping_action_cable
if options[:skip_action_cable] if options[:skip_action_cable]
remove_dir "app/javascript/channels" remove_dir "app/javascript/channels"
remove_dir "app/channels"
remove_dir "test/channels"
end end
end end

@ -1,4 +0,0 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end

@ -1,4 +0,0 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end

@ -1,13 +0,0 @@
require "test_helper"
module ApplicationCable
class ConnectionTest < ActionCable::Connection::TestCase
# test "connects with cookies" do
# cookies.signed[:user_id] = 42
#
# connect
#
# assert_equal connection.user_id, "42"
# end
end
end

@ -71,7 +71,6 @@ def test_generator_if_skip_action_cable_is_given
run_generator [destination_root, "--api", "--skip-action-cable"] run_generator [destination_root, "--api", "--skip-action-cable"]
assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/
assert_no_file "config/cable.yml" assert_no_file "config/cable.yml"
assert_no_file "app/channels"
assert_file "Gemfile" do |content| assert_file "Gemfile" do |content|
assert_no_match(/"redis"/, content) assert_no_match(/"redis"/, content)
end end
@ -136,7 +135,6 @@ def default_files
Rakefile Rakefile
Dockerfile Dockerfile
config.ru config.ru
app/channels
app/controllers app/controllers
app/mailers app/mailers
app/models app/models

@ -19,8 +19,6 @@
Rakefile Rakefile
app/assets/images/.keep app/assets/images/.keep
app/assets/stylesheets/application.css app/assets/stylesheets/application.css
app/channels/application_cable/channel.rb
app/channels/application_cable/connection.rb
app/controllers/application_controller.rb app/controllers/application_controller.rb
app/controllers/concerns/.keep app/controllers/concerns/.keep
app/helpers/application_helper.rb app/helpers/application_helper.rb
@ -72,7 +70,6 @@
script/.keep script/.keep
storage/.keep storage/.keep
test/application_system_test_case.rb test/application_system_test_case.rb
test/channels/application_cable/connection_test.rb
test/controllers/.keep test/controllers/.keep
test/fixtures/files/.keep test/fixtures/files/.keep
test/helpers/.keep test/helpers/.keep
@ -244,7 +241,6 @@ def test_app_update_does_not_generate_action_cable_contents_when_skip_action_cab
assert_file "config/environments/production.rb" do |content| assert_file "config/environments/production.rb" do |content|
assert_no_match(/config\.action_cable/, content) assert_no_match(/config\.action_cable/, content)
end end
assert_no_file "test/channels/application_cable/connection_test.rb"
end end
def test_app_update_does_not_generate_bootsnap_contents_when_skip_bootsnap_is_given def test_app_update_does_not_generate_bootsnap_contents_when_skip_bootsnap_is_given

@ -27,8 +27,6 @@
test/dummy/Rakefile test/dummy/Rakefile
test/dummy/app/assets/images/.keep test/dummy/app/assets/images/.keep
test/dummy/app/assets/stylesheets/application.css test/dummy/app/assets/stylesheets/application.css
test/dummy/app/channels/application_cable/channel.rb
test/dummy/app/channels/application_cable/connection.rb
test/dummy/app/controllers/application_controller.rb test/dummy/app/controllers/application_controller.rb
test/dummy/app/controllers/concerns/.keep test/dummy/app/controllers/concerns/.keep
test/dummy/app/helpers/application_helper.rb test/dummy/app/helpers/application_helper.rb

@ -334,9 +334,6 @@ def test_generator_if_skip_action_cable_is_given
run_generator [destination_root, "--skip-action-cable", "--webpack"] run_generator [destination_root, "--skip-action-cable", "--webpack"]
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_cable\/engine["']/
assert_no_file "#{application_path}/config/cable.yml" assert_no_file "#{application_path}/config/cable.yml"
assert_no_file "#{application_path}/app/javascript/consumer.js"
assert_no_directory "#{application_path}/app/javascript/channels"
assert_no_directory "#{application_path}/app/channels"
assert_file "Gemfile" do |content| assert_file "Gemfile" do |content|
assert_no_match(/"redis"/, content) assert_no_match(/"redis"/, content)
end end