If a defendant unsuccessfully moves to compel arbitration of a lawsuit filed against it, the lawsuit continues in court.  So for purposes of Civ. Code 1717, the plaintiff does not become the prevailing party on the contract simply by defeating the motion to compel arbitration.  However, if not yet having been sued, a party files an independent petition to compel arbitration, an order denying the petition ends the lawsuit.  So in that situation the party that prevailed on the petition to compel arbitration is the prevailing party for purposes of Civ. Code 1717.