2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
2018-05-27 14:50:04 -04:00
|
|
|
require "minitest/mock"
|
2016-08-06 13:15:15 -04:00
|
|
|
require "stubs/test_connection"
|
|
|
|
require "stubs/room"
|
2015-10-20 18:17:18 -04:00
|
|
|
|
2018-06-08 16:19:39 -04:00
|
|
|
class ActionCable::Channel::RejectionTest < ActionCable::TestCase
|
2015-10-20 18:17:18 -04:00
|
|
|
class SecretChannel < ActionCable::Channel::Base
|
|
|
|
def subscribed
|
2015-11-05 10:37:15 -05:00
|
|
|
reject if params[:id] > 0
|
2015-10-20 18:17:18 -04:00
|
|
|
end
|
2016-02-18 12:31:04 -05:00
|
|
|
|
|
|
|
def secret_action
|
|
|
|
end
|
2015-10-20 18:17:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@user = User.new "lifo"
|
|
|
|
@connection = TestConnection.new(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "subscription rejection" do
|
2018-05-27 14:50:04 -04:00
|
|
|
subscriptions = Minitest::Mock.new
|
|
|
|
subscriptions.expect(:remove_subscription, SecretChannel, [SecretChannel])
|
2015-10-20 18:17:18 -04:00
|
|
|
|
2018-05-27 14:50:04 -04:00
|
|
|
@connection.stub(:subscriptions, subscriptions) do
|
|
|
|
@channel = SecretChannel.new @connection, "{id: 1}", id: 1
|
|
|
|
@channel.subscribe_to_channel
|
|
|
|
|
|
|
|
expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
|
|
|
|
assert_equal expected, @connection.last_transmission
|
|
|
|
end
|
|
|
|
|
|
|
|
assert subscriptions.verify
|
2015-10-20 18:17:18 -04:00
|
|
|
end
|
2016-02-18 12:31:04 -05:00
|
|
|
|
|
|
|
test "does not execute action if subscription is rejected" do
|
2018-05-27 14:50:04 -04:00
|
|
|
subscriptions = Minitest::Mock.new
|
|
|
|
subscriptions.expect(:remove_subscription, SecretChannel, [SecretChannel])
|
2016-02-18 12:31:04 -05:00
|
|
|
|
2018-05-27 14:50:04 -04:00
|
|
|
@connection.stub(:subscriptions, subscriptions) do
|
|
|
|
@channel = SecretChannel.new @connection, "{id: 1}", id: 1
|
|
|
|
@channel.subscribe_to_channel
|
|
|
|
|
|
|
|
expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
|
|
|
|
assert_equal expected, @connection.last_transmission
|
|
|
|
assert_equal 1, @connection.transmissions.size
|
|
|
|
|
|
|
|
@channel.perform_action("action" => :secret_action)
|
|
|
|
assert_equal 1, @connection.transmissions.size
|
|
|
|
end
|
2016-02-18 12:31:04 -05:00
|
|
|
|
2018-05-27 14:50:04 -04:00
|
|
|
assert subscriptions.verify
|
2016-02-18 12:31:04 -05:00
|
|
|
end
|
2015-10-20 18:17:18 -04:00
|
|
|
end
|