aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/channel/rejection_test.rb
blob: 15db57d6ba5be2d5673218f2b67929a068e8c322 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'test_helper'
require 'stubs/test_connection'
require 'stubs/room'

class ActionCable::Channel::RejectionTest < ActiveSupport::TestCase
  class SecretChannel < ActionCable::Channel::Base
    def subscribed
      reject if params[:id] > 0
    end
  end

  setup do
    @user = User.new "lifo"
    @connection = TestConnection.new(@user)
  end

  test "subscription rejection" do
    @connection.expects(:subscriptions).returns mock().tap { |m| m.expects(:remove_subscription).with instance_of(SecretChannel) }
    @channel = SecretChannel.new @connection, "{id: 1}", { id: 1 }

    expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
    assert_equal expected, @connection.last_transmission
  end

end