2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
2017-06-11 08:59:23 -04:00
|
|
|
require_relative "common"
|
|
|
|
require_relative "channel_prefix"
|
2016-01-24 05:43:40 -05:00
|
|
|
|
2017-11-13 02:55:06 -05:00
|
|
|
require "action_cable/subscription_adapter/redis"
|
|
|
|
|
2016-01-24 05:43:40 -05:00
|
|
|
class RedisAdapterTest < ActionCable::TestCase
|
|
|
|
include CommonSubscriptionAdapterTest
|
2017-01-17 23:20:36 -05:00
|
|
|
include ChannelPrefixTest
|
2016-01-24 05:43:40 -05:00
|
|
|
|
|
|
|
def cable_config
|
2019-02-05 09:50:06 -05:00
|
|
|
{ adapter: "redis", driver: "ruby" }.tap do |x|
|
|
|
|
if host = URI(ENV["REDIS_URL"] || "").hostname
|
|
|
|
x[:host] = host
|
|
|
|
end
|
|
|
|
end
|
2016-01-31 10:00:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RedisAdapterTest::Hiredis < RedisAdapterTest
|
|
|
|
def cable_config
|
2016-08-06 13:15:15 -04:00
|
|
|
super.merge(driver: "hiredis")
|
2016-01-24 05:43:40 -05:00
|
|
|
end
|
|
|
|
end
|
2017-06-21 21:10:08 -04:00
|
|
|
|
|
|
|
class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
|
|
|
def cable_config
|
|
|
|
alt_cable_config = super.dup
|
|
|
|
alt_cable_config.delete(:url)
|
2019-02-05 09:50:06 -05:00
|
|
|
alt_cable_config.merge(host: URI(ENV["REDIS_URL"] || "").hostname || "127.0.0.1", port: 6379, db: 12)
|
2017-11-13 02:55:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-08 16:19:39 -04:00
|
|
|
class RedisAdapterTest::Connector < ActionCable::TestCase
|
2019-04-22 09:59:53 -04:00
|
|
|
test "excludes adapter and channel prefix" do
|
2018-09-05 09:54:44 -04:00
|
|
|
config = { url: 1, host: 2, port: 3, db: 4, password: 5, id: "Some custom ID" }
|
2017-11-13 02:55:06 -05:00
|
|
|
|
|
|
|
assert_called_with ::Redis, :new, [ config ] do
|
2019-04-22 09:59:53 -04:00
|
|
|
connect config.merge(adapter: "redis", channel_prefix: "custom")
|
2017-11-13 02:55:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-05 09:54:44 -04:00
|
|
|
test "adds default id if it is not specified" do
|
2018-09-06 15:00:00 -04:00
|
|
|
config = { url: 1, host: 2, port: 3, db: 4, password: 5, id: "ActionCable-PID-#{$$}" }
|
2018-09-05 09:54:44 -04:00
|
|
|
|
|
|
|
assert_called_with ::Redis, :new, [ config ] do
|
2018-09-06 15:00:00 -04:00
|
|
|
connect config.except(:id)
|
2018-09-05 09:54:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-13 02:55:06 -05:00
|
|
|
def connect(config)
|
|
|
|
ActionCable::SubscriptionAdapter::Redis.redis_connector.call(config)
|
2017-06-21 21:10:08 -04:00
|
|
|
end
|
|
|
|
end
|