Skip to content

Commit db8fc9a

Browse files
authored
Merge pull request #56 from excid3/fix-unique-list-with-limit
Appending to unique list with limit should trim from the end
2 parents 6a5b461 + b8edff2 commit db8fc9a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/kredis/types/unique_list.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def append(elements)
1616
multi do
1717
remove elements
1818
super
19-
ltrim (limit - 1), -1 if limit
19+
ltrim -limit, -1 if limit
2020
end if Array(elements).flatten.any?
2121
end
2222
alias << append

test/types/unique_list_test.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "test_helper"
22

33
class UniqueListTest < ActiveSupport::TestCase
4-
setup { @list = Kredis.unique_list "myuniquelist" }
4+
setup { @list = Kredis.unique_list "myuniquelist", limit: 5 }
55

66
test "append" do
77
@list.append(%w[ 1 2 3 ])
@@ -51,4 +51,16 @@ class UniqueListTest < ActiveSupport::TestCase
5151
@list.append [ 1, 2 ]
5252
assert @list.exists?
5353
end
54+
55+
test "appending over limit" do
56+
@list.append(%w[ 1 2 3 4 5 ])
57+
@list.append(%w[ 6 7 8 ])
58+
assert_equal %w[ 4 5 6 7 8 ], @list.elements
59+
end
60+
61+
test "prepending over limit" do
62+
@list.prepend(%w[ 1 2 3 4 5 ])
63+
@list.prepend(%w[ 6 7 8 ])
64+
assert_equal %w[ 8 7 6 5 4 ], @list.elements
65+
end
5466
end

0 commit comments

Comments
 (0)