Use the generators options to not generate channel assets

This commit is contained in:
Rafael Mendonça França 2015-12-21 18:58:08 -02:00
parent daa890331e
commit f51a30c666
2 changed files with 6 additions and 7 deletions

@ -5,11 +5,14 @@ class ChannelGenerator < NamedBase
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

@ -17,17 +17,13 @@ def test_channel_is_created
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