Skip to content

Commit

Permalink
509 bug recurring pet task (#518)
Browse files Browse the repository at this point in the history
* commit annotation change

* add tests for completing a recurring task with a due date

* update task update action to not remove next due in days when completing task
  • Loading branch information
MooseCowBear authored Mar 9, 2024
1 parent 35943c6 commit 1c78c92
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/organizations/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def edit
end

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

if @task.update(task_params)
if @task.recurring && @task.completed_previously_changed?(from: false, to: true)
Expand Down
4 changes: 2 additions & 2 deletions app/models/adopter_foster_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#
# Indexes
#
# index_adopter_profiles_on_adopter_account_id (adopter_account_id)
# index_adopter_profiles_on_location_id (location_id)
# index_adopter_foster_profiles_on_adopter_account_id (adopter_account_id)
# index_adopter_foster_profiles_on_location_id (location_id)
#
# Foreign Keys
#
Expand Down
14 changes: 13 additions & 1 deletion test/controllers/organizations/tasks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class TasksControllerTest < ActionDispatch::IntegrationTest
assert_turbo_stream action: "remove", target: @task
end

test "should create a new task when recurring task is completed" do
test "should create a new task when recurring task without due date is completed" do
task = create(:task, pet: @pet, recurring: true)

assert_difference "Task.count", 1 do
Expand All @@ -147,6 +147,18 @@ class TasksControllerTest < ActionDispatch::IntegrationTest
end
end

test "should create a new task when recurring task with due date is completed" do
task = create(:task, pet: @pet, recurring: true, due_date: Date.today + 2, next_due_date_in_days: 4)

assert_difference "Task.count", 1 do
patch pet_task_path(@pet, task, format: :turbo_stream), params: {
task: {
completed: true
}
}
end
end

test "should not create a new task if non-recurring task is completed" do
task = create(:task, pet: @pet, recurring: false)

Expand Down
16 changes: 15 additions & 1 deletion test/system/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TasksTest < ApplicationSystemTestCase
assert has_current_path?(pet_path(@pet, active_tab: "tasks"))
end

test "marking a recurring task as complete creates and displays a new task without redirecting" do
test "marking a recurring task without due date as complete creates and displays a new task without redirecting" do
recurring_task = create(:task, recurring: true, pet: @pet, name: "recurring task")

visit pet_path(@pet, active_tab: "tasks")
Expand All @@ -52,6 +52,20 @@ class TasksTest < ApplicationSystemTestCase
assert has_current_path?(pet_path(@pet, active_tab: "tasks"))
end

test "marking a recurring task with due date as complete creates and displays a new task without redirecting" do
due_date = (Date.today + 2.days)
recurring_task_with_due_date = create(:task, recurring: true, pet: @pet, name: "recurring task with due date", due_date: due_date, next_due_date_in_days: 4)

visit pet_path(@pet, active_tab: "tasks")

within("#edit_task_#{recurring_task_with_due_date.id}") do
check "task_completed"
end

assert_text("recurring task with due date", count: 2)
assert has_current_path?(pet_path(@pet, active_tab: "tasks"))
end

test "doesn't incomplete completed recurring task" do
recurring_task = create(:task, recurring: true, completed: true, pet: @pet, name: "completed recurring task")
visit pet_path(@pet, active_tab: "tasks")
Expand Down

0 comments on commit 1c78c92

Please sign in to comment.