Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing conditional type coercion for zset.add #214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/mock_redis/zset.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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