pusher-fake 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,7 +49,7 @@ Feature: Triggering events on a channel
49
49
  Given I am subscribed to the "private-chat" channel
50
50
  And Bob is subscribed to the "private-chat" channel
51
51
  When I trigger the "client-message" event on the "private-chat" channel
52
- Then I should receive a "client-message" event on the "private-chat" channel
52
+ Then I should not receive a "client-message" event on the "private-chat" channel
53
53
  And Bob should receive a "client-message" event on the "private-chat" channel
54
54
 
55
55
  Scenario: Client triggers a client event on a previously subscribed private channel
@@ -82,3 +82,10 @@ Feature: Triggering events on a channel
82
82
  | private-chat-2 |
83
83
  Then I should receive a "message" event on the "private-chat-1" channel
84
84
  And Bob should receive a "message" event on the "private-chat-2" channel
85
+
86
+ Scenario: Server triggers an event and excludes a client by socket ID
87
+ Given I am subscribed to the "chat" channel
88
+ And Bob is subscribed to the "chat" channel
89
+ When a "message" event is triggered on the "chat" channel, ignoring Bob
90
+ Then I should receive a "message" event on the "chat" channel
91
+ And Bob should not receive a "message" event on the "chat" channel
@@ -2,6 +2,17 @@ When %{a "$event" event is triggered on the "$channel" channel} do |event, chann
2
2
  Pusher.trigger(channel, event, {})
3
3
  end
4
4
 
5
+ When %{a "$event" event is triggered on the "$channel" channel, ignoring $name} do |event, channel, name|
6
+ name = nil if name == "me"
7
+ socket_id = nil
8
+
9
+ using_session(name) do
10
+ socket_id = page.evaluate_script("Pusher.instance.connection.socket_id")
11
+ end
12
+
13
+ Pusher.trigger(channel, event, {}, socket_id: socket_id)
14
+ end
15
+
5
16
  When %{a "$event" event is triggered on the following channels:} do |event, table|
6
17
  channels = table.hashes.collect { |hash| hash["name"] }
7
18
 
@@ -16,7 +16,7 @@ require "pusher-fake/webhook"
16
16
 
17
17
  module PusherFake
18
18
  # The current version string.
19
- VERSION = "0.3.0"
19
+ VERSION = "0.4.0"
20
20
 
21
21
  # Call this method to modify the defaults.
22
22
  #
@@ -27,8 +27,10 @@ module PusherFake
27
27
  #
28
28
  # @param [String] event The event name.
29
29
  # @param [Hash] data The event data.
30
- def emit(event, data)
30
+ def emit(event, data, options = {})
31
31
  connections.each do |connection|
32
+ next if connection.socket.object_id == options[:socket_id]
33
+
32
34
  connection.emit(event, data, name)
33
35
  end
34
36
  end
@@ -47,7 +47,7 @@ module PusherFake
47
47
  return unless channel.is_a?(Channel::Private)
48
48
  return unless channel.includes?(self)
49
49
 
50
- channel.emit(event, data)
50
+ channel.emit(event, data, socket_id: socket.object_id)
51
51
  end
52
52
  end
53
53
  end
@@ -11,7 +11,7 @@ module PusherFake
11
11
  event = MultiJson.load(request.body.read)
12
12
 
13
13
  event["channels"].each do |channel|
14
- Channel.factory(channel).emit(event["name"], event["data"])
14
+ Channel.factory(channel).emit(event["name"], event["data"], socket_id: event["socket_id"])
15
15
  end
16
16
 
17
17
  Rack::Response.new("{}").finish
@@ -52,9 +52,11 @@ describe PusherFake::Channel, "#emit" do
52
52
  let(:data) { stub }
53
53
  let(:name) { "name" }
54
54
  let(:event) { "event" }
55
+ let(:socket_1) { stub }
56
+ let(:socket_2) { stub }
55
57
  let(:connections) { [connection_1, connection_2] }
56
- let(:connection_1) { stub(emit: nil) }
57
- let(:connection_2) { stub(emit: nil) }
58
+ let(:connection_1) { stub(emit: nil, socket: socket_1) }
59
+ let(:connection_2) { stub(emit: nil, socket: socket_2) }
58
60
 
59
61
  subject { PusherFake::Channel::Public.new(name) }
60
62
 
@@ -67,6 +69,12 @@ describe PusherFake::Channel, "#emit" do
67
69
  connection_1.should have_received(:emit).with(event, data, name)
68
70
  connection_2.should have_received(:emit).with(event, data, name)
69
71
  end
72
+
73
+ it "ignores connection if socket_id matches the connections socket object_id" do
74
+ subject.emit(event, data, socket_id: socket_2.object_id)
75
+ connection_1.should have_received(:emit).with(event, data, name)
76
+ connection_2.should have_received(:emit).never
77
+ end
70
78
  end
71
79
 
72
80
  describe PusherFake::Channel, "#includes?" do
@@ -145,7 +145,7 @@ describe PusherFake::Connection, "#process, with a client event" do
145
145
  it "emits the event to the channel when the connection is in the channel" do
146
146
  channel.stubs(includes?: true)
147
147
  subject.process(json)
148
- channel.should have_received(:emit).with(event, data)
148
+ channel.should have_received(:emit).with(event, data, socket_id: subject.socket.object_id)
149
149
  end
150
150
 
151
151
  it "does not emit the event to the channel when the channel is not private" do
@@ -5,12 +5,13 @@ describe PusherFake::Server::Application, ".call" do
5
5
  let(:data) { mock }
6
6
  let(:json) { mock }
7
7
  let(:name) { "event-name" }
8
- let(:event) { { "channels" => channels, "name" => name, "data" => data } }
8
+ let(:event) { { "channels" => channels, "name" => name, "data" => data, "socket_id" => socket_id } }
9
9
  let(:request) { stub(body: body) }
10
10
  let(:channels) { ["channel-1", "channel-2"] }
11
11
  let(:response) { mock }
12
12
  let(:channel_1) { stub(emit: true) }
13
13
  let(:channel_2) { stub(emit: true) }
14
+ let(:socket_id) { stub }
14
15
  let(:environment) { mock }
15
16
 
16
17
  subject { PusherFake::Server::Application }
@@ -45,8 +46,8 @@ describe PusherFake::Server::Application, ".call" do
45
46
 
46
47
  it "emits the event to the channels" do
47
48
  subject.call(environment)
48
- channel_1.should have_received(:emit).with(name, data)
49
- channel_2.should have_received(:emit).with(name, data)
49
+ channel_1.should have_received(:emit).with(name, data, socket_id: socket_id)
50
+ channel_2.should have_received(:emit).with(name, data, socket_id: socket_id)
50
51
  end
51
52
 
52
53
  it "creates a Rack response with an empty JSON object" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-12 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 1.4.0
69
+ version: 1.5.0
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 1.4.0
77
+ version: 1.5.0
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: bourne
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - '='
148
148
  - !ruby/object:Gem::Version
149
- version: 10.0.2
149
+ version: 10.0.3
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ dependencies:
154
154
  requirements:
155
155
  - - '='
156
156
  - !ruby/object:Gem::Version
157
- version: 10.0.2
157
+ version: 10.0.3
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: redcarpet
160
160
  requirement: !ruby/object:Gem::Requirement
@@ -279,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
279
279
  version: '0'
280
280
  segments:
281
281
  - 0
282
- hash: 4186586164521781753
282
+ hash: 422324926089299174
283
283
  required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  none: false
285
285
  requirements:
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  version: '0'
289
289
  segments:
290
290
  - 0
291
- hash: 4186586164521781753
291
+ hash: 422324926089299174
292
292
  requirements: []
293
293
  rubyforge_project:
294
294
  rubygems_version: 1.8.23