aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable
diff options
context:
space:
mode:
authorVladimir Dementyev <dementiev.vm@gmail.com>2019-01-13 21:54:31 -0500
committerVladimir Dementyev <dementiev.vm@gmail.com>2019-01-13 21:54:31 -0500
commit0f41aa30d30afff051e68afe67c53b626d5b05c0 (patch)
treeb08adc9c77b37ebae0772568a30ee1a0d6ccde8b /actioncable
parent3631d7eee4bd034f2eefe1b9892d5fcd565579ac (diff)
downloadrails-0f41aa30d30afff051e68afe67c53b626d5b05c0.tar.gz
rails-0f41aa30d30afff051e68afe67c53b626d5b05c0.tar.bz2
rails-0f41aa30d30afff051e68afe67c53b626d5b05c0.zip
Add channel test generator
Diffstat (limited to 'actioncable')
-rw-r--r--actioncable/lib/rails/generators/channel/USAGE3
-rw-r--r--actioncable/lib/rails/generators/channel/channel_generator.rb2
-rw-r--r--actioncable/lib/rails/generators/test_unit/channel_generator.rb20
-rw-r--r--actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt10
4 files changed, 34 insertions, 1 deletions
diff --git a/actioncable/lib/rails/generators/channel/USAGE b/actioncable/lib/rails/generators/channel/USAGE
index ea9662436c..bb5dd7e2db 100644
--- a/actioncable/lib/rails/generators/channel/USAGE
+++ b/actioncable/lib/rails/generators/channel/USAGE
@@ -7,6 +7,7 @@ Example:
========
rails generate channel Chat speak
- creates a Chat channel class and JavaScript asset:
+ creates a Chat channel class, test and JavaScript asset:
Channel: app/channels/chat_channel.rb
+ Test: test/channels/chat_channel_test.rb
Assets: app/javascript/channels/chat_channel.js
diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb
index ef51981e89..0b80d1f96b 100644
--- a/actioncable/lib/rails/generators/channel/channel_generator.rb
+++ b/actioncable/lib/rails/generators/channel/channel_generator.rb
@@ -11,6 +11,8 @@ module Rails
check_class_collision suffix: "Channel"
+ hook_for :test_framework
+
def create_channel_file
template "channel.rb", File.join("app/channels", class_path, "#{file_name}_channel.rb")
diff --git a/actioncable/lib/rails/generators/test_unit/channel_generator.rb b/actioncable/lib/rails/generators/test_unit/channel_generator.rb
new file mode 100644
index 0000000000..7d13a12f0a
--- /dev/null
+++ b/actioncable/lib/rails/generators/test_unit/channel_generator.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module TestUnit
+ module Generators
+ class ChannelGenerator < ::Rails::Generators::NamedBase
+ source_root File.expand_path("templates", __dir__)
+
+ check_class_collision suffix: "ChannelTest"
+
+ def create_test_files
+ template "channel_test.rb", File.join("test/channels", class_path, "#{file_name}_channel_test.rb")
+ end
+
+ private
+ def file_name # :doc:
+ @_file_name ||= super.sub(/_channel\z/i, "")
+ end
+ end
+ end
+end
diff --git a/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt b/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt
new file mode 100644
index 0000000000..301dc0b6fe
--- /dev/null
+++ b/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+require "test_helper"
+
+class <%= class_name %>ChannelTest < ActionCable::Channel::TestCase
+ # test "subscribes" do
+ # subscribe
+ # assert subscription.confirmed?
+ # end
+end