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

53 lines
1 KiB
Ruby
Raw Normal View History

2015-07-14 11:58:46 -04:00
require 'test_helper'
class WorkerTest < ActiveSupport::TestCase
class Receiver
attr_accessor :last_action
def run
@last_action = :run
end
def process(message)
@last_action = [ :process, message ]
end
2015-10-15 22:11:49 -04:00
def connection
2016-01-24 05:43:40 -05:00
self
end
def logger
ActionCable.server.logger
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
assert_equal :run, @receiver.last_action
end
test "invoke with arguments" do
@worker.invoke @receiver, :process, "Hello"
assert_equal [ :process, "Hello" ], @receiver.last_action
end
test "running periodic timers with a proc" do
@worker.run_periodic_timer @receiver, @receiver.method(:run)
assert_equal :run, @receiver.last_action
end
test "running periodic timers with a method" do
@worker.run_periodic_timer @receiver, :run
assert_equal :run, @receiver.last_action
end
end