Fork me on GitHub
#component
<
2018-03-17
>
NaleagDeco22:03:49

Hello! Apologies if this is a beginner question asked somewhere more appropriate, but: I've been trying to convert Eric Normand's article on using database transactions for quicker integration test cleanup into something that works with component. So far I have:

(defn with-transaction-fixture
  [f]
  (let [db (:db *system*)
        spec (:spec db)]
    (dbc/migrate db)
    (sql/with-db-transaction [spec spec]
      (sql/db-set-rollback-only! spec)
      (binding [*system* (assoc-in *system* [:db :spec] spec)]
        (f)))))
which worked well originally, until I put a bunch of my logic into a second component for business logic which uses the db component as a dependency. I could write a second fixture that performs the binding on that second component, but I'm wondering if there's something that wouldn't require a variant for every db-using-component I define and test. This feels like a pattern that should be common and yet I'm not seeing many examples of it in github for some reason (perhaps I don't know the right code-snippet to look for)