socky-server 0.4.1 → 0.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +0 -4
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.md +11 -5
  4. data/Gemfile +2 -0
  5. data/README.md +47 -68
  6. data/Rakefile +5 -7
  7. data/config.ru +19 -0
  8. data/example/config.yml +4 -0
  9. data/lib/socky/server.rb +23 -0
  10. data/lib/socky/server/application.rb +51 -0
  11. data/lib/socky/server/channel.rb +30 -0
  12. data/lib/socky/server/channel/base.rb +80 -0
  13. data/lib/socky/server/channel/presence.rb +49 -0
  14. data/lib/socky/server/channel/private.rb +44 -0
  15. data/lib/socky/server/channel/public.rb +43 -0
  16. data/lib/socky/server/channel/stub.rb +17 -0
  17. data/lib/socky/server/config.rb +52 -0
  18. data/lib/socky/server/connection.rb +66 -0
  19. data/lib/socky/server/http.rb +95 -0
  20. data/lib/socky/server/logger.rb +24 -0
  21. data/lib/socky/server/message.rb +35 -0
  22. data/lib/socky/server/misc.rb +18 -0
  23. data/lib/socky/server/version.rb +5 -0
  24. data/lib/socky/server/websocket.rb +43 -0
  25. data/socky-server.gemspec +5 -7
  26. data/spec/fixtures/example_config.yml +3 -0
  27. data/spec/integration/ws_channels_spec.rb +144 -0
  28. data/spec/integration/ws_connection_spec.rb +48 -0
  29. data/spec/integration/ws_presence_spec.rb +118 -0
  30. data/spec/integration/ws_rights_spec.rb +133 -0
  31. data/spec/spec_helper.rb +24 -2
  32. data/spec/support/websocket_application.rb +14 -0
  33. data/spec/unit/socky/server/application_spec.rb +54 -0
  34. data/spec/unit/socky/server/config_spec.rb +50 -0
  35. data/spec/unit/socky/server/connection_spec.rb +67 -0
  36. data/spec/unit/socky/server/message_spec.rb +64 -0
  37. metadata +93 -126
  38. data/bin/socky +0 -5
  39. data/lib/em-websocket_hacks.rb +0 -15
  40. data/lib/socky.rb +0 -75
  41. data/lib/socky/connection.rb +0 -137
  42. data/lib/socky/connection/authentication.rb +0 -99
  43. data/lib/socky/connection/finders.rb +0 -67
  44. data/lib/socky/message.rb +0 -85
  45. data/lib/socky/misc.rb +0 -74
  46. data/lib/socky/net_request.rb +0 -27
  47. data/lib/socky/options.rb +0 -39
  48. data/lib/socky/options/config.rb +0 -79
  49. data/lib/socky/options/parser.rb +0 -93
  50. data/lib/socky/runner.rb +0 -95
  51. data/spec/em-websocket_spec.rb +0 -36
  52. data/spec/files/default.yml +0 -18
  53. data/spec/files/invalid.yml +0 -1
  54. data/spec/socky/connection/authentication_spec.rb +0 -183
  55. data/spec/socky/connection/finders_spec.rb +0 -188
  56. data/spec/socky/connection_spec.rb +0 -151
  57. data/spec/socky/message_spec.rb +0 -102
  58. data/spec/socky/misc_spec.rb +0 -74
  59. data/spec/socky/net_request_spec.rb +0 -42
  60. data/spec/socky/options/config_spec.rb +0 -72
  61. data/spec/socky/options/parser_spec.rb +0 -76
  62. data/spec/socky/options_spec.rb +0 -60
  63. data/spec/socky/runner_spec.rb +0 -88
  64. data/spec/socky_spec.rb +0 -89
  65. data/spec/support/stallion.rb +0 -96
@@ -1,18 +0,0 @@
1
- :port: 8080
2
- :debug: false
3
-
4
- # :subscribe_url: http://localhost:3000/socky/subscribe
5
- # :unsubscribe_url: http://localhost:3000/socky/unsubscribe
6
-
7
- :secret: my_secret_key
8
-
9
- :secure: false
10
-
11
- # :timeout: 3
12
-
13
- # :log_path: /var/log/socky.log
14
- # :pid_path: /var/run/socky.pid
15
-
16
- # :tls_options:
17
- # :private_key_file: /private/key
18
- # :cert_chain_file: /ssl/certificate
@@ -1 +0,0 @@
1
- invalid data
@@ -1,183 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Socky::Connection::Authentication do
4
- include Socky::Connection::Authentication
5
-
6
- context "instance" do
7
- context "#subscribe_request" do
8
- before(:each) do
9
- stub!(:admin).and_return(false)
10
- stub!(:send_data)
11
- end
12
- it "should not call #send_subscribe_request if already authenticated" do
13
- stub!(:authenticated?).and_return(true)
14
- should_not_receive(:send_subscribe_request)
15
- subscribe_request
16
- end
17
- it "should call #send_subscribe_request if unauthenticated" do
18
- stub!(:authenticated?).and_return(false)
19
- should_receive(:send_subscribe_request)
20
- subscribe_request
21
- end
22
- it "should add self to connection list if #send_subscribe_request block is true" do
23
- EM.run do
24
- stub!(:authenticated?).and_return(false)
25
- stub!(:send_subscribe_request).and_yield(true)
26
- should_receive(:add_to_pool)
27
- subscribe_request
28
- EM.stop
29
- end
30
- end
31
- it "should be authenticated by url if #send_subscribe_request block is true" do
32
- EM.run do
33
- stub!(:authenticated?).and_return(false)
34
- stub!(:send_subscribe_request).and_yield(true)
35
- stub!(:add_to_pool)
36
- subscribe_request
37
- authenticated_by_url?.should be_true
38
- EM.stop
39
- end
40
- end
41
- it "should disconnect if #send_subscribe_request block is false" do
42
- EM.run do
43
- stub!(:send_subscribe_request).and_yield(false)
44
- should_receive(:disconnect)
45
- subscribe_request
46
- EM.add_timer(0.1) do
47
- EM.stop
48
- end
49
- end
50
- end
51
- end
52
- context "#unsubscribe_request" do
53
- it "should remove self from connection list if authenticated" do
54
- stub!(:admin).and_return(false)
55
- stub!(:authenticated?).and_return(true)
56
- should_receive(:remove_from_pool)
57
- unsubscribe_request
58
- end
59
- it "should send unsubscribe request if authenticated but not admin" do
60
- stub!(:admin).and_return(false)
61
- stub!(:authenticated?).and_return(true)
62
- stub!(:remove_from_pool)
63
- should_receive(:send_unsubscribe_request)
64
- unsubscribe_request
65
- end
66
- it "should not send unsubscribe request if authenticated and admin" do
67
- stub!(:admin).and_return(true)
68
- stub!(:authenticated?).and_return(true)
69
- stub!(:remove_from_pool)
70
- should_not_receive(:send_unsubscribe_request)
71
- unsubscribe_request
72
- end
73
- it "should not send unsubscribe request if unauthenticated" do
74
- stub!(:authenticated?).and_return(false)
75
- should_not_receive(:send_unsubscribe_request)
76
- unsubscribe_request
77
- end
78
- end
79
- context "#authenticated?" do
80
- it "should authenticate as admin if admin" do
81
- stub!(:admin).and_return(true)
82
- should_receive(:authenticate_as_admin)
83
- authenticated?
84
- end
85
- it "should authenticate as user if not admin" do
86
- stub!(:admin).and_return(false)
87
- should_receive(:authenticate_as_user)
88
- authenticated?
89
- end
90
- end
91
- context "#authenticate_as_admin" do
92
- it "should return true if client secret is equal server secret" do
93
- stub!(:secret).and_return("test")
94
- Socky.stub!(:options).and_return({:secret => "test"})
95
- authenticate_as_admin.should be_true
96
- end
97
- it "should return false if client secret is not equal server secret" do
98
- stub!(:secret).and_return("abstract")
99
- Socky.stub!(:options).and_return({:secret => "test"})
100
- authenticate_as_admin.should be_false
101
- end
102
- it "should return true if server secret is nil" do
103
- stub!(:secret).and_return("abstract")
104
- Socky.stub!(:options).and_return({:secret => nil})
105
- authenticate_as_admin.should be_true
106
- end
107
- end
108
- it "#authenticate_as_user should call #authenticated_by_url?" do
109
- should_receive(:authenticated_by_url?)
110
- authenticate_as_user
111
- end
112
- it "#authenticated_by_url? should return current status" do
113
- instance_variable_set('@authenticated_by_url',true)
114
- authenticated_by_url?.should be_true
115
- instance_variable_set('@authenticated_by_url',false)
116
- authenticated_by_url?.should be_false
117
- end
118
- context "#send_subscribe_request" do
119
- it "should build params for request if socky option subscribe_url is not nil" do
120
- Socky.stub!(:options).and_return({:subscribe_url => "any"})
121
- should_receive(:params_for_request)
122
- send_subscribe_request
123
- end
124
- it "should call Socky::NetRequest#post if socky option subscribe_url is not nil" do
125
- Socky.stub!(:options).and_return({:subscribe_url => "any"})
126
- stub!(:params_for_request)
127
- Socky::NetRequest.should_receive(:post)
128
- send_subscribe_request
129
- end
130
- it "should not call Socky::NetRequest#post if socky option subscribe_url is nil" do
131
- Socky.stub!(:options).and_return({:subscribe_url => nil})
132
- Socky::NetRequest.should_not_receive(:post)
133
- send_subscribe_request{}
134
- end
135
- end
136
- context "#send_unsubscribe_request" do
137
- it "should build params for request if socky option unsubscribe_url is not nil" do
138
- Socky.stub!(:options).and_return({:unsubscribe_url => "any"})
139
- should_receive(:params_for_request)
140
- send_unsubscribe_request{}
141
- end
142
- it "should call Socky::NetRequest#post if socky option unsubscribe_url is not nil" do
143
- Socky.stub!(:options).and_return({:unsubscribe_url => "any"})
144
- stub!(:params_for_request)
145
- Socky::NetRequest.should_receive(:post)
146
- send_unsubscribe_request{}
147
- end
148
- it "should not call Socky::NetRequest#post if socky option unsubscribe_url is nil" do
149
- Socky.stub!(:options).and_return({:unsubscribe_url => nil})
150
- Socky::NetRequest.should_not_receive(:post)
151
- send_unsubscribe_request{}
152
- end
153
- end
154
- context "#params_for_request" do
155
- before(:each) do
156
- stub!(:client)
157
- stub!(:secret)
158
- stub!(:channels).and_return([])
159
- end
160
- it "should return empty hash if none of (client,secret,channels) are set" do
161
- params_for_request.should eql({})
162
- end
163
- it "should return client as client_id if set" do
164
- stub!(:client).and_return("some client")
165
- params_for_request.should eql({:client_id => "some client"})
166
- end
167
- it "should return secret as client_secret if set" do
168
- stub!(:secret).and_return("some secret")
169
- params_for_request.should eql({:client_secret => "some secret"})
170
- end
171
- it "should return channels if not empty" do
172
- stub!(:channels).and_return(["some channel"])
173
- params_for_request.should eql({:channels => ["some channel"]})
174
- end
175
- it "should return client, secret and channels as hash if all are set" do
176
- stub!(:client).and_return("some client")
177
- stub!(:secret).and_return("some secret")
178
- stub!(:channels).and_return(["some channel"])
179
- params_for_request.should eql({:client_id => "some client", :client_secret => "some secret", :channels => ["some channel"]})
180
- end
181
- end
182
- end
183
- end
@@ -1,188 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Socky::Connection::Finders do
4
- include Socky::Connection::Finders
5
- include Socky::Misc
6
-
7
- context "class" do
8
- before(:each) do
9
- @connection1 = mock(:connection1, :client => "client1", :channels => [nil])
10
- @connection2 = mock(:connection2, :client => "client1", :channels => ["1", "3", "5"])
11
- @connection3 = mock(:connection3, :client => "client2", :channels => ["2", "5"])
12
- @connection4 = mock(:connection4, :client => "client3", :channels => ["3", "5"])
13
- @connections = [@connection1,@connection2,@connection3,@connection4]
14
- @connections.collect { |connection| Socky::Connection.connections << connection }
15
- end
16
- after(:each) do
17
- Socky::Connection.connections.clear
18
- end
19
-
20
- it "#find_all should return all connections" do
21
- find_all.should eql(@connections)
22
- end
23
- context "#find" do
24
- it "should return all connections if no options specified" do
25
- find.should eql(@connections)
26
- end
27
- context "on :to" do
28
- context "if :clients option is specified" do
29
- it "should return all connections if :clients is nil" do
30
- find(:to => {:clients => nil}).should eql(@connections)
31
- end
32
- it "should return none connections if :clients is empty" do
33
- find(:to => {:clients => []}).should eql([])
34
- end
35
- it "should return only connections from specified client" do
36
- find(:to => {:clients => "client1"}).should eql([@connection1,@connection2])
37
- end
38
- it "should return only connections from specified clients if array provided" do
39
- find(:to => {:clients => ["client1","client2"]}).should eql([@connection1,@connection2,@connection3])
40
- end
41
- end
42
- context "if :channels option is specified" do
43
- it "should return all connections if :channels is nil" do
44
- find(:to => {:channels => nil}).should eql(@connections)
45
- end
46
- it "should return none connections if :channels is empty" do
47
- find(:to => {:channels => []}).should eql([])
48
- end
49
- it "should return all connections that include specified channel" do
50
- find(:to => {:channels => "3"}).should eql([@connection2,@connection4])
51
- end
52
- it "should return all connections that include at last one of specified channels" do
53
- find(:to => {:channels => ["2","3"]}).should eql([@connection2,@connection3,@connection4])
54
- end
55
- end
56
- context "if both :clients and :channels options are provided" do
57
- context "but :channels are nil" do
58
- it "should return only connections from specified client" do
59
- find(:to => {:channels => nil,:clients => "client1"}).should eql([@connection1,@connection2])
60
- end
61
- it "should return only connections from specified clients if array provided" do
62
- find(:to => {:channels => nil,:clients => ["client1","client2"]}).should eql([@connection1,@connection2,@connection3])
63
- end
64
- end
65
- context "but :channels are empty" do
66
- it "should return none connections" do
67
- find(:to => {:channels => [],:clients => "client1"}).should eql([])
68
- end
69
- it "should return none connections if array provided" do
70
- find(:to => {:channels => [],:clients => ["client1","client2"]}).should eql([])
71
- end
72
- end
73
- context "but :clients are nil" do
74
- it "should return all connections that include specified channel" do
75
- find(:to => {:clients => nil,:channels => "3"}).should eql([@connection2,@connection4])
76
- end
77
- it "should return all connections that include at last one of specified channels" do
78
- find(:to => {:clients => nil,:channels => ["2","3"]}).should eql([@connection2,@connection3,@connection4])
79
- end
80
- end
81
- context "but :clients are empty" do
82
- it "should return none connections" do
83
- find(:to => {:clients => [],:channels => "3"}).should eql([])
84
- end
85
- it "should return none connections if array provided" do
86
- find(:to => {:clients => [],:channels => ["2","3"]}).should eql([])
87
- end
88
- end
89
- it "should return only connections from specified client that include specified channel" do
90
- find(:to => {:clients => "client1",:channels => "3"}).should eql([@connection2])
91
- find(:to => {:clients => "client1",:channels => "2"}).should eql([])
92
- end
93
- it "should return only connections from specified client that include one of specified channels" do
94
- find(:to => {:clients => "client1",:channels => ["2","3"]}).should eql([@connection2])
95
- end
96
- it "should return only connections from specified clients that include specified channel" do
97
- find(:to => {:clients => ["client1","client2"],:channels => "2"}).should eql([@connection3])
98
- end
99
- it "should return only connections from specified clients that include at last one of specified channels" do
100
- find(:to => {:clients => ["client1","client2"],:channels => ["2","1"]}).should eql([@connection2,@connection3])
101
- end
102
- end
103
- end
104
-
105
- context "on :except" do
106
- context "if :clients option is specified" do
107
- it "should return all connections if :clients is nil" do
108
- find(:except => {:clients => nil}).should eql(@connections)
109
- end
110
- it "should return all connections if :clients is empty" do
111
- find(:except => {:clients => []}).should eql(@connections)
112
- end
113
- it "should return all connections except of specified client" do
114
- find(:except => {:clients => "client1"}).should eql([@connection3,@connection4])
115
- end
116
- it "should return all connections except of specified clients if array provided" do
117
- find(:except => {:clients => ["client1","client2"]}).should eql([@connection4])
118
- end
119
- end
120
- context "if :channels option is specified" do
121
- it "should return all connections if :channels is nil" do
122
- find(:except => {:channels => nil}).should eql(@connections)
123
- end
124
- it "should return all connections if :channels is empty" do
125
- find(:except => {:channels => []}).should eql(@connections)
126
- end
127
- it "should return all connections except of that include all specified channels" do
128
- find(:except => {:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
129
- end
130
- end
131
- context "if both :clients and :channels options are provided" do
132
- context "but :channels are nil" do
133
- it "should return all connections except of specified client" do
134
- find(:except => {:channels => nil,:clients => "client1"}).should eql([@connection3,@connection4])
135
- end
136
- it "should return all connections except of specified clients if array provided" do
137
- find(:except => {:channels => nil,:clients => ["client1","client2"]}).should eql([@connection4])
138
- end
139
- end
140
- context "but :channels are empty" do
141
- it "should return all connections except of specified client" do
142
- find(:except => {:channels => [],:clients => "client1"}).should eql([@connection3,@connection4])
143
- end
144
- it "should return all connections except of provided clients if array provided" do
145
- find(:except => {:channels => [],:clients => ["client1","client2"]}).should eql([@connection4])
146
- end
147
- end
148
- context "but :clients are nil" do
149
- it "should return all connections except of that include all of specified channels" do
150
- find(:except => {:clients => nil,:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
151
- end
152
- end
153
- context "but :clients are empty" do
154
- it "should return all connections except of that include all of specified channels " do
155
- find(:except => {:clients => [],:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
156
- end
157
- end
158
- it "should return all connections except of specified client or all specified channels" do
159
- find(:except => {:clients => "client2",:channels => "3"}).should eql([@connection1,@connection2,@connection4])
160
- find(:except => {:clients => "client2",:channels => ["3","5"]}).should eql([@connection1,@connection2])
161
- end
162
- it "should return only connections from specified clients that include specified channel" do
163
- find(:except => {:clients => ["client1","client2"],:channels => "3"}).should eql([@connection4])
164
- find(:except => {:clients => ["client1","client2"],:channels => ["3","5"]}).should eql([])
165
- end
166
- end
167
- end
168
-
169
- context "on :to and :except" do
170
- context "should value 'except' more that 'to'" do
171
- it "on :client" do
172
- find(:to => {:clients => "client1"},:except => {:clients => "client1"}).should eql([])
173
- end
174
- it "on :channels" do
175
- find(:to => {:channels => "5"},:except => {:channels => "5"}).should eql([])
176
- end
177
- it "on :client allow and :channels except" do
178
- find(:to => {:clients => "client2"},:except => {:channels => ["2","5"]}).should eql([])
179
- end
180
- it "on :channels allow and :clients except" do
181
- find(:to => {:channels => ["5"]},:except => {:clients => "client2"}).should eql([@connection2,@connection4])
182
- end
183
- end
184
- end
185
- end
186
-
187
- end
188
- end
@@ -1,151 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Socky::Connection do
4
-
5
- context "class" do
6
- it "should have connections array" do
7
- described_class.connections.should_not be_nil
8
- described_class.connections.class.should eql(Array)
9
- end
10
- it "should have empty connections array at start" do
11
- described_class.connections.should be_empty
12
- end
13
- it "should create instance and assign socket to self" do
14
- socket = mock(:socket)
15
- connection = described_class.new(socket)
16
- connection.socket.should equal(socket)
17
- end
18
- end
19
-
20
- context "instance" do
21
- before(:each) do
22
- described_class.connections.clear
23
- socket = mock(:socket, :request => { "query" => {}})
24
- @connection = described_class.new(socket)
25
- end
26
-
27
- context "#admin" do
28
- it "should return true for socket request data admin equal to '1' and 'true'" do
29
- ["1","true"].each do |value|
30
- @connection.socket.request["query"]["admin"] = value
31
- @connection.admin.should be_true
32
- end
33
- end
34
- it "should return false for socket request data admin equal to anything except '1' and 'true'" do
35
- [nil,"0","false","abstract"].each do |value|
36
- @connection.socket.request["query"]["admin"] = value
37
- @connection.admin.should be_false
38
- end
39
- end
40
- it "should return false if socket request data is nil" do
41
- @connection.socket.request["query"] = nil
42
- @connection.admin.should be_false
43
- end
44
- end
45
- it "#client should return client_id from socket request data" do
46
- @connection.socket.request["query"]["client_id"] = "abstract"
47
- @connection.client.should eql("abstract")
48
- end
49
- it "#secret should return client_secret from socket request data" do
50
- @connection.socket.request["query"]["client_secret"] = "abstract"
51
- @connection.secret.should eql("abstract")
52
- end
53
- context "#channels" do
54
- it "should ba array" do
55
- @connection.channels.should_not be_nil
56
- @connection.channels.class.should eql(Array)
57
- end
58
- it "should return table with nil if socket request data 'channels' is nil" do
59
- @connection.socket.request["query"]["channels"] = nil
60
- @connection.channels.should eql([nil])
61
- end
62
- it "should return table of channels if provided and separated by comma" do
63
- @connection.socket.request["query"]["channels"] = "aaa,bbb,ccc"
64
- @connection.channels.should eql(["aaa","bbb","ccc"])
65
- end
66
- it "should not allow empty names of channels" do
67
- @connection.socket.request["query"]["channels"] = "aaa,,ccc"
68
- @connection.channels.should eql(["aaa","ccc"])
69
- end
70
- it "should strip trailing spaces in channel names" do
71
- @connection.socket.request["query"]["channels"] = " aaa\n , \n , ccc "
72
- @connection.channels.should eql(["aaa","ccc"])
73
- end
74
- end
75
- it "#subscribe should send subscribe request" do
76
- @connection.stub!(:subscribe_request)
77
- @connection.should_receive(:subscribe_request)
78
- @connection.subscribe
79
- end
80
- it "#unsubscribe should send unsubscribe request" do
81
- @connection.stub!(:unsubscribe_request)
82
- @connection.should_receive(:unsubscribe_request)
83
- @connection.unsubscribe
84
- end
85
- context "#process_message" do
86
- it "should send process request to socky message class if connection is by admin" do
87
- @connection.stub!(:admin).and_return(true)
88
- Socky::Message.stub!(:process)
89
- Socky::Message.should_receive(:process).with(@connection, "abstract")
90
- @connection.process_message("abstract")
91
- end
92
- it "should send user message that he can not send messages if connection is not admin" do
93
- @connection.stub!(:admin).and_return(false)
94
- @connection.stub!(:send_message)
95
- @connection.should_receive(:send_message).with("You are not authorized to post messages")
96
- @connection.process_message("abstract")
97
- end
98
- end
99
- it "#send_message should call #send_data with hashed form of message" do
100
- @connection.should_receive(:send_data).with({:type => :message, :body => "abstract"})
101
- @connection.send_message("abstract")
102
- end
103
- it "#send_data should send message by socket in json format" do
104
- @connection.socket.stub!(:send)
105
- @connection.socket.should_receive(:send).with({:test => "abstract"}.to_json)
106
- @connection.send(:send_data, {:test => "abstract"})
107
- end
108
- it "#disconnect should close connection after writing" do
109
- @connection.socket.stub!(:close_connection_after_writing)
110
- @connection.socket.should_receive(:close_connection_after_writing)
111
- @connection.disconnect
112
- end
113
- context "#add_to_pool" do
114
- it "should add self to class connection list if self isn't already on list or self isn't admin" do
115
- @connection.stub!(:admin).and_return(false)
116
- @connection.send(:add_to_pool)
117
- described_class.connections.should include(@connection)
118
- described_class.connections.should have(1).item
119
- end
120
- it "should not add self to class connection list if self is already on it" do
121
- described_class.connections << @connection
122
- described_class.connections.should have(1).item
123
- @connection.stub!(:admin).and_return(false)
124
- @connection.send(:add_to_pool)
125
- described_class.connections.should include(@connection)
126
- described_class.connections.should have(1).item
127
- end
128
- it "should not add self to class connection list if self is admin" do
129
- @connection.stub!(:admin).and_return(true)
130
- @connection.send(:add_to_pool)
131
- described_class.connections.should_not include(@connection)
132
- end
133
- end
134
- it "#remove_from_pool should delete self from class connection list" do
135
- described_class.connections << @connection
136
- described_class.connections.should have(1).item
137
- @connection.send(:remove_from_pool)
138
- described_class.connections.should_not include(@connection)
139
- described_class.connections.should have(0).items
140
- end
141
- it "#to_json should return self as hash of object_id, client_id and channels" do
142
- @connection.socket.request["query"]["client_id"] = "abstract"
143
- @connection.socket.request["query"]["channels"] = "first,second,third"
144
- json = @connection.to_json
145
- JSON.parse(json).should eql({ "id" => @connection.object_id,
146
- "client_id" => @connection.client,
147
- "channels" => @connection.channels})
148
- end
149
- end
150
-
151
- end