2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
|
|
|
require "stubs/test_server"
|
2016-01-06 17:16:02 -05:00
|
|
|
|
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-08-06 13:15:15 -04: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
|
2016-08-06 13:15:15 -04:00
|
|
|
callback = lambda { puts "callback" }
|
|
|
|
success_callback = lambda { puts "success" }
|
2016-01-15 17:11:30 -05:00
|
|
|
|
2016-01-06 17:16:02 -05:00
|
|
|
assert_raises NotImplementedError do
|
2016-08-06 13:15:15 -04: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
|
2016-08-06 13:15:15 -04:00
|
|
|
callback = lambda { puts "callback" }
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-01-15 17:11:30 -05:00
|
|
|
assert_raises NotImplementedError do
|
2016-08-06 13:15:15 -04:00
|
|
|
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
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2017-07-02 11:16:53 -04:00
|
|
|
SuccessAdapter.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 is implemented" do
|
2016-08-06 13:15:15 -04:00
|
|
|
callback = lambda { puts "callback" }
|
|
|
|
success_callback = lambda { puts "success" }
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2017-07-02 11:16:53 -04:00
|
|
|
SuccessAdapter.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 is implemented" do
|
2016-08-06 13:15:15 -04:00
|
|
|
callback = lambda { puts "callback" }
|
2016-01-06 17:16:02 -05:00
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised do
|
2017-07-02 11:16:53 -04:00
|
|
|
SuccessAdapter.new(@server).unsubscribe("channel", callback)
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
|
|
|
end
|