celluloid_pubsub 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdde06fb1422bf75d45e6f83706c695288d9c42e
4
- data.tar.gz: f98a1a07331fbc7fcb67ee168191c0e4510b5181
3
+ metadata.gz: 2205e89d97959a97cb9a4887be58c2633478e1f4
4
+ data.tar.gz: 7fae7ef47ce0afd1c13caaad16b7d56f7de15246
5
5
  SHA512:
6
- metadata.gz: 02f4c5e864fa97fa3cffbb2cdf30f0f5dddf7f6341c2b042b247cbc75209118feb79cb9570ebae48f7e7ac6928a3ebdf1df7247523001f84a0d4bf04873d25c9
7
- data.tar.gz: b8e905df5512a160194ea0ea13e0034c62ffbaa6b05031fa63df6f7c3d2af8384b49eba3e12a2092ffefd343e28061a5823319094c754576fe086e4ccafe1ba2
6
+ metadata.gz: 3e09e51937f275c8eac631cbfe66403810da789bf4062e4e32812fdf54ac5ceb119f3ee2be4357040aa7e3751e56941dbdcd7e414235e6722a8dcffc3321a414
7
+ data.tar.gz: 9dd88606ce87f7418ab94a9108820833327762f4b4d214057311c6154dc7846237934485f26c387a304974bf785bff395ca67c0e1187d46d2010e16df7c5d223
data/.travis.yml CHANGED
@@ -1,9 +1,20 @@
1
+ language: ruby
1
2
  sudo: false
3
+
2
4
  cache: bundler
3
- language: ruby
5
+
6
+ bundler_args: --without test --jobs 3 --retry 3
7
+
4
8
  before_install:
5
9
  - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
6
10
  - gem install bundler
11
+ - gem update bundler
12
+
13
+ install:
14
+ - bundle install --path vendor/bundle
15
+
16
+ script: bundle exec rake
17
+
7
18
  rvm:
8
19
  - 2.0.0
9
20
  - 2.1.5
data/Gemfile CHANGED
@@ -2,8 +2,7 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- if RUBY_VERSION >= "2.2.0"
6
- gem 'activesupport', '>= 4.0', '>= 4.0'
7
- else
5
+ if RUBY_VERSION < "2.2.0"
8
6
  gem 'activesupport', '>= 4.0', '< 5.0'
7
+ gem 'bundler' '< 1.13'
9
8
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activesupport", ">= 4.0", ">= 4.0"
6
5
  gem "celluloid", "0.16.0"
7
6
 
8
7
  gemspec :path => "../"
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activesupport", ">= 4.0", ">= 4.0"
6
5
  gem "celluloid", "0.17.3"
7
6
 
8
7
  gemspec :path => "../"
@@ -147,12 +147,12 @@ module CelluloidPubsub
147
147
  #
148
148
  # @api public
149
149
  def handle_parsed_websocket_message(json_data)
150
- if json_data.is_a?(Hash)
151
- json_data = json_data.stringify_keys
150
+ data = json_data.is_a?(Hash) ? json_data.stringify_keys : {}
151
+ if CelluloidPubsub::Reactor::AVAILABLE_ACTIONS.include?(data['client_action'].to_s)
152
152
  log_debug "#{self.class} finds actions for #{json_data}"
153
- delegate_action(json_data) if json_data['client_action'].present?
153
+ delegate_action(data) if data['client_action'].present?
154
154
  else
155
- handle_unknown_action(json_data)
155
+ handle_unknown_action(data['channel'], json_data)
156
156
  end
157
157
  end
158
158
 
@@ -179,9 +179,7 @@ module CelluloidPubsub
179
179
  #
180
180
  # @api public
181
181
  def delegate_action(json_data)
182
- channel, client_action = json_data.slice('channel', 'client_action').values
183
- return unless CelluloidPubsub::Reactor::AVAILABLE_ACTIONS.include?(client_action)
184
- async.send(client_action, channel, json_data)
182
+ async.send(json_data['client_action'], json_data['channel'], json_data)
185
183
  end
186
184
 
187
185
  # the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
@@ -357,10 +355,10 @@ module CelluloidPubsub
357
355
  # @return [void]
358
356
  #
359
357
  # @api public
360
- def unsubscribe_all(_channel, _json_data)
358
+ def unsubscribe_all(_channel, json_data)
361
359
  log_debug "#{self.class} runs 'unsubscribe_all' method"
362
360
  CelluloidPubsub::Registry.channels.dup.pmap do |channel|
363
- unsubscribe_clients(channel)
361
+ unsubscribe_clients(channel, json_data)
364
362
  end
365
363
  log_debug 'clearing connections'
366
364
  shutdown
@@ -19,10 +19,10 @@ module CelluloidPubsub
19
19
  # minor release version
20
20
  MINOR = 0
21
21
  # tiny release version
22
- TINY = 0
22
+ TINY = 1
23
23
  # prelease version ( set this only if it is a prelease)
24
24
  PRE = nil
25
-
25
+
26
26
  # generates the version string
27
27
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
28
28
  end
@@ -80,86 +80,108 @@ describe CelluloidPubsub::Reactor do
80
80
 
81
81
  describe '#handle_parsed_websocket_message' do
82
82
  it 'handle_websocket_message with a hash' do
83
- data = { 'client_action' => 'b' }
83
+ data = { 'client_action' => 'subscribe' }
84
84
  data.expects(:stringify_keys).returns(data)
85
85
  subject.expects(:delegate_action).with(data)
86
86
  subject.handle_parsed_websocket_message(data)
87
87
  end
88
88
 
89
89
  it 'handle_websocket_message with something else than a hash' do
90
- data = 'some message'
91
- subject.expects(:handle_unknown_action).with(data)
90
+ data = { 'message'=> 'some message' }
91
+ subject.expects(:handle_unknown_action).with(data['channel'], data)
92
92
  subject.handle_parsed_websocket_message(data)
93
93
  end
94
94
  end
95
95
 
96
96
  describe '#delegate_action' do
97
+
98
+ before(:each) do
99
+ subject.stubs(:unsubscribe_clients).returns(true)
100
+ subject.stubs(:shutdown).returns(true)
101
+ end
102
+
97
103
  it 'unsubscribes all' do
98
- data = { 'client_action' => 'unsubscribe_all' }
99
- subject.expects(:unsubscribe_all).returns('bla')
104
+ data = { 'client_action' => 'unsubscribe_all', 'channel' => '' }
105
+ subject.expects(:send).with(data['client_action'], data['channel'], data).returns('bla')
100
106
  subject.delegate_action(data)
101
107
  end
102
108
 
103
109
  it 'unsubscribes all' do
104
110
  data = { 'client_action' => 'unsubscribe', 'channel' => 'some channel' }
105
- subject.expects(:unsubscribe).with(data['channel'])
111
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
106
112
  subject.delegate_action(data)
107
113
  end
108
-
114
+ #
109
115
  it 'subscribes to channell' do
110
116
  data = { 'client_action' => 'subscribe', 'channel' => 'some channel' }
111
- subject.expects(:start_subscriber).with(data['channel'], data)
117
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
112
118
  subject.delegate_action(data)
113
119
  end
114
120
 
115
121
  it 'publish' do
116
122
  data = { 'client_action' => 'publish', 'channel' => 'some channel', 'data' => 'some data' }
117
- subject.expects(:publish_event).with(data['channel'], data['data'].to_json)
118
- subject.delegate_action(data)
119
- end
120
-
121
- it 'handles unknown' do
122
- data = { 'client_action' => 'some action', 'channel' => 'some channel' }
123
- subject.expects(:handle_unknown_action).with(data)
123
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
124
124
  subject.delegate_action(data)
125
125
  end
126
126
  end
127
-
127
+ #
128
128
  describe '#handle_unknown_action' do
129
129
  it 'handles unknown' do
130
130
  data = 'some data'
131
+ channel = "some_channel"
131
132
  server.expects(:handle_dispatched_message)
132
- subject.handle_unknown_action(data)
133
+ subject.handle_unknown_action(channel, data)
133
134
  end
134
135
  end
135
136
 
136
137
  describe '#unsubscribe_client' do
137
138
  let(:channel) { 'some channel' }
139
+ let(:data) { {'client_action' => 'unsubscribe', 'channel' => channel } }
138
140
  it 'returns nil' do
139
- act = subject.unsubscribe('')
141
+ act = subject.unsubscribe('', data)
140
142
  expect(act).to eq(nil)
141
143
  end
142
144
 
143
145
  it 'unsubscribes' do
144
- subject.channels.stubs(:blank?).returns(false)
145
- subject.channels.expects(:delete).with(channel)
146
- act = subject.unsubscribe(channel)
146
+ channel.stubs(:present?).returns(true)
147
+ subject.expects(:forget_channel).with(channel)
148
+ subject.expects(:delete_server_subscribers).with(channel)
149
+ act = subject.unsubscribe(channel, data)
147
150
  expect(act).to eq(nil)
148
151
  end
149
152
 
153
+
154
+ end
155
+
156
+ describe '#delete_server_subscribers' do
157
+ let(:channel) { 'some channel' }
158
+
159
+ before(:each) do
160
+ server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
161
+ end
162
+
163
+ it 'unsubscribes' do
164
+ act = subject.delete_server_subscribers(channel)
165
+ expect(server.subscribers[channel]).to eq([])
166
+ end
167
+ end
168
+
169
+ describe '#forget_channel' do
170
+ let(:channel) { 'some channel' }
171
+
150
172
  it 'unsubscribes' do
151
173
  subject.channels.stubs(:blank?).returns(true)
152
174
  subject.websocket.expects(:close)
153
- act = subject.unsubscribe(channel)
175
+ act = subject.forget_channel(channel)
154
176
  expect(act).to eq(nil)
155
177
  end
156
178
 
157
179
  it 'unsubscribes' do
158
180
  subject.channels.stubs(:blank?).returns(false)
159
- subject.channels.stubs(:delete)
160
- server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
161
- subject.unsubscribe(channel)
162
- expect(server.subscribers[channel]).to eq([])
181
+ subject.channels.expects(:delete).with(channel)
182
+ # server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
183
+ subject.forget_channel(channel)
184
+ # expect(server.subscribers[channel]).to eq([])
163
185
  end
164
186
  end
165
187
 
@@ -175,7 +197,7 @@ describe CelluloidPubsub::Reactor do
175
197
  let(:message) { { a: 'b' } }
176
198
 
177
199
  it 'subscribes ' do
178
- act = subject.start_subscriber('', message)
200
+ act = subject.subscribe('', message)
179
201
  expect(act).to eq(nil)
180
202
  end
181
203
 
@@ -183,7 +205,7 @@ describe CelluloidPubsub::Reactor do
183
205
  subject.stubs(:add_subscriber_to_channel).with(channel, message)
184
206
  server.stubs(:redis_enabled?).returns(false)
185
207
  subject.websocket.expects(:<<).with(message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json)
186
- subject.start_subscriber(channel, message)
208
+ subject.subscribe(channel, message)
187
209
  end
188
210
 
189
211
  # it 'raises error' do
@@ -218,8 +240,8 @@ describe CelluloidPubsub::Reactor do
218
240
 
219
241
  it 'adds subscribed' do
220
242
  CelluloidPubsub::Registry.stubs(:channels).returns([channel])
221
- subject.expects(:unsubscribe_from_channel).with(channel)
222
- subject.unsubscribe_all
243
+ subject.expects(:unsubscribe_from_channel).with(channel).returns(true)
244
+ subject.unsubscribe_all(channel, message)
223
245
  end
224
246
  end
225
247
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid