2015-12-18 23:43:11 -05:00
|
|
|
require 'generators/generators_test_helper'
|
|
|
|
require 'rails/generators/channel/channel_generator'
|
|
|
|
|
|
|
|
class ChannelGeneratorTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
|
|
|
tests Rails::Generators::ChannelGenerator
|
|
|
|
|
2016-02-10 17:36:11 -05:00
|
|
|
def test_application_cable_skeleton_is_created
|
|
|
|
run_generator ['books']
|
|
|
|
|
|
|
|
assert_file "app/channels/application_cable/channel.rb" do |cable|
|
|
|
|
assert_match(/module ApplicationCable\n class Channel < ActionCable::Channel::Base\n/, cable)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_file "app/channels/application_cable/connection.rb" do |cable|
|
|
|
|
assert_match(/module ApplicationCable\n class Connection < ActionCable::Connection::Base\n/, cable)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-18 23:43:11 -05:00
|
|
|
def test_channel_is_created
|
|
|
|
run_generator ['chat']
|
2015-12-21 11:44:47 -05:00
|
|
|
|
2015-12-18 23:43:11 -05:00
|
|
|
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
|
|
|
|
|
2015-12-21 15:58:08 -05:00
|
|
|
def test_channel_asset_is_not_created_when_skip_assets_is_passed
|
|
|
|
run_generator ['chat', '--skip-assets']
|
2015-12-18 23:43:11 -05:00
|
|
|
|
|
|
|
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
|