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/subscription_adapter/base_test.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

require 'test_helper'
require 'stubs/test_server'
class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
## TEST THAT ERRORS ARE RETURNED FOR INHERITORS THAT DON'T OVERRIDE METHODS
class BrokenAdapter < ActionCable::SubscriptionAdapter::Base
end
setup do
@server = TestServer.new
@server.config.subscription_adapter = BrokenAdapter
@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')
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' }
assert_raises NotImplementedError do
2016-01-15 17:11:30 -05:00
BrokenAdapter.new(@server).subscribe('channel', callback, success_callback)
end
end
2016-01-15 17:11:30 -05:00
test "#unsubscribe returns NotImplementedError by default" do
callback = lambda { puts 'callback' }
2016-01-15 17:11:30 -05:00
assert_raises NotImplementedError do
BrokenAdapter.new(@server).unsubscribe('channel', callback)
end
2016-01-15 17:11:30 -05:00
end
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-15 17:11:30 -05:00
assert_respond_to(SuccessAdapter.new(@server), :broadcast)
assert_nothing_raised do
2016-01-15 17:11:30 -05:00
broadcast
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)
assert_nothing_raised do
2016-01-15 17:11:30 -05:00
subscribe
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-15 17:11:30 -05:00
assert_respond_to(SuccessAdapter.new(@server), :unsubscribe)
assert_nothing_raised do
2016-01-15 17:11:30 -05:00
unsubscribe
end
end
end