To add a few more things to what Stranger has said, unstable cases will require cardioversion, as per the ACLS protocol. Consider anticoagulation, as cardioversion restores an organized rhythm in the atria, which may have formed mural thrombi. This is less of a consideration in new or recent-onset a-fib, but becomes much more so in a-fib of prolonged or undeterminate duration. If fibrillation has lasted over 48 hours, there is a 2-5% risk of stroke in cardioversion without anticoagulation.
If the patient is stable, the agents mentioned above may be used for rate or rhythm control. If using rate control, 50-67% of cases will spontaneously cardiovert anyway. If using rhythm control, anticoagulation again becomes an issue. If fibrillation has been present for over 48 hours, you may use TEE to rule out mural thrombi or use therapeutic anticoagulation for 3 weeks prior to conversion. Likelihood of recurrence is highest in first 3 months after conversion, so anticoagulate for 4-12 weeks afterwards as well. Use CHADS2 score beyond that.
For test purposes, according to Conrad Fischer, you don't cardiovert stable patients, and elect for rate control as first choice.