leaderboard 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ describe 'Leaderboard (reverse option)' do
5
5
  @redis_connection = Redis.new(:host => "127.0.0.1", :db => 15)
6
6
  @leaderboard = Leaderboard.new('name', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS.merge({:reverse => true}), :host => "127.0.0.1", :db => 15)
7
7
  end
8
-
8
+
9
9
  after(:each) do
10
10
  @redis_connection.flushdb
11
11
  @leaderboard.disconnect
@@ -21,29 +21,29 @@ describe 'Leaderboard (reverse option)' do
21
21
 
22
22
  it 'should return the correct list when calling leaders' do
23
23
  rank_members_in_leaderboard(25)
24
-
24
+
25
25
  @leaderboard.total_members.should be(25)
26
26
 
27
27
  leaders = @leaderboard.leaders(1)
28
-
28
+
29
29
  leaders.size.should be(25)
30
- leaders[0][:member].should == 'member_1'
31
- leaders[-2][:member].should == 'member_24'
32
- leaders[-1][:member].should == 'member_25'
30
+ leaders[0][:member].should eql('member_1')
31
+ leaders[-2][:member].should eql('member_24')
32
+ leaders[-1][:member].should eql('member_25')
33
33
  leaders[-1][:score].to_i.should be(25)
34
34
  end
35
35
 
36
36
  it 'should return the correct list when calling members' do
37
37
  rank_members_in_leaderboard(25)
38
-
38
+
39
39
  @leaderboard.total_members.should be(25)
40
40
 
41
41
  members = @leaderboard.members(1)
42
-
42
+
43
43
  members.size.should be(25)
44
- members[0][:member].should == 'member_1'
45
- members[-2][:member].should == 'member_24'
46
- members[-1][:member].should == 'member_25'
44
+ members[0][:member].should eql('member_1')
45
+ members[-2][:member].should eql('member_24')
46
+ members[-1][:member].should eql('member_25')
47
47
  members[-1][:score].to_i.should be(25)
48
48
  end
49
49
 
@@ -53,31 +53,31 @@ describe 'Leaderboard (reverse option)' do
53
53
  members = @leaderboard.members_from_score_range(10, 15, {:with_scores => false, :with_rank => false})
54
54
 
55
55
  member_10 = {:member => 'member_10'}
56
- members[0].should == member_10
56
+ members[0].should eql(member_10)
57
57
 
58
58
  member_15 = {:member => 'member_15'}
59
- members[5].should == member_15
59
+ members[5].should eql(member_15)
60
60
 
61
61
  members = @leaderboard.members_from_score_range(10, 15, {:with_scores => true, :with_rank => true, :with_member_data => true})
62
62
 
63
63
  member_10 = {:member => 'member_10', :rank => 10, :score => 10.0, :member_data => {'member_name' => 'Leaderboard member 10'}}
64
- members[0].should == member_10
64
+ members[0].should eql(member_10)
65
65
 
66
66
  member_15 = {:member => 'member_15', :rank => 15, :score => 15.0, :member_data => {'member_name' => 'Leaderboard member 15'}}
67
- members[5].should == member_15
67
+ members[5].should eql(member_15)
68
68
  end
69
69
 
70
70
  it 'should allow you to retrieve leaders without scores and ranks' do
71
71
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE)
72
-
72
+
73
73
  @leaderboard.total_members.should be(Leaderboard::DEFAULT_PAGE_SIZE)
74
74
  leaders = @leaderboard.leaders(1, {:with_scores => false, :with_rank => false})
75
75
 
76
76
  member_1 = {:member => 'member_1'}
77
- leaders[0].should == member_1
78
-
77
+ leaders[0].should eql(member_1)
78
+
79
79
  member_25 = {:member => 'member_25'}
80
- leaders[24].should == member_25
80
+ leaders[24].should eql(member_25)
81
81
  end
82
82
 
83
83
  it 'should allow you to call leaders with various options that respect the defaults for the options not passed in' do
@@ -85,90 +85,90 @@ describe 'Leaderboard (reverse option)' do
85
85
 
86
86
  leaders = @leaderboard.leaders(1, :page_size => 1)
87
87
  leaders.size.should be(1)
88
-
88
+
89
89
  leaders = @leaderboard.leaders(1, :with_rank => false)
90
90
  leaders.size.should be(Leaderboard::DEFAULT_PAGE_SIZE)
91
- member_1 = {:member => 'member_1', :score => 1}
92
- member_2 = {:member => 'member_2', :score => 2}
93
- member_3 = {:member => 'member_3', :score => 3}
94
- leaders[0].should == member_1
95
- leaders[1].should == member_2
96
- leaders[2].should == member_3
91
+ member_1 = {:member => 'member_1', :score => 1.0}
92
+ member_2 = {:member => 'member_2', :score => 2.0}
93
+ member_3 = {:member => 'member_3', :score => 3.0}
94
+ leaders[0].should eql(member_1)
95
+ leaders[1].should eql(member_2)
96
+ leaders[2].should eql(member_3)
97
97
 
98
98
  leaders = @leaderboard.leaders(1, :with_scores => false)
99
99
  leaders.size.should be(Leaderboard::DEFAULT_PAGE_SIZE)
100
100
  member_1 = {:member => 'member_1', :rank => 1}
101
101
  member_2 = {:member => 'member_2', :rank => 2}
102
- leaders[0].should == member_1
103
- leaders[1].should == member_2
102
+ leaders[0].should eql(member_1)
103
+ leaders[1].should eql(member_2)
104
104
 
105
105
  leaders = @leaderboard.leaders(1, :with_scores => false, :with_rank => false)
106
106
  leaders.size.should be(Leaderboard::DEFAULT_PAGE_SIZE)
107
107
  member_1 = {:member => 'member_1'}
108
108
  member_2 = {:member => 'member_2'}
109
- leaders[0].should == member_1
110
- leaders[1].should == member_2
109
+ leaders[0].should eql(member_1)
110
+ leaders[1].should eql(member_2)
111
111
 
112
112
  leaders = @leaderboard.leaders(1, :with_rank => false, :page_size => 1)
113
113
  leaders.size.should be(1)
114
- member_1 = {:member => 'member_1', :score => 1}
115
- leaders[0].should == member_1
114
+ member_1 = {:member => 'member_1', :score => 1.0}
115
+ leaders[0].should eql(member_1)
116
116
  end
117
117
 
118
118
  it 'should return a single member when calling member_at' do
119
119
  rank_members_in_leaderboard(50)
120
- @leaderboard.member_at(1)[:rank].should == 1
121
- @leaderboard.member_at(1)[:score].should == 1.0
122
- @leaderboard.member_at(26)[:rank].should == 26
123
- @leaderboard.member_at(50)[:rank].should == 50
120
+ @leaderboard.member_at(1)[:rank].should eql(1)
121
+ @leaderboard.member_at(1)[:score].should eql(1.0)
122
+ @leaderboard.member_at(26)[:rank].should eql(26)
123
+ @leaderboard.member_at(50)[:rank].should eql(50)
124
124
  @leaderboard.member_at(51).should be_nil
125
- @leaderboard.member_at(1, :with_member_data => true)[:member_data].should == {'member_name' => 'Leaderboard member 1'}
126
- @leaderboard.member_at(1, :use_zero_index_for_rank => true)[:rank].should == 0
125
+ @leaderboard.member_at(1, :with_member_data => true)[:member_data].should eql({'member_name' => 'Leaderboard member 1'})
126
+ @leaderboard.member_at(1, :use_zero_index_for_rank => true)[:rank].should eql(0)
127
127
  end
128
128
 
129
129
  it 'should return the correct information when calling around_me' do
130
130
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE * 3 + 1)
131
131
 
132
132
  @leaderboard.total_members.should be(Leaderboard::DEFAULT_PAGE_SIZE * 3 + 1)
133
-
133
+
134
134
  leaders_around_me = @leaderboard.around_me('member_30')
135
135
  (leaders_around_me.size / 2).should be(@leaderboard.page_size / 2)
136
-
136
+
137
137
  leaders_around_me = @leaderboard.around_me('member_76')
138
138
  leaders_around_me.size.should be(@leaderboard.page_size / 2 + 1)
139
-
139
+
140
140
  leaders_around_me = @leaderboard.around_me('member_1')
141
141
  (leaders_around_me.size / 2).should be(@leaderboard.page_size / 2)
142
142
  end
143
143
 
144
144
  it 'should return the correct information when calling ranked_in_list' do
145
145
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE)
146
-
146
+
147
147
  @leaderboard.total_members.should be(Leaderboard::DEFAULT_PAGE_SIZE)
148
-
148
+
149
149
  members = ['member_1', 'member_5', 'member_10']
150
150
  ranked_members = @leaderboard.ranked_in_list(members, Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS)
151
-
151
+
152
152
  ranked_members.size.should be(3)
153
153
 
154
- ranked_members[0][:rank].should == 1
155
- ranked_members[0][:score].should == 1
154
+ ranked_members[0][:rank].should eql(1)
155
+ ranked_members[0][:score].should eql(1.0)
156
156
 
157
- ranked_members[1][:rank].should == 5
158
- ranked_members[1][:score].should == 5
157
+ ranked_members[1][:rank].should eql(5)
158
+ ranked_members[1][:score].should eql(5.0)
159
159
 
160
- ranked_members[2][:rank].should == 10
161
- ranked_members[2][:score].should == 10
160
+ ranked_members[2][:rank].should eql(10)
161
+ ranked_members[2][:score].should eql(10.0)
162
162
  end
163
163
 
164
164
  it 'should return the correct information when calling ranked_in_list without scores' do
165
165
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE)
166
-
166
+
167
167
  @leaderboard.total_members.should be(Leaderboard::DEFAULT_PAGE_SIZE)
168
-
168
+
169
169
  members = ['member_1', 'member_5', 'member_10']
170
170
  ranked_members = @leaderboard.ranked_in_list(members, {:with_scores => false, :with_rank => true, :use_zero_index_for_rank => false})
171
-
171
+
172
172
  ranked_members.size.should be(3)
173
173
 
174
174
  ranked_members[0][:rank].should be(1)
@@ -180,18 +180,18 @@ describe 'Leaderboard (reverse option)' do
180
180
 
181
181
  it 'should return the correct information when calling score_and_rank_for' do
182
182
  rank_members_in_leaderboard
183
-
183
+
184
184
  data = @leaderboard.score_and_rank_for('member_1')
185
- data[:member].should == 'member_1'
186
- data[:score].should == 1
185
+ data[:member].should eql('member_1')
186
+ data[:score].should eql(1.0)
187
187
  data[:rank].should be(1)
188
188
  end
189
189
 
190
190
  it 'should allow you to remove members in a given score range' do
191
191
  rank_members_in_leaderboard
192
-
192
+
193
193
  @leaderboard.total_members.should be(5)
194
-
194
+
195
195
  @leaderboard.rank_member('cheater_1', 100)
196
196
  @leaderboard.rank_member('cheater_2', 101)
197
197
  @leaderboard.rank_member('cheater_3', 102)
@@ -199,9 +199,9 @@ describe 'Leaderboard (reverse option)' do
199
199
  @leaderboard.total_members.should be(8)
200
200
 
201
201
  @leaderboard.remove_members_in_score_range(100, 102)
202
-
202
+
203
203
  @leaderboard.total_members.should be(5)
204
-
204
+
205
205
  leaders = @leaderboard.leaders(1)
206
206
  leaders.each do |leader|
207
207
  leader[:score].should be < 100
@@ -209,26 +209,26 @@ describe 'Leaderboard (reverse option)' do
209
209
  end
210
210
 
211
211
  it 'should allow you to merge leaderboards' do
212
- foo = Leaderboard.new('foo', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
212
+ foo = Leaderboard.new('foo', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
213
213
  bar = Leaderboard.new('bar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
214
-
214
+
215
215
  foo.rank_member('foo_1', 1)
216
216
  foo.rank_member('foo_2', 2)
217
217
  bar.rank_member('bar_1', 3)
218
218
  bar.rank_member('bar_2', 4)
219
219
  bar.rank_member('bar_3', 5)
220
-
220
+
221
221
  foobar_keys = foo.merge_leaderboards('foobar', ['bar'])
222
222
  foobar_keys.should be(5)
223
-
224
- foobar = Leaderboard.new('foobar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
223
+
224
+ foobar = Leaderboard.new('foobar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
225
225
  foobar.total_members.should be(5)
226
-
226
+
227
227
  first_leader_in_foobar = foobar.leaders(1).first
228
228
  first_leader_in_foobar[:rank].should be(1)
229
- first_leader_in_foobar[:member].should == 'bar_3'
230
- first_leader_in_foobar[:score].should == 5
231
-
229
+ first_leader_in_foobar[:member].should eql('bar_3')
230
+ first_leader_in_foobar[:score].should eql(5.0)
231
+
232
232
  foo.disconnect
233
233
  bar.disconnect
234
234
  foobar.disconnect
@@ -237,25 +237,25 @@ describe 'Leaderboard (reverse option)' do
237
237
  it 'should allow you to intersect leaderboards' do
238
238
  foo = Leaderboard.new('foo', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
239
239
  bar = Leaderboard.new('bar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
240
-
240
+
241
241
  foo.rank_member('foo_1', 1)
242
242
  foo.rank_member('foo_2', 2)
243
243
  foo.rank_member('bar_3', 6)
244
244
  bar.rank_member('bar_1', 3)
245
245
  bar.rank_member('foo_1', 4)
246
246
  bar.rank_member('bar_3', 5)
247
-
248
- foobar_keys = foo.intersect_leaderboards('foobar', ['bar'], {:aggregate => :max})
247
+
248
+ foobar_keys = foo.intersect_leaderboards('foobar', ['bar'], {:aggregate => :max})
249
249
  foobar_keys.should be(2)
250
-
250
+
251
251
  foobar = Leaderboard.new('foobar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
252
252
  foobar.total_members.should be(2)
253
-
253
+
254
254
  first_leader_in_foobar = foobar.leaders(1).first
255
255
  first_leader_in_foobar[:rank].should be(1)
256
- first_leader_in_foobar[:member].should == 'bar_3'
257
- first_leader_in_foobar[:score].should == 6
258
-
256
+ first_leader_in_foobar[:member].should eql('bar_3')
257
+ first_leader_in_foobar[:score].should eql(6.0)
258
+
259
259
  foo.disconnect
260
260
  bar.disconnect
261
261
  foobar.disconnect
@@ -263,14 +263,14 @@ describe 'Leaderboard (reverse option)' do
263
263
 
264
264
  it 'should respect the with_scores option in the massage_leader_data method' do
265
265
  rank_members_in_leaderboard(25)
266
-
266
+
267
267
  @leaderboard.total_members.should be(25)
268
268
 
269
269
  leaders = @leaderboard.leaders(1, {:with_scores => false, :with_rank => false})
270
270
  leaders[0][:member].should_not be_nil
271
271
  leaders[0][:score].should be_nil
272
272
  leaders[0][:rank].should be_nil
273
-
273
+
274
274
  @leaderboard.page_size = 25
275
275
  leaders = @leaderboard.leaders(1, {:with_scores => false, :with_rank => false})
276
276
  leaders.size.should be(25)
@@ -280,7 +280,7 @@ describe 'Leaderboard (reverse option)' do
280
280
  leaders[0][:member].should_not be_nil
281
281
  leaders[0][:score].should_not be_nil
282
282
  leaders[0][:rank].should_not be_nil
283
-
283
+
284
284
  @leaderboard.page_size = 25
285
285
  leaders = @leaderboard.leaders(1, Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS)
286
286
  leaders.size.should be(25)
@@ -288,21 +288,21 @@ describe 'Leaderboard (reverse option)' do
288
288
 
289
289
  it 'should return the correct number of members when calling around_me with a page_size options' do
290
290
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE * 3 + 1)
291
-
291
+
292
292
  leaders_around_me = @leaderboard.around_me('member_30', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS.merge({:page_size => 3}))
293
293
  leaders_around_me.size.should be(3)
294
- leaders_around_me[2][:member].should == 'member_31'
295
- leaders_around_me[0][:member].should == 'member_29'
294
+ leaders_around_me[2][:member].should eql('member_31')
295
+ leaders_around_me[0][:member].should eql('member_29')
296
296
  end
297
297
 
298
298
  it 'should return the correct information when calling percentile_for' do
299
299
  rank_members_in_leaderboard(12)
300
-
301
- @leaderboard.percentile_for('member_1').should == 100
302
- @leaderboard.percentile_for('member_2').should == 91
303
- @leaderboard.percentile_for('member_3').should == 83
304
- @leaderboard.percentile_for('member_4').should == 75
305
- @leaderboard.percentile_for('member_12').should == 8
300
+
301
+ @leaderboard.percentile_for('member_1').should eql(100)
302
+ @leaderboard.percentile_for('member_2').should eql(91)
303
+ @leaderboard.percentile_for('member_3').should eql(83)
304
+ @leaderboard.percentile_for('member_4').should eql(75)
305
+ @leaderboard.percentile_for('member_12').should eql(8)
306
306
  end
307
307
 
308
308
  it 'should return the correct page when calling page_for a given member in the leaderboard' do
@@ -325,13 +325,33 @@ describe 'Leaderboard (reverse option)' do
325
325
  @leaderboard.total_members.should be(0)
326
326
  @leaderboard.rank_members('member_1', 1, 'member_10', 10)
327
327
  @leaderboard.total_members.should be(2)
328
- @leaderboard.leaders(1).first[:member].should == 'member_1'
328
+ @leaderboard.leaders(1).first[:member].should eql('member_1')
329
329
  end
330
330
 
331
331
  it 'should allow you to rank multiple members with an array' do
332
332
  @leaderboard.total_members.should be(0)
333
333
  @leaderboard.rank_members(['member_1', 1, 'member_10', 10])
334
334
  @leaderboard.total_members.should be(2)
335
- @leaderboard.leaders(1).first[:member].should == 'member_1'
335
+ @leaderboard.leaders(1).first[:member].should eql('member_1')
336
+ end
337
+
338
+ it 'should allow you to retrieve a given set of members from the leaderboard in a rank range' do
339
+ rank_members_in_leaderboard(25)
340
+
341
+ members = @leaderboard.members_from_rank_range(5, 9)
342
+ members.size.should be(5)
343
+ members[0][:member].should eql('member_5')
344
+ members[0][:score].to_i.should be(5)
345
+ members[4][:member].should eql('member_9')
346
+
347
+ members = @leaderboard.members_from_rank_range(1, 1)
348
+ members.size.should be(1)
349
+ members[0][:member].should eql('member_1')
350
+
351
+ members = @leaderboard.members_from_rank_range(-1, 26)
352
+ members.size.should be(25)
353
+ members[0][:member].should eql('member_1')
354
+ members[0][:score].to_i.should be(1)
355
+ members[24][:member].should eql('member_25')
336
356
  end
337
357
  end
data/spec/version_spec.rb CHANGED
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Leaderboard::VERSION' do
4
4
  it 'should be the correct version' do
5
- Leaderboard::VERSION.should == '2.4.0'
5
+ Leaderboard::VERSION.should == '2.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaderboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -77,11 +77,9 @@ files:
77
77
  - leaderboard.gemspec
78
78
  - lib/leaderboard.rb
79
79
  - lib/leaderboard/version.rb
80
- - spec/db/.gitkeep
81
80
  - spec/leaderboard_spec.rb
82
81
  - spec/reverse_leaderboard_spec.rb
83
82
  - spec/spec_helper.rb
84
- - spec/test.conf
85
83
  - spec/version_spec.rb
86
84
  homepage: https://github.com/agoragames/leaderboard
87
85
  licenses: []
@@ -97,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
95
  version: '0'
98
96
  segments:
99
97
  - 0
100
- hash: -2580404106533235495
98
+ hash: 1313694139295611168
101
99
  required_rubygems_version: !ruby/object:Gem::Requirement
102
100
  none: false
103
101
  requirements:
@@ -106,17 +104,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  version: '0'
107
105
  segments:
108
106
  - 0
109
- hash: -2580404106533235495
107
+ hash: 1313694139295611168
110
108
  requirements: []
111
109
  rubyforge_project: leaderboard
112
- rubygems_version: 1.8.23
110
+ rubygems_version: 1.8.24
113
111
  signing_key:
114
112
  specification_version: 3
115
113
  summary: Leaderboards backed by Redis in Ruby
116
114
  test_files:
117
- - spec/db/.gitkeep
118
115
  - spec/leaderboard_spec.rb
119
116
  - spec/reverse_leaderboard_spec.rb
120
117
  - spec/spec_helper.rb
121
- - spec/test.conf
122
118
  - spec/version_spec.rb