Gel.Sandbox (Gel v0.9.0)

View Source

Custom connection for tests that involve modifying the database through the driver.

This connection, when started, wraps the actual connection to Gel into a transaction using the start transaction statement. And then further calls to Gel.transaction/3 will result in executing declare savepoint statement instead of start transaction.

To use this module in tests, change the configuration of the :gel application in the config/test.exs:

config :gel,
  connection: Gel.Sandbox

Then modify the test case to initialize the sandbox when you run the test and to clean the sandbox at the end of the test:

defmodule MyApp.TestCase do
  use ExUnit.CaseTemplate

  # other stuff for this case (e.g. Phoenix setup, Plug configuration, etc.)

  setup _context do
    Gel.Sandbox.initialize(MyApp.Gel)

    on_exit(fn ->
      Gel.Sandbox.clean(MyApp.Gel)
    end)

    :ok
  end
end

Summary

Functions

Release the connection transaction.

Wrap a connection in a transaction.

Functions

clean(client)

(since 0.2.0)
@spec clean(GenServer.server()) :: :ok

Release the connection transaction.

initialize(client)

(since 0.2.0)
@spec initialize(GenServer.server()) :: :ok

Wrap a connection in a transaction.