garufa 0.0.1.beta.1 → 0.0.1.beta.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed1fb1125ed40c4f3cc0a19dcae61dff59691948
4
- data.tar.gz: 30e670e78a6ecdf3c678a8a32523bce7ad768ee9
3
+ metadata.gz: 0bbc4d733e7b71f96bdb8b0d0929daffd9042615
4
+ data.tar.gz: 2c3d7c91f49298af24a5f1e6f05ea9a3c4345354
5
5
  SHA512:
6
- metadata.gz: c92cfa90de87f3256e6b9e7888438d6ae2c014458ea4fd630a9f44e516861dece549eb9a47ee08c3b9384d7f1b962a7734bf8a26b3bb90dacb031b123790c567
7
- data.tar.gz: f294190202d0cc16e2a7bd95e9d34d213ffaa003bcc473c67800e166ae6a9d409d91331ead19d5c02e77889e5f891250266520e2ece44291999897282f8db2ba
6
+ metadata.gz: 5a44c756812053df6672f5a123635785ad017dfa92ce5d6cf86fd6937f956f91eb9ffa451783afadea861ce41dd3ac9a5dcf9ea18d02c11c42bdc977754e21ec
7
+ data.tar.gz: 3e41c06d811cdb818a0282566d0817ff3ffcacbd936b1d8ef78785f6d97299ba91715d2dfedb6feb9fe5c09bd2adf767c733e0aafb0c0bbab98286bdbdbd280e
@@ -4,15 +4,15 @@ $:.push File.expand_path("../lib", __FILE__)
4
4
  require 'garufa/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "garufa"
8
- s.version = Garufa::VERSION
9
- s.summary = "Websocket server compatible with Pusher."
10
- s.description = "Garufa is a websocket server compatible with the Pusher service protocol."
11
- s.authors = ["Juan Manuel Cuello"]
12
- s.email = ["juanmacuello@gmail.com"]
13
- s.homepage = "http://github.com/Juanmcuello/garufa"
14
- s.bindir = 'bin'
15
- s.executables << 'garufa'
7
+ s.name = "garufa"
8
+ s.version = Garufa::VERSION
9
+ s.summary = "Websocket server compatible with Pusher."
10
+ s.description = "Garufa is a websocket server compatible with the Pusher protocol."
11
+ s.authors = ["Juan Manuel Cuello"]
12
+ s.email = ["juanmacuello@gmail.com"]
13
+ s.homepage = "http://github.com/Juanmcuello/garufa"
14
+ s.bindir = 'bin'
15
+ s.executables << 'garufa'
16
16
 
17
17
  s.files = Dir[
18
18
  "LICENSE",
@@ -29,4 +29,5 @@ Gem::Specification.new do |s|
29
29
  s.add_dependency "cuba"
30
30
  s.add_dependency "signature"
31
31
  s.add_development_dependency "rake"
32
+ s.add_development_dependency "minitest", '~> 5.3.1'
32
33
  end
@@ -39,7 +39,7 @@ module Garufa
39
39
  private
40
40
 
41
41
  def subscriptions
42
- @subscriptions ||= Hash.new(Set.new)
42
+ @subscriptions ||= Hash.new { |h, k| h[k] = Set.new }
43
43
  end
44
44
  end
45
45
 
@@ -1,4 +1,4 @@
1
1
  module Garufa
2
- VERSION = '0.0.1.beta.1'
2
+ VERSION = '0.0.1.beta.2'
3
3
  end
4
4
 
@@ -11,6 +11,18 @@ module Garufa
11
11
 
12
12
  describe '.handle_incomming_data' do
13
13
 
14
+ describe 'pusher:ping' do
15
+
16
+ let(:data) { { event: 'pusher:ping', data: { channel: 'ch1' } } }
17
+
18
+ it 'should response with pong' do
19
+ message = Message.pong
20
+ @socket.expect :send, true, [message.to_json]
21
+ @connection.handle_incomming_data data.to_json
22
+ @socket.verify
23
+ end
24
+ end
25
+
14
26
  describe 'pusher:subscribe' do
15
27
 
16
28
  let(:data) { { event: 'pusher:subscribe', data: { channel: 'ch1' } } }
@@ -70,6 +82,25 @@ module Garufa
70
82
  end
71
83
  end
72
84
  end
85
+
86
+ describe 'pusher:unsubscribe' do
87
+
88
+ let(:channel) { 'ch1' }
89
+ let(:data_subscribe) { { event: 'pusher:subscribe', data: { channel: channel } } }
90
+ let(:data_unsubscribe) { { event: 'pusher:unsubscribe', data: { channel: channel } } }
91
+
92
+ before do
93
+ @socket.expect :send, true, [String]
94
+ @connection.handle_incomming_data data_subscribe.to_json
95
+ end
96
+
97
+ it 'should remove Subscription from Subscriptions' do
98
+ count = Subscriptions.all[channel].count
99
+ @connection.handle_incomming_data data_unsubscribe.to_json
100
+ Subscriptions.all[channel].count.must_equal count - 1
101
+ end
102
+
103
+ end
73
104
  end
74
105
  end
75
106
  end
@@ -27,11 +27,11 @@ module Garufa
27
27
 
28
28
  describe '.channel_event' do
29
29
 
30
- let(:channel) { 'channel-123' }
31
- let(:event) { 'my-event' }
32
- let(:data) { { itemId: 1, value: 'Sample Item' } }
30
+ let(:channel) { 'channel-123' }
31
+ let(:event) { 'my-event' }
32
+ let(:data) { { itemId: 1, value: 'Sample Item' } }
33
33
 
34
- before do
34
+ before do
35
35
  @message = Message.channel_event channel, event, data
36
36
  end
37
37
 
@@ -0,0 +1,56 @@
1
+ require File.expand_path("helper", File.dirname(__FILE__))
2
+
3
+ module Garufa
4
+ describe Subscriptions do
5
+
6
+ let(:channel) { 'channel1' }
7
+ let(:data) { { 'channel' => channel } }
8
+
9
+ describe '.remove' do
10
+
11
+ before do
12
+ @subscription = Subscription.new(data, nil)
13
+ Subscriptions.add @subscription
14
+ end
15
+
16
+ it 'should remove subscription to channel' do
17
+ count = Subscriptions.all[channel].count
18
+ Subscriptions.remove @subscription
19
+ Subscriptions.all[channel].count.must_equal count - 1
20
+ end
21
+ end
22
+
23
+ describe '.add' do
24
+
25
+ before do
26
+ @connection = MiniTest::Mock.new
27
+ @connection.expect :socket_id, true
28
+ @connection.expect :send_message, true, [Message]
29
+ end
30
+
31
+ it 'should add a new subscription to channel' do
32
+ count = Subscriptions.all[channel].count
33
+ Subscriptions.add Subscription.new(data, @connection)
34
+ Subscriptions.all[channel].count.must_equal count + 1
35
+ end
36
+ end
37
+
38
+ describe '.notify' do
39
+
40
+ let(:event) { 'my-event' }
41
+
42
+ it 'should notify to subscribed subscriptions' do
43
+
44
+ @connection = MiniTest::Mock.new
45
+ @connection.expect :socket_id, true
46
+ @connection.expect(:send_message, true) do |m|
47
+ Message.channel_event(channel, event, nil).to_json == m.to_json
48
+ end
49
+
50
+ Subscriptions.add Subscription.new(data, @connection)
51
+ Subscriptions.notify([channel], event)
52
+ @connection.verify
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garufa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta.1
4
+ version: 0.0.1.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Manuel Cuello
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: goliath
@@ -80,7 +80,21 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Garufa is a websocket server compatible with the Pusher service protocol.
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 5.3.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 5.3.1
97
+ description: Garufa is a websocket server compatible with the Pusher protocol.
84
98
  email:
85
99
  - juanmacuello@gmail.com
86
100
  executables:
@@ -107,6 +121,7 @@ files:
107
121
  - garufa.gemspec
108
122
  - test/helper.rb
109
123
  - test/message.rb
124
+ - test/subscriptions.rb
110
125
  - test/connection.rb
111
126
  homepage: http://github.com/Juanmcuello/garufa
112
127
  licenses: []