rubyforgood / homeward-tails

Homeward Tails is an application making it easy to link adopters/fosters with pets. We work with grassroots pet rescue organizations to understand how we can make the most impact.
MIT License
69 stars 117 forks source link

Bug: recurring pet task - turbostream when marking complete is returning 400 bad request #509

Closed kasugaijin closed 8 months ago

kasugaijin commented 8 months ago

To reproduce: Go to Pet > Tasks and create a new task that is recurring, has due date in future, and next due at in days. Save it. Then try to mark it complete.

What should happen: the recurring task is marked complete and a new identical, recurring task is created with a new due date and is added to the list of tasks.

What happens: Task does not save due to failed request.

image
MooseCowBear commented 8 months ago

I see the problem.

This line in the update action

@task.next_due_date_in_days = nil unless task_params.dig(:next_due_date_in_days)

was added to handle the case that someone wanted to edit a recurring action to remove the due date. But this isn't quite right because checking complete doesn't send the next_due_in_days field.

If we switch to:

@task.next_due_date_in_days = nil unless task_params.dig(:next_due_date_in_days) || task_params.dig(:completed)

then I think that will solve the problem.

I can make the change and add tests to cover this if you want.

kasugaijin commented 8 months ago

Ah good catch @MooseCowBear ! Assigned.