backrub 0.0.1 → 1.0.0

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: d7780eda17a51d6eb07f8a5ea32877b96da3abf1
4
- data.tar.gz: ce2e4e6312cf7a7ebb3a0e810197ca83813e755f
3
+ metadata.gz: 27968ba3418abbcab97c0b582bcfab4c70a18178
4
+ data.tar.gz: b38040b3676d3c4a765e7cf4ce8711a6c50e5aac
5
5
  SHA512:
6
- metadata.gz: 67fc625e211468e0b46c8ee1acb5be624d74546609a8813fa80f4e1fdf29fb0916f38da18fc2ceb5fc039354087c3557451752bd3c4699ab7139cf9a1fefd99b
7
- data.tar.gz: b916b4fbef1b680a7b971e5578ca1d52b34d7a81f08746e463e2ceaba1a67e4c02949dfa3bcb85e267becdcf99f437837b743bbcace1f5c255441197f298ef23
6
+ metadata.gz: 5fe540cc437d3766e524506ed6dc60499a376b6a478e0a349ecf676c1ffa9c1e991a969ae7a32681540c6e7fd48b6dc8a8f90b85de7d9f3982f1a188d5d77ace
7
+ data.tar.gz: 75cc23037ab89e3bfc1d9fe9f503008a3ce510da7c5527ff6fdb92bdb68cfbd92a6109aaa6dfe9326363a027881f2aa8919502e1e99249a97b92cef518b40f0a
@@ -7,6 +7,10 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ metaclass (0.0.2)
11
+ minitest (4.7.5)
12
+ mocha (1.0.0)
13
+ metaclass (~> 0.0.1)
10
14
  rake (10.1.1)
11
15
  redis (3.0.7)
12
16
 
@@ -16,4 +20,6 @@ PLATFORMS
16
20
  DEPENDENCIES
17
21
  backrub!
18
22
  bundler (~> 1.5)
23
+ minitest
24
+ mocha
19
25
  rake
data/Rakefile CHANGED
@@ -1 +1,13 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ desc "Run tests"
13
+ task :default => :test
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.5"
23
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "mocha"
24
26
  end
@@ -1,7 +1,7 @@
1
1
  require 'redis'
2
2
 
3
3
  module Backrub
4
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
5
5
 
6
6
  DEFAULT_BACKLOG_SIZE = 100
7
7
 
@@ -21,12 +21,19 @@ module Backrub
21
21
  raise ArgumentError.new "You have to pass at least one channel" if channels.count.zero?
22
22
 
23
23
  if channels.count == 1 && channels.first.is_a?(Hash)
24
- channels.first.each do |channel, offset|
25
- redis.lrange(channel, 0, offset - 1).reverse_each do |message|
26
- yield channel, message
24
+ hash = channels.first
25
+
26
+ hash.each do |channel, offset|
27
+ if offset > 0
28
+ backlog = redis.lrange(channel, 0, offset - 1)
29
+
30
+ backlog.reverse_each do |message|
31
+ yield channel.to_s, message
32
+ end
27
33
  end
28
34
  end
29
- channels = channels.first.keys
35
+
36
+ channels = hash.keys
30
37
  end
31
38
 
32
39
  begin
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class BackrubTest < MiniTest::Unit::TestCase
4
+ def test_publishing_messages
5
+ channel = "test"
6
+ message = "data"
7
+ Backrub.redis.expects(:publish).with(channel, message)
8
+ Backrub.redis.expects(:lpush).with(channel, message)
9
+ Backrub.redis.expects(:ltrim).with(channel, 0, Backrub::DEFAULT_BACKLOG_SIZE - 1)
10
+
11
+ Backrub.publish(channel, message)
12
+ end
13
+
14
+ def test_subscribing
15
+ fake_redis = mock()
16
+ subscribe_object = mock()
17
+ subscribe_object.expects(:message).yields(["test", "data"])
18
+ fake_redis.expects(:subscribe).with("test").yields(subscribe_object)
19
+ fake_redis.expects(:quit)
20
+
21
+ Backrub.expects(:new_redis).returns(fake_redis)
22
+
23
+ Backrub.subscribe("test") do |channel, message|
24
+ assert_equal "test", channel
25
+ assert_equal "data", message
26
+ end
27
+ end
28
+
29
+ def test_subscribing_with_hash_backlog
30
+ channels = {
31
+ first_channel: 0,
32
+ second_channel: 2
33
+ }
34
+ second_channel_data = ["first_bit", "second_bit"]
35
+ Backrub.redis.expects(:lrange).with(:second_channel, 0, 1).returns(second_channel_data.dup)
36
+ second_channel_data.unshift("third_bit")
37
+
38
+ fake_redis = mock()
39
+ subscribe_object = mock()
40
+ subscribe_object.expects(:message).yields(["second_channel", "third_bit"])
41
+
42
+ fake_redis.expects(:subscribe).with(:first_channel, :second_channel).yields(subscribe_object)
43
+ fake_redis.expects(:quit)
44
+
45
+ Backrub.expects(:new_redis).returns(fake_redis)
46
+
47
+ Backrub.subscribe(channels) do |channel, message|
48
+ assert_equal "second_channel", channel
49
+ assert_equal second_channel_data.pop, message
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'mocha/mini_test'
4
+
5
+ require 'backrub'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backrub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Redis-based pubsub system with a backlog
56
84
  email:
57
85
  - boukevanderbijl@gmail.com
@@ -67,6 +95,8 @@ files:
67
95
  - Rakefile
68
96
  - backrub.gemspec
69
97
  - lib/backrub.rb
98
+ - test/backrub_test.rb
99
+ - test/test_helper.rb
70
100
  homepage: ''
71
101
  licenses:
72
102
  - MIT
@@ -91,5 +121,7 @@ rubygems_version: 2.2.0
91
121
  signing_key:
92
122
  specification_version: 4
93
123
  summary: Redis-based pubsub system with a backlog
94
- test_files: []
124
+ test_files:
125
+ - test/backrub_test.rb
126
+ - test/test_helper.rb
95
127
  has_rdoc: