Liking cljdoc? Tell your friends :D

toucan.util.test

Utility functions for writing tests with Toucan models.

Utility functions for writing tests with Toucan models.
raw docstring

do-with-tempclj

(do-with-temp model attributes f)

Internal implementation of with-temp (don't call this directly).

Internal implementation of `with-temp` (don't call this directly).
sourceraw docstring

expect-with-tempcljmacro

(expect-with-temp with-temp*-form expected actual)

Combines expect with a with-temp* form. The temporary objects established by with-temp* are available to both EXPECTED and ACTUAL.

(expect-with-temp [Database [{database-id :id}]] database-id (get-most-recent-database-id))

Combines `expect` with a `with-temp*` form. The temporary objects established by `with-temp*` are available
to both EXPECTED and ACTUAL.

(expect-with-temp [Database [{database-id :id}]]
   database-id
   (get-most-recent-database-id))
sourceraw docstring

with-tempcljmacro

(with-temp model [binding-form & [options-map]] & body)

Create a temporary instance of ENTITY bound to BINDING-FORM, execute BODY, then deletes it via delete!.

Our unit tests rely a heavily on the test data and make some assumptions about the DB staying in the same clean state. This allows us to write very concise tests. Generally this means tests should "clean up after themselves" and leave things the way they found them.

with-temp should be preferrable going forward over creating random objects without deleting them afterward.

(with-temp EmailReport [report {:creator_id (user->id :rasta) :name (random-name)}] ...)

Create a temporary instance of ENTITY bound to BINDING-FORM, execute BODY,
then deletes it via `delete!`.

Our unit tests rely a heavily on the test data and make some assumptions about the
DB staying in the same *clean* state. This allows us to write very concise tests.
Generally this means tests should "clean up after themselves" and leave things the
way they found them.

`with-temp` should be preferrable going forward over creating random objects *without*
deleting them afterward.

 (with-temp EmailReport [report {:creator_id (user->id :rasta)
                                 :name       (random-name)}]
   ...)
sourceraw docstring

with-temp*cljmacro

(with-temp* model-bindings & body)

Like with-temp but establishes multiple temporary objects at the same time.

(with-temp* [Database [{database-id :id}] Table [table {:db_id database-id}]] ...)

Like `with-temp` but establishes multiple temporary objects at the same time.

(with-temp* [Database [{database-id :id}]
             Table    [table {:db_id database-id}]]
  ...)
sourceraw docstring

WithTempDefaultscljprotocol

Protocol defining the with-temp-defaults method, which provides default values for new temporary objects.

Protocol defining the `with-temp-defaults` method, which provides default values for new temporary objects.

with-temp-defaultsclj

(with-temp-defaults this)

Return a map of default values that should be used when creating a new temporary object of this model.

;; Use a random first and last name for new temporary Users unless otherwise specified (extend-protocol WithTempDefaults (class User) (with-temp-defaults [_] {:first-name (random-name), :last-name (random-name)}))

Return a map of default values that should be used when creating a new temporary object of this model.

;; Use a random first and last name for new temporary Users unless otherwise specified
(extend-protocol WithTempDefaults
  (class User)
  (with-temp-defaults [_] {:first-name (random-name), :last-name (random-name)}))
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close