       applicable_task = Tasks.get_availables(nil, volunteer1.id, Timex.now())
       assert applicable_task == [task1]
     end
+
+    test "does not return even if max_volunteers is surpassed" do
+      [volunteer1, volunteer2, volunteer3] = insert_list(3, :volunteer)
+      [task1, task2] = insert_list(2, :task, max_volunteers: 1)
+      adds_extra_volunteer_without_check(%{task: task1, volunteers: [volunteer1, volunteer2]})
+
+      [applicable_task] = Tasks.get_availables(nil, volunteer3.id, Timex.now())
+      assert applicable_task.id == task2.id
+    end
   end
 
   describe "listing of volunteer's past tasks" do

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


  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
