pusher-fake 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/features/channel_presence.feature +6 -0
- data/features/step_definitions/channel_steps.rb +8 -0
- data/features/step_definitions/presence_steps.rb +2 -2
- data/features/support/application.rb +1 -1
- data/lib/pusher-fake.rb +1 -1
- data/lib/pusher-fake/channel/presence.rb +5 -6
- data/lib/pusher-fake/channel/public.rb +2 -2
- data/lib/pusher-fake/server/application.rb +3 -1
- data/spec/lib/pusher-fake/channel/presence_spec.rb +3 -3
- data/spec/lib/pusher-fake/channel/public_spec.rb +8 -0
- metadata +34 -34
@@ -19,3 +19,9 @@ Feature: Client on a presence channel
|
|
19
19
|
Then I should see 2 clients
|
20
20
|
When Bob unsubscribes from the "presence-game-1" channel
|
21
21
|
Then I should see 1 client
|
22
|
+
|
23
|
+
Scenario: Subscribing client should receive User info
|
24
|
+
Given Bob is connected
|
25
|
+
And Bob is subscribed to the "presence-game-1" channel
|
26
|
+
When I subscribe to the "presence-game-1" channel with presence events
|
27
|
+
Then I should see 2 clients with the name "Alan Turing"
|
@@ -26,6 +26,10 @@ When %{I subscribe to the "$channel" channel with presence events} do |channel|
|
|
26
26
|
var
|
27
27
|
element = list.appendChild(document.createElement("li"));
|
28
28
|
element.setAttribute("id", "client-" + client.id);
|
29
|
+
|
30
|
+
if (client.info) {
|
31
|
+
element.innerHTML = client.info.name;
|
32
|
+
}
|
29
33
|
});
|
30
34
|
});
|
31
35
|
channel.bind("pusher:member_added", function(client) {
|
@@ -34,6 +38,10 @@ When %{I subscribe to the "$channel" channel with presence events} do |channel|
|
|
34
38
|
var
|
35
39
|
element = list.appendChild(document.createElement("li"));
|
36
40
|
element.setAttribute("id", "client-" + client.id);
|
41
|
+
|
42
|
+
if (client.info) {
|
43
|
+
element.innerHTML = client.info.name;
|
44
|
+
}
|
37
45
|
});
|
38
46
|
channel.bind("pusher:member_removed", function(client) {
|
39
47
|
var item = list.querySelector("li#client-" + client.id);
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Then /^I should see (\d+) clients?$/ do |count|
|
1
|
+
Then /^I should see (\d+) clients?(?: with the name "([^"]+)")?$/ do |count, name|
|
2
2
|
within("#presence") do
|
3
3
|
should have_css("header h1 span", text: count)
|
4
|
-
should have_css("ul li", count: count.to_i)
|
4
|
+
should have_css("ul li", count: count.to_i, text: name)
|
5
5
|
end
|
6
6
|
end
|
@@ -19,7 +19,7 @@ class Sinatra::Application
|
|
19
19
|
channel = Pusher[params[:channel_name]]
|
20
20
|
|
21
21
|
if params[:channel_name] =~ /^presence-/
|
22
|
-
data = { user_id: params[:socket_id], user_info: {} }
|
22
|
+
data = { user_id: params[:socket_id], user_info: { name: "Alan Turing" } }
|
23
23
|
end
|
24
24
|
|
25
25
|
channel.authenticate(params[:socket_id], data).to_json
|
data/lib/pusher-fake.rb
CHANGED
@@ -8,7 +8,7 @@ module PusherFake
|
|
8
8
|
#
|
9
9
|
# @param [String] name The channel name.
|
10
10
|
def initialize(name)
|
11
|
-
super
|
11
|
+
super
|
12
12
|
|
13
13
|
@members = {}
|
14
14
|
end
|
@@ -22,14 +22,13 @@ module PusherFake
|
|
22
22
|
emit("pusher_internal:member_removed", members.delete(connection))
|
23
23
|
end
|
24
24
|
|
25
|
-
# Returns a
|
26
|
-
# the channel.
|
25
|
+
# Returns a hash containing presence information for the channel.
|
27
26
|
#
|
28
|
-
# @return [Hash]
|
27
|
+
# @return [Hash] Hash containing presence information.
|
29
28
|
def subscription_data
|
30
29
|
hash = Hash[
|
31
30
|
members.map { |_, member|
|
32
|
-
[member[:user_id], member]
|
31
|
+
[member[:user_id], member[:user_info]]
|
33
32
|
}
|
34
33
|
]
|
35
34
|
|
@@ -43,7 +42,7 @@ module PusherFake
|
|
43
42
|
|
44
43
|
emit("pusher_internal:member_added", members[connection])
|
45
44
|
|
46
|
-
super
|
45
|
+
super
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -48,12 +48,12 @@ module PusherFake
|
|
48
48
|
connections.delete(connection)
|
49
49
|
end
|
50
50
|
|
51
|
-
private
|
52
|
-
|
53
51
|
def subscription_data
|
54
52
|
{}
|
55
53
|
end
|
56
54
|
|
55
|
+
private
|
56
|
+
|
57
57
|
def subscription_succeeded(connection, options = {})
|
58
58
|
connection.emit("pusher_internal:subscription_succeeded", subscription_data, name)
|
59
59
|
connections.push(connection)
|
@@ -18,7 +18,9 @@ module PusherFake
|
|
18
18
|
#
|
19
19
|
# @return [String] The channel name.
|
20
20
|
def self.channel
|
21
|
-
|
21
|
+
matcher = %r{/apps/#{PusherFake.configuration.app_id}/channels/(.+)/events}i
|
22
|
+
matches = path.match(matcher)
|
23
|
+
matches[1]
|
22
24
|
end
|
23
25
|
|
24
26
|
# Parse and return the event data from the request JSON.
|
@@ -111,10 +111,10 @@ describe PusherFake::Channel::Presence, "#subscription_data" do
|
|
111
111
|
subject.stubs(members: members)
|
112
112
|
end
|
113
113
|
|
114
|
-
it "returns
|
114
|
+
it "returns hash with presence information" do
|
115
115
|
subject.subscription_data.should == {
|
116
116
|
presence: {
|
117
|
-
hash: { member[:user_id] => member },
|
117
|
+
hash: { member[:user_id] => member[:user_info] },
|
118
118
|
count: 1
|
119
119
|
}
|
120
120
|
}
|
@@ -125,7 +125,7 @@ describe PusherFake::Channel::Presence, "#subscription_data" do
|
|
125
125
|
|
126
126
|
subject.subscription_data.should == {
|
127
127
|
presence: {
|
128
|
-
hash: { member[:user_id] => member, other[:user_id] => other },
|
128
|
+
hash: { member[:user_id] => member[:user_info], other[:user_id] => other[:user_info] },
|
129
129
|
count: 2
|
130
130
|
}
|
131
131
|
}
|
@@ -88,3 +88,11 @@ describe PusherFake::Channel, "#remove" do
|
|
88
88
|
subject.connections.should be_empty
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
describe PusherFake::Channel::Public, "#subscription_data" do
|
93
|
+
subject { PusherFake::Channel::Public.new("name") }
|
94
|
+
|
95
|
+
it "returns an empty hash" do
|
96
|
+
subject.subscription_data.should == {}
|
97
|
+
end
|
98
|
+
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: em-websocket
|
16
|
-
requirement: &
|
16
|
+
requirement: &70109727331120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.3.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70109727331120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-hmac
|
27
|
-
requirement: &
|
27
|
+
requirement: &70109727329680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.4.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70109727329680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thin
|
38
|
-
requirement: &
|
38
|
+
requirement: &70109727327300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.3.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70109727327300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yajl-ruby
|
49
|
-
requirement: &
|
49
|
+
requirement: &70109727325360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.1.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70109727325360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bourne
|
60
|
-
requirement: &
|
60
|
+
requirement: &70109727339500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.1.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70109727339500
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70109727337120 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.1.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70109727337120
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: capybara
|
82
|
-
requirement: &
|
82
|
+
requirement: &70109727335040 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - =
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.1.2
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70109727335040
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: capybara-webkit
|
93
|
-
requirement: &
|
93
|
+
requirement: &70109727333180 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - =
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.11.0
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70109727333180
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: cucumber
|
104
|
-
requirement: &
|
104
|
+
requirement: &70109727332620 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - =
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 1.1.9
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70109727332620
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: pusher
|
115
|
-
requirement: &
|
115
|
+
requirement: &70109727347660 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - =
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 0.9.2
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70109727347660
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rake
|
126
|
-
requirement: &
|
126
|
+
requirement: &70109727346760 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - =
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 0.9.2.2
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70109727346760
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: redcarpet
|
137
|
-
requirement: &
|
137
|
+
requirement: &70109727345700 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - =
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 2.1.1
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70109727345700
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: rspec
|
148
|
-
requirement: &
|
148
|
+
requirement: &70109727344740 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - =
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: 2.9.0
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70109727344740
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: sinatra
|
159
|
-
requirement: &
|
159
|
+
requirement: &70109727343960 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - =
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: 1.3.2
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70109727343960
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: yard
|
170
|
-
requirement: &
|
170
|
+
requirement: &70109727343260 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - =
|
@@ -175,7 +175,7 @@ dependencies:
|
|
175
175
|
version: 0.7.5
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *70109727343260
|
179
179
|
description: A fake Pusher server for development and testing.
|
180
180
|
email: hello@tristandunn.com
|
181
181
|
executables: []
|
@@ -231,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
231
|
version: '0'
|
232
232
|
segments:
|
233
233
|
- 0
|
234
|
-
hash:
|
234
|
+
hash: 2074501190721020282
|
235
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
236
|
none: false
|
237
237
|
requirements:
|
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
240
|
version: '0'
|
241
241
|
segments:
|
242
242
|
- 0
|
243
|
-
hash:
|
243
|
+
hash: 2074501190721020282
|
244
244
|
requirements: []
|
245
245
|
rubyforge_project:
|
246
246
|
rubygems_version: 1.8.11
|