提交 61366f5a 编写于 作者: R Ryo Hashimoto

Action Cable channel generator should not create JS assets in --api mode

上级 914a45b5
......@@ -9,7 +9,9 @@ class ChannelGenerator < NamedBase
def create_channel_file
template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb")
template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
if Rails::Generators.options[:rails][:assets]
template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
end
end
protected
......
require 'generators/generators_test_helper'
require 'rails/generators/channel/channel_generator'
class ChannelGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
tests Rails::Generators::ChannelGenerator
def test_channel_is_created
run_generator ['chat']
assert_file "app/channels/chat_channel.rb" do |channel|
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)
end
end
def test_channel_asset_is_not_created
Rails::Generators.options[:rails][:assets] = false
run_generator ['chat']
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"
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册