# Unit testing ActionCable

**URL:** <https://discuss.rubyonrails.org/t/unit-testing-actioncable/72265>\
**Category:** rubyonrails-core\
**Created:** [November 22, 2016, 5:13pm UTC](https://discuss.rubyonrails.org/t/unit-testing-actioncable/72265 "2016-11-22T17:13:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Snitko](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roman\_Snitko](https://discuss.rubyonrails.org/u/Roman_Snitko)\
**Post date:** [November 22, 2016, 5:13pm UTC](https://discuss.rubyonrails.org/t/unit-testing-actioncable/72265/1 "2016-11-22T17:13:04Z")

</div>

It seems there currently is no easy (or hard even) way to unit test ActionCable channels, which makes me very sad. There is a bit of logic in my Channels which would be very nice to cover with tests. Ideally, I’d like to have something like this:

```
it "rejects connection if current_user isn't the owner of the contract" do

  channel = create_channel(:contract)

  sign_in @unauthorized_user

  expect(channel.subscribe(params: {contract_id: 1}).to reject_connection

end

```

Is this something even remotely likely to happen? I googled very hard and I also checked every ActionCable issue (opened & closed) and couldn’t find anyone asking this question.

---

<div class="post-metadata">

**Author:** ![rafaelfranca](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rafaelfranca/32/616_2.png) [@rafaelfranca](https://discuss.rubyonrails.org/u/rafaelfranca)\
**Post date:** [November 22, 2016, 7:05pm UTC](https://discuss.rubyonrails.org/t/unit-testing-actioncable/72265/2 "2016-11-22T19:05:31Z")

</div>

[https://github.com/rails/rails/pull/23211](https://github.com/rails/rails/pull/23211)
