agoragames / leaderboard

Leaderboards backed by Redis in Ruby
https://rubygems.org/gems/leaderboard
MIT License
478 stars 65 forks source link

ranked_in_list error when {:with_member_data => true, :include_missing => false} #60

Closed dcampano closed 7 years ago

dcampano commented 7 years ago

I am testing upgrading from version 3.10.0 to 3.11.0 and came across an issue when using ranked_in_list with {:with_member_data => true, :include_missing => false}. The following code runs successfully on 3.10.0 but gets a "NoMethodError: undefined method `[]=' for nil:NilClass" on 3.11.0.

REDIS = Redis.new({:host => '127.0.0.1', :port => 6379, :db => 0})

leaderboard_name = 'testing'
opts = {:redis_connection => REDIS}
@leaderboard = Leaderboard.new(leaderboard_name, {:page_size => 7}, opts)
1.upto(100) do |n|
  @leaderboard.rank_member(n, n * 100)
  @leaderboard.update_member_data(n, "sample member data")
end

ids = [200, 201] #  ids don't exist in the leaderboard
@leaderboard.ranked_in_list(ids, {:with_member_data => true, :include_missing => false})
dcampano commented 7 years ago

Working on a fix for this and will send a pull request.