Sha256: 242612038a2004bc33a7b078c4ef6aa4800709bd76823a3b80a73ac21c2dc4bf

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

module WebsocketRails
  describe Channel do
    subject { Channel.new :awesome_channel }

    let(:connection) { double('connection') }

    before do
      connection.stub!(:trigger)
    end

    it "should maintain a pool of subscribed connections" do
      subject.subscribers.should == []
    end

    describe "#subscribe" do
      it "should add the connection to the subscriber pool" do
        subject.subscribe connection
        subject.subscribers.include?(connection).should be_true
      end
    end

    describe "#trigger" do
      it "should create a new event and trigger it on all subscribers" do
        event = double('event').as_null_object
        Event.should_receive(:new) do |name,options|
          name.should == 'event'
          options[:data].should == 'data'
          event
        end
        connection.should_receive(:trigger).with(event)
        subject.subscribe connection
        subject.trigger 'event', 'data'
      end
    end

    describe "#trigger_event" do
      it "should forward the event to the subscribers" do
        subject.should_receive(:send_data).with('event')
        subject.trigger_event 'event'
      end
    end

    context "private channels" do
      it "should be public by default" do
        subject.instance_variable_get(:@private).should_not be_true
      end

      describe "#make_private" do
        it "should set the @private instance variable to true" do
          subject.make_private
          subject.instance_variable_get(:@private).should be_true
        end
      end

      describe "#is_private?" do
        it "should return true if the channel is private" do
          subject.instance_variable_set(:@private,true)
          subject.is_private?.should be_true
        end

        it "should return false if the channel is public" do
          subject.instance_variable_set(:@private,false)
          subject.is_private?.should_not be_true
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
websocket-rails-0.3.0 spec/unit/channel_spec.rb
websocket-rails-0.2.1 spec/unit/channel_spec.rb
websocket-rails-0.2.0 spec/unit/channel_spec.rb
websocket-rails-0.1.9 spec/unit/channel_spec.rb