Skip to content

Commit cb647e8

Browse files
authored
fix after_change callback for unique_list (#65)
1 parent 8b77172 commit cb647e8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/kredis/types/callbacks_proxy.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Kredis::Types::CallbacksProxy
1111
Kredis::Types::List => %i[ remove prepend append << ],
1212
Kredis::Types::Scalar => %i[ value= clear ],
1313
Kredis::Types::Set => %i[ add << remove replace take clear ],
14-
Kredis::Types::Slots => %i[ reserve release reset ]
14+
Kredis::Types::Slots => %i[ reserve release reset ],
15+
Kredis::Types::UniqueList => %i[ remove prepend append << ]
1516
}
1617

1718
def initialize(type, callback)

test/attributes_callbacks_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def id
1818
assert_callback_executed_for :kredis_list, :method, ->(type) { type << %w[ david kasper ] }
1919
end
2020

21+
test "unique_list with after_change callback" do
22+
assert_callback_executed_for :kredis_unique_list, :proc, ->(type) { type.append %w[ david kasper ] }
23+
assert_callback_executed_for :kredis_unique_list, :method, ->(type) { type << %w[ david kasper ] }
24+
end
25+
2126
test "flag with after_change callback" do
2227
assert_callback_executed_for :kredis_flag, :proc, ->(type) { type.mark }
2328
assert_callback_executed_for :kredis_flag, :method, ->(type) { type.mark }

test/callbacks_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,12 @@ class CallbacksTest < ActiveSupport::TestCase
7272

7373
assert_equal 1, @callback_check
7474
end
75+
76+
test "unique list with after_change proc callback" do
77+
@callback_check = nil
78+
names = Kredis.unique_list "names", after_change: ->(list) { @callback_check = list.elements }
79+
names.append %w[ david kasper ]
80+
81+
assert_equal %w[ david kasper ], @callback_check
82+
end
7583
end

0 commit comments

Comments
 (0)