Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop_stream_from causes undefined method 'pubsub' #2493

Open
ghost opened this issue Apr 12, 2021 · 3 comments
Open

stop_stream_from causes undefined method 'pubsub' #2493

ghost opened this issue Apr 12, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 12, 2021

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.7.2
Rails version: 6.1.3.1
RSpec version: 3.10

Observed behaviour

Full write-up in Rails repo under issue rails/rails#41077

@pirj
Copy link
Member

pirj commented Apr 13, 2021

Have you had a chance to investigate the root cause, @jasonatball ?
A pull request is welcome.

@ghost
Copy link
Author

ghost commented Apr 13, 2021

Reproduceable on rails 6.1.3.1. Reproduction steps:

Install rails, rails new blog. Update Gemfile to add rspec-rails to test group:

group :test do
  gem 'rspec-rails', "~> 4.0.0"

Install rspec: rails generate rspec:install

Add following method to app/channels/application_cable/channel.rb:

module ApplicationCable
  class Channel < ActionCable::Channel::Base
    def subscribed
      stream_from uuid
      stop_stream_from uuid # This causes the error
    end
  end
end

Create following spec/channels/channel_spec.rb

require "rails_helper"
RSpec.describe ApplicationCable::Channel, :type => :channel do
  it "subscribes" do
    stub_connection uuid: '12345'
    subscribe()
  end
end

Run spec: rspec spec\channels\channel_spec.rb

Observe error:

Failures:

  1) ApplicationCable::Channel subscribes
     Failure/Error: stop_stream_from uuid

     NoMethodError:
       undefined method `pubsub' for #<ActionCable::Channel::ConnectionStub:0x000000000bd0d8a0>
     # ./app/channels/application_cable/channel.rb:5:in `subscribed'
     # ./spec/channels/channel_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.04651 seconds (files took 10.52 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/channels/channel_spec.rb:4 # ApplicationCable::Channel subscribes

Fix issue by adding code to channel_spec.rb:

module ActionCable
  module Channel
    class ConnectionStub
      def pubsub
        ActionCable.server.pubsub
      end
    end
  end
end

@ghost
Copy link
Author

ghost commented Apr 13, 2021

Not sure if always defering to ActionCable.server.pubsub via ConnectionStub pubsub is the correct solution but this worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant