Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a disconnect method and test. Also be better about Redis connecti…

…on cleanup in the tests.
  • Loading branch information...
commit d1af2df78f6f1139e27fafd6d599d227a194aa61 1 parent 407d916
@czarneckid czarneckid authored
View
4 CHANGELOG.markdown
@@ -1,3 +1,7 @@
+# leaderboard 1.0.6 (in progress)
+
+ * Added `disconnect` method
+
# leaderboard 1.0.5 (2011-05-04)
* Updated Rakefile to run tests under ruby 1.8.7 and ruby 1.9.2
View
6 lib/leaderboard.rb
@@ -1,7 +1,7 @@
require 'redis'
class Leaderboard
- VERSION = '1.0.5'.freeze
+ VERSION = '1.0.6'.freeze
DEFAULT_PAGE_SIZE = 25
DEFAULT_REDIS_HOST = 'localhost'
@@ -31,6 +31,10 @@ def initialize(leaderboard_name, host = DEFAULT_REDIS_HOST, port = DEFAULT_REDIS
@redis_connection = Redis.new(@redis_options)
end
+
+ def disconnect
+ @redis_connection.client.disconnect
+ end
def add_member(member, score)
add_member_to(@leaderboard_name, member, score)
View
31 test/test_leaderboard.rb
@@ -8,10 +8,12 @@ def setup
def teardown
@redis_connection.flushdb
+ @leaderboard.disconnect
+ @redis_connection.client.disconnect
end
def test_version
- assert_equal '1.0.5', Leaderboard::VERSION
+ assert_equal '1.0.6', Leaderboard::VERSION
end
def test_initialize_with_defaults
@@ -21,10 +23,23 @@ def test_initialize_with_defaults
assert_equal Leaderboard::DEFAULT_PAGE_SIZE, @leaderboard.page_size
end
+ def test_disconnect
+ assert_equal nil, @leaderboard.disconnect
+ end
+
+ def test_will_automatically_reconnect_after_a_disconnect
+ assert_equal 0, @leaderboard.total_members
+ add_members_to_leaderboard(5)
+ assert_equal 5, @leaderboard.total_members
+ assert_equal nil, @leaderboard.disconnect
+ assert_equal 5, @leaderboard.total_members
+ end
+
def test_page_size_is_default_page_size_if_set_to_invalid_value
- @leaderboard = Leaderboard.new('name', 'localhost', 6379, 0)
+ some_leaderboard = Leaderboard.new('name', 'localhost', 6379, 0)
- assert_equal Leaderboard::DEFAULT_PAGE_SIZE, @leaderboard.page_size
+ assert_equal Leaderboard::DEFAULT_PAGE_SIZE, some_leaderboard.page_size
+ some_leaderboard.disconnect
end
def test_add_member_and_total_members
@@ -205,7 +220,7 @@ def test_remove_members_in_score_range
end
def test_merge_leaderboards
- foo = Leaderboard.new('foo')
+ foo = Leaderboard.new('foo')
bar = Leaderboard.new('bar')
foo.add_member('foo_1', 1)
@@ -224,6 +239,10 @@ def test_merge_leaderboards
assert_equal 1, first_leader_in_foobar[:rank]
assert_equal 'bar_3', first_leader_in_foobar[:member]
assert_equal 5, first_leader_in_foobar[:score]
+
+ foo.disconnect
+ bar.disconnect
+ foobar.disconnect
end
def test_intersect_leaderboards
@@ -247,6 +266,10 @@ def test_intersect_leaderboards
assert_equal 1, first_leader_in_foobar[:rank]
assert_equal 'bar_3', first_leader_in_foobar[:member]
assert_equal 6, first_leader_in_foobar[:score]
+
+ foo.disconnect
+ bar.disconnect
+ foobar.disconnect
end
def test_massage_leader_data_respects_with_scores
Please sign in to comment.
Something went wrong with that request. Please try again.