Mock hearings, last-minute deals and primary threats helped move controversial nominees through the Senate.