 
   alias CoursePlanner.{Tasks, Tasks.Task}
   import CoursePlanner.Factory
+
+  defp adds_extra_volunteer_without_check(%{task: task, volunteers: volunteers}) do
+    changeset =
+      task
+      |> Repo.preload([:volunteers])
+      |> Task.changeset()
+
+    changeset = Task.put_assoc(changeset, :volunteers, volunteers)
+    Repo.update(changeset)
+  end
 
   describe "tests tasks sorting functionality when" do
     test "query without sort option" do

      [applicable_task] = Tasks.get_for_user(nil, volunteer.id, Timex.now())
      assert applicable_task.id == task.id
    end
  end
end

      volunteer = insert(:volunteer)
      insert_list(5, :task)
      assert [] == Tasks.get_past(nil, volunteer.id, Timex.shift(Timex.now(), days: 10))
    end

    test "return even if max_volunteers is surpassed" do
      [volunteer1, volunteer2] = insert_list(2, :volunteer)
      {:ok, task} =  adds_extra_volunteer_without_check(%{task: insert(:task, max_volunteers: 1),
                                                        volunteers: [volunteer1, volunteer2]})

      [applicable_task] = Tasks.get_past(nil, volunteer1.id, Timex.shift(Timex.now(), days: 20))
      assert length(applicable_task.volunteers) > applicable_task.max_volunteers
      assert applicable_task.id == task.id
    end
  end

