Parboil the beans in fresh water for 10 minutes, then drain.
Heat 1 tbsp of the oil in a soup pot over medium heat. Add the onion, bay leaf, and thyme. Cook for several minutes, then add the beans and 6 cups water. Simmer, covered, until the beans are nearly tender, about 30 minutes, adding more water if necessary to keep the beans covered. When nearly tender, season with 1-1/2 teaspoons salt and cook for 15 minutes more or until tender. Let cool in their broth.
In a food processor, coarsely chop the garlic and basil. Scrape down the sides, then add the remaining oil and the cheese. Process until you have a coarse puree, then season with salt and pepper to taste.
Preheat the oven to 350°F. Oil a 2-quart gratin dish.
Cook the pasta in salted water until more al dente than usual since it will cook further, then drain and rinse under cold water.
Combine the pasta, beans, 2 cups of the broth, and the tomatoes in the baking dish. Slip spoonfuls of the pesto and ricotta into the beans, poking them beneath the surface. Lightly press the bread crumbs over the surface, then bake until heated through and browned, about 35 minutes.