aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/channel_generator_test.rb
blob: 5cc1cd83b124bff83a1974d7c8d8398393c5c3af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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