2016-01-06 17:16:02 -05:00
|
|
|
require 'test_helper'
|
|
|
|
require 'stubs/test_server'
|
|
|
|
|
2016-01-15 19:07:18 -05:00
|
|
|
class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
|
2016-01-06 17:16:02 -05:00
|
|
|
## TEST THAT ERRORS ARE RETURNED FOR INHERITORS THAT DON'T OVERRIDE METHODS
|
|
|
|
|
2016-01-15 19:07:18 -05:00
|
|
|
class BrokenAdapter < ActionCable::SubscriptionAdapter::Base
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@server = TestServer.new
|
2016-01-15 19:07:18 -05:00
|
|
|
@server.config.subscription_adapter = BrokenAdapter
|
2016-01-06 17:16:02 -05:00
|
|
|
@server.config.allowed_request_origins = %w( http://rubyonrails.com )
|
|
|
|
end
|
|
|
|
|
|
|
|
test "#broadcast returns NotImplementedError by default" do
|
|
|
|
assert_raises NotImplementedError do
|
2016-01-15 17:11:30 -05:00
|
|
|
BrokenAdapter.new(@server).broadcast('channel', 'payload')
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
test "#subscribe returns NotImplementedError by default" do
|
|
|
|
callback = lambda { puts 'callback' }
|
|
|
|
success_callback = lambda { puts 'success' }
|
|
|
|
|
2016-01-06 17:16:02 -05:00
|
|
|
assert_raises NotImplementedError do
|
2016-01-15 17:11:30 -05:00
|
|
|
BrokenAdapter.new(@server).subscribe('channel', callback, success_callback)
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
test "#unsubscribe returns NotImplementedError by default" do
|
|
|
|
callback = lambda { puts 'callback' }
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
assert_raises NotImplementedError do
|
|
|
|
BrokenAdapter.new(@server).unsubscribe('channel', callback)
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
# TEST METHODS THAT ARE REQUIRED OF THE ADAPTER'S BACKEND STORAGE OBJECT
|
|
|
|
|
|
|
|
test "#broadcast is implemented" do
|
|
|
|
broadcast = SuccessAdapter.new(@server).broadcast('channel', 'payload')
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
assert_respond_to(SuccessAdapter.new(@server), :broadcast)
|
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2016-01-15 17:11:30 -05:00
|
|
|
broadcast
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
test "#subscribe is implemented" do
|
|
|
|
callback = lambda { puts 'callback' }
|
|
|
|
success_callback = lambda { puts 'success' }
|
|
|
|
subscribe = SuccessAdapter.new(@server).subscribe('channel', callback, success_callback)
|
|
|
|
|
|
|
|
assert_respond_to(SuccessAdapter.new(@server), :subscribe)
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2016-01-15 17:11:30 -05:00
|
|
|
subscribe
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
test "#unsubscribe is implemented" do
|
|
|
|
callback = lambda { puts 'callback' }
|
|
|
|
unsubscribe = SuccessAdapter.new(@server).unsubscribe('channel', callback)
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
assert_respond_to(SuccessAdapter.new(@server), :unsubscribe)
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2016-01-15 17:11:30 -05:00
|
|
|
unsubscribe
|
|
|
|
end
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|