From f51a30c66692a5da2d5152d5e7e6130d88480c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 21 Dec 2015 18:58:08 -0200 Subject: Use the generators options to not generate channel assets --- actioncable/lib/rails/generators/channel/channel_generator.rb | 5 ++++- railties/test/generators/channel_generator_test.rb | 8 ++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb index 925dd3d098..c5d398810a 100644 --- a/actioncable/lib/rails/generators/channel/channel_generator.rb +++ b/actioncable/lib/rails/generators/channel/channel_generator.rb @@ -5,11 +5,14 @@ module Rails argument :actions, type: :array, default: [], banner: "method method" + class_option :assets, type: :boolean + check_class_collision suffix: "Channel" def create_channel_file template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb") - if Rails::Generators.options[:rails][:assets] + + if options[:assets] template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee") end end diff --git a/railties/test/generators/channel_generator_test.rb b/railties/test/generators/channel_generator_test.rb index f58ff83ac9..c1f0c03fbf 100644 --- a/railties/test/generators/channel_generator_test.rb +++ b/railties/test/generators/channel_generator_test.rb @@ -17,17 +17,13 @@ class ChannelGeneratorTest < Rails::Generators::TestCase end end - def test_channel_asset_is_not_created - enable_assets = Rails::Generators.options[:rails][:assets] - Rails::Generators.options[:rails][:assets] = false - run_generator ['chat'] + def test_channel_asset_is_not_created_when_skip_assets_is_passed + run_generator ['chat', '--skip-assets'] assert_file "app/channels/chat_channel.rb" do |channel| assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) end assert_no_file "app/assets/javascripts/channels/chat.coffee" - ensure - Rails::Generators.options[:rails][:assets] = enable_assets end end -- cgit v1.2.3