1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/test/worker_test.rb

47 lines
1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "test_helper"
2015-07-14 11:58:46 -04:00
class WorkerTest < ActionCable::TestCase
2015-07-14 11:58:46 -04:00
class Receiver
attr_accessor :last_action
def run
@last_action = :run
end
def process(message)
@last_action = [ :process, message ]
2015-07-14 11:58:46 -04:00
end
2015-10-15 22:11:49 -04:00
def connection
2016-01-24 05:43:40 -05:00
self
end
def logger
# Impersonating a connection requires a TaggedLoggerProxy'ied logger.
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
2015-10-15 22:11:49 -04:00
end
2015-07-14 11:58:46 -04:00
end
setup do
@worker = ActionCable::Server::Worker.new
@receiver = Receiver.new
end
teardown do
@receiver.last_action = nil
end
test "invoke" do
@worker.invoke @receiver, :run, connection: @receiver.connection
2015-07-14 11:58:46 -04:00
assert_equal :run, @receiver.last_action
end
test "invoke with arguments" do
@worker.invoke @receiver, :process, "Hello", connection: @receiver.connection
2015-07-14 11:58:46 -04:00
assert_equal [ :process, "Hello" ], @receiver.last_action
end
end