aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/subscription_adapter/channel_prefix.rb
blob: 3071facd9dde9502cde351387d9950cfa14a7462 (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
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require "test_helper"

class ActionCable::Server::WithIndependentConfig < ActionCable::Server::Base
  # ActionCable::Server::Base defines config as a class variable.
  # Need config to be an instance variable here as we're testing 2 separate configs
  def config
    @config ||= ActionCable::Server::Configuration.new
  end
end

module ChannelPrefixTest
  def test_channel_prefix
    server2 = ActionCable::Server::WithIndependentConfig.new
    server2.config.cable = alt_cable_config
    server2.config.logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }

    adapter_klass = server2.config.pubsub_adapter

    rx_adapter2 = adapter_klass.new(server2)
    tx_adapter2 = adapter_klass.new(server2)

    subscribe_as_queue("channel") do |queue|
      subscribe_as_queue("channel", rx_adapter2) do |queue2|
        @tx_adapter.broadcast("channel", "hello world")
        tx_adapter2.broadcast("channel", "hello world 2")

        assert_equal "hello world", queue.pop
        assert_equal "hello world 2", queue2.pop
      end
    end
  end

  def alt_cable_config
    cable_config.merge(channel_prefix: "foo")
  end
end