Skip to content

Commit

Permalink
Removing conditional type coercion for zset.add (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentamoore committed Jul 22, 2021
1 parent 0dc409c commit fc03a07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/mock_redis/zset.rb
Expand Up @@ -23,12 +23,7 @@ def initialize_copy(source)

def add(score, member)
members.add(member)
scores[member] =
if score.to_f.to_i == score.to_f
score.to_f.to_i
else
score.to_f
end
scores[member] = score.to_f
self
end

Expand Down
6 changes: 6 additions & 0 deletions spec/commands/zadd_spec.rb
Expand Up @@ -23,6 +23,12 @@
@redises.zrange(@key, 0, -1).should == [member.to_s]
end

it 'allows scores to be set to Float::INFINITY' do
member = '1'
@redises.zadd(@key, Float::INFINITY, member)
@redises.zrange(@key, 0, -1).should == [member]
end

it 'updates the score' do
@redises.zadd(@key, 1, 'foo')
@redises.zadd(@key, 2, 'foo')
Expand Down

0 comments on commit fc03a07

Please sign in to comment.