Skip to content

Commit 53255f9

Browse files
intripjeremy
authored andcommitted
Add reset to Cycle after_change callbacks
`reset` is a public action exposed by `Cycle` and should be included in the after_change callbacks lifecycle.
1 parent c5d5042 commit 53255f9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/kredis/types/callbacks_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Kredis::Types::CallbacksProxy
44

55
AFTER_CHANGE_OPERATIONS = {
66
Kredis::Types::Counter => %i[ increment decrement reset ],
7-
Kredis::Types::Cycle => %i[ next ],
7+
Kredis::Types::Cycle => %i[ next reset ],
88
Kredis::Types::Enum => %i[ value= reset ],
99
Kredis::Types::Flag => %i[ mark remove ],
1010
Kredis::Types::Hash => %i[ update delete []= remove ],

test/callbacks_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ class CallbacksTest < ActiveSupport::TestCase
7373
assert_equal 1, @callback_check
7474
end
7575

76+
test "cycle with after_change proc callback" do
77+
@callback_check = nil
78+
amount = Kredis.cycle "semaphore_light", after_change: ->(cycle) { @callback_check = cycle.value }, values: %w[ green yellow red ]
79+
80+
amount.next
81+
assert_equal "yellow", @callback_check
82+
83+
amount.reset
84+
assert_equal "green", @callback_check
85+
end
86+
7687
test "unique list with after_change proc callback" do
7788
@callback_check = nil
7889
names = Kredis.unique_list "names", after_change: ->(list) { @callback_check = list.elements }

0 commit comments

Comments
 (0)