Skip to content

Commit

Permalink
handle offset above set range with an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
rfroetscher committed Apr 18, 2016
1 parent 0136520 commit e219019
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fakeredis/sort_method.rb
Expand Up @@ -101,7 +101,7 @@ def slice(sorted, limit)
skip = limit.first || 0
take = limit.last || sorted.length

sorted[skip...(skip + take)] || sorted
sorted[skip...(skip + take)] || []
end

def lookup_from_pattern(pattern, element)
Expand Down
4 changes: 4 additions & 0 deletions spec/support/shared_examples/sortable.rb
Expand Up @@ -53,6 +53,10 @@
it 'only returns requested window in the enumerable' do
expect(@client.sort(@key, :limit => [0, 1])).to eq(['1'])
end

it 'returns an empty array if the offset if more than the length of the list' do
expect(@client.sort(@key, :limit => [3, 1])).to eq([])
end
end

context 'store' do
Expand Down

0 comments on commit e219019

Please sign in to comment.