diff --git a/lib/kredis/types/unique_list.rb b/lib/kredis/types/unique_list.rb index 21ce068..669923f 100644 --- a/lib/kredis/types/unique_list.rb +++ b/lib/kredis/types/unique_list.rb @@ -16,7 +16,7 @@ def append(elements) multi do remove elements super - ltrim (limit - 1), -1 if limit + ltrim -limit, -1 if limit end if Array(elements).flatten.any? end alias << append diff --git a/test/types/unique_list_test.rb b/test/types/unique_list_test.rb index 66ec1b2..ee46a75 100644 --- a/test/types/unique_list_test.rb +++ b/test/types/unique_list_test.rb @@ -1,7 +1,7 @@ require "test_helper" class UniqueListTest < ActiveSupport::TestCase - setup { @list = Kredis.unique_list "myuniquelist" } + setup { @list = Kredis.unique_list "myuniquelist", limit: 5 } test "append" do @list.append(%w[ 1 2 3 ]) @@ -51,4 +51,16 @@ class UniqueListTest < ActiveSupport::TestCase @list.append [ 1, 2 ] assert @list.exists? end + + test "appending over limit" do + @list.append(%w[ 1 2 3 4 5 ]) + @list.append(%w[ 6 7 8 ]) + assert_equal %w[ 4 5 6 7 8 ], @list.elements + end + + test "prepending over limit" do + @list.prepend(%w[ 1 2 3 4 5 ]) + @list.prepend(%w[ 6 7 8 ]) + assert_equal %w[ 8 7 6 5 4 ], @list.elements + end end