Skip to content

Commit

Permalink
Merge bb4e068 into 1d338df
Browse files Browse the repository at this point in the history
  • Loading branch information
mthorn committed Feb 20, 2014
2 parents 1d338df + bb4e068 commit b07f00c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/pusher-fake/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def process(data)
message = MultiJson.load(data, symbolize_keys: true)
data = message[:data]
event = message[:event]
channel = Channel.factory(message[:channel] || data.delete(:channel))
name = message[:channel] || data.delete(:channel)
channel = Channel.factory(name) if name

case event
when "pusher:subscribe"
channel.add(self, data)
when "pusher:unsubscribe"
channel.remove(self)
when "pusher:ping"
emit("pusher:pong")
when CLIENT_EVENT_MATCHER
if channel.is_a?(Channel::Private) && channel.includes?(self)
channel.emit(event, data, socket_id: socket.object_id)
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/pusher-fake/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@
end
end

describe PusherFake::Connection, "#process, with a ping event" do
let(:json) { stub }
let(:message) { { event: "pusher:ping", data: {} } }

subject { PusherFake::Connection.new(stub) }

before do
MultiJson.stubs(load: message)
PusherFake::Channel.stubs(:factory)
subject.stubs(:emit)
end

it "parses the JSON data" do
subject.process(json)

expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
end

it "creates no channels" do
subject.process(json)

expect(PusherFake::Channel).to have_received(:factory).never
end

it "emits a pong event" do
subject.process(json)

expect(subject).to have_received(:emit).with("pusher:pong")
end
end

describe PusherFake::Connection, "#process, with a client event" do
let(:data) { {} }
let(:json) { stub }
Expand Down

0 comments on commit b07f00c

Please sign in to comment.