aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/subscription_adapter/redis_test.rb
blob: 63823d6ef0b5fff5a4a5cc4c98f5c09c3318de33 (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
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require "test_helper"
require_relative "common"
require_relative "channel_prefix"

require "active_support/testing/method_call_assertions"
require "action_cable/subscription_adapter/redis"

class RedisAdapterTest < ActionCable::TestCase
  include CommonSubscriptionAdapterTest
  include ChannelPrefixTest

  def cable_config
    { adapter: "redis", driver: "ruby" }
  end
end

class RedisAdapterTest::Hiredis < RedisAdapterTest
  def cable_config
    super.merge(driver: "hiredis")
  end
end

class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
  def cable_config
    alt_cable_config = super.dup
    alt_cable_config.delete(:url)
    alt_cable_config.merge(host: "127.0.0.1", port: 6379, db: 12)
  end
end

class RedisAdapterTest::Connector < ActiveSupport::TestCase
  include ActiveSupport::Testing::MethodCallAssertions

  test "slices url, host, port, db, and password from config" do
    config = { url: 1, host: 2, port: 3, db: 4, password: 5 }

    assert_called_with ::Redis, :new, [ config ] do
      connect config.merge(other: "unrelated", stuff: "here")
    end
  end

  def connect(config)
    ActionCable::SubscriptionAdapter::Redis.redis_connector.call(config)
  end
end