diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 08:52:43 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 08:52:43 -0300 |
commit | db312a9fb04097e7d584d24dd446aac7dea7e11f (patch) | |
tree | eba6c8973aa6046188b2c38e7ac811d833501138 /railties | |
parent | 7087ff99071cd29f1d07e5298dbc204bede6ca86 (diff) | |
parent | 63ac6255ba3553b529f4b23846ec756b7a7a746d (diff) | |
download | rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.gz rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.bz2 rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.zip |
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
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/named_base.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/channel_generator_test.rb | 24 |
2 files changed, 24 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index efbf51ddfb..ee076eb711 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -26,6 +26,10 @@ module Rails super end end + + def js_template(source, destination) + template(source + '.js', destination + '.js') + end end protected diff --git a/railties/test/generators/channel_generator_test.rb b/railties/test/generators/channel_generator_test.rb index d58b54ac24..e3edde681f 100644 --- a/railties/test/generators/channel_generator_test.rb +++ b/railties/test/generators/channel_generator_test.rb @@ -24,8 +24,24 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) end - assert_file "app/assets/javascripts/channels/chat.coffee" do |channel| - assert_match(/App.cable.subscriptions.create "ChatChannel"/, channel) + assert_file "app/assets/javascripts/channels/chat.js" do |channel| + assert_match(/App.chat = App.cable.subscriptions.create\("ChatChannel/, channel) + end + end + + def test_channel_with_multiple_actions_is_created + run_generator ['chat', 'speak', 'mute'] + + assert_file "app/channels/chat_channel.rb" do |channel| + assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) + assert_match(/def speak/, channel) + assert_match(/def mute/, channel) + end + + assert_file "app/assets/javascripts/channels/chat.js" do |channel| + assert_match(/App.chat = App.cable.subscriptions.create\("ChatChannel/, channel) + assert_match(/,\n\n speak/, channel) + assert_match(/,\n\n mute: function\(\) \{\n return this\.perform\('mute'\);\n \}\n\}\);/, channel) end end @@ -36,7 +52,7 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) end - assert_no_file "app/assets/javascripts/channels/chat.coffee" + assert_no_file "app/assets/javascripts/channels/chat.js" end def test_cable_js_is_created_if_not_present_already @@ -52,7 +68,7 @@ class ChannelGeneratorTest < Rails::Generators::TestCase run_generator ['chat'], behavior: :revoke assert_no_file "app/channels/chat_channel.rb" - assert_no_file "app/assets/javascripts/channels/chat.coffee" + assert_no_file "app/assets/javascripts/channels/chat.js" assert_file "app/channels/application_cable/channel.rb" assert_file "app/channels/application_cable/connection.rb" |