Skip to content

Commit

Permalink
Patch: do not degister pomodor if it hasn't finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdok committed Apr 19, 2019
1 parent d0f78ce commit 07bfce9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Command = {
onUpdate = function()
Command.pomodoro = Pomodoro.ping(Command.pomodoro)

EVENT_MANAGER:UnregisterForUpdate(Pomodoro.updateId)
if (nil ~= Command.pomodoro.completedAt) then
EVENT_MANAGER:UnregisterForUpdate(Pomodoro.updateId)
end
end,

call = function(argument)
Expand Down
9 changes: 2 additions & 7 deletions src/Pomodoro.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Pomodoro = {
tenSecondsInMilliseconds = 10000,
updateId = 'Pomodoro.onUpdate', -- Seconds = 25 minutes
pomodoroDurationInSeconds = 25, -- 25 minutes
--pomodoroDurationInSeconds = 1500, -- 25 minutes
updateId = 'Pomodoro.onUpdate',
pomodoroDurationInSeconds = 1500, -- 25 minutes
error_already_finished = "Error: Attempting to process finished Pomodoro.\nPlease report this at https://git.io/fjO3p",

new = function()
Expand Down Expand Up @@ -55,8 +54,4 @@ Pomodoro = {

return pomodoro
end,

currentDuration = function()

end
}
10 changes: 10 additions & 0 deletions tests/Unit/Command_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ describe("Command", function()
assert.spy(EVENT_MANAGER.UnregisterForUpdate).was_called_with(EVENT_MANAGER, Pomodoro.updateId)
end)

it("should not deregister if pomodoro hasn't complete", function()
spy.on(EVENT_MANAGER, "UnregisterForUpdate")
Command.call('start')
Command.pomodoro.completedAt = nil
Command.onUpdate()
assert.spy(EVENT_MANAGER.UnregisterForUpdate).was_not_called(

)
end)

it("should deregister when pomodoro is stopped. #cmd_register", function()
stub(_G, EVENT_MANAGER)
Command.call('start')
Expand Down

0 comments on commit 07bfce9

Please sign in to comment.