Using ex machina version 2.3
i have this factory
def lab_factory do
%Lab{
email: sequence(:email, &"email-#{&1}@example.com"),
name_of_lab: "some lab",
phone: "some phone",
cac_reg_number: "RV9199",
head_scientist_licence_code: "829928838838",
address: "some address",
verified: true,
active: true,
suspended: false,
location: build(:location)
}
expected this will work in my test:
describe "lab" do
location = insert(:location)
@valid_attrs %{
email: "imagediagnostics@gmail.com",
name_of_lab: "some lab",
phone: "some phone",
cac_reg_number: "RV9199",
head_scientist_licence_code: "829928838838",
address: "some address",
verified: true,
active: true,
suspended: false,
location_id: location.id
}
@update_attrs %{
email: "imagediagnostics@gmail.com",
name_of_lab: some lab",
phone: "some phone",
cac_reg_number: "RV9199",
head_scientist_licence_code: "829928838838",
address: "some address",
verified: true,
active: true,
suspended: false,
location_id: location.id
}
@invalid_attrs %{
email: nil,
name_of_lab: nil,
phone: nil,
cac_reg_number: nil,
head_scientist_licence_code: nil,
address: nil,
verified: nil,
active: nil,
suspended: nil,
location_id: nil
}
test "list_location/0 returns all location" do
location = insert(:location)
lab = insert(:lab, location: location)
assert Accounts.list_lab() == [lab]
end
test "get_lab!/1 returns the lab with given id" do
location = insert(:location)
lab = insert(:lab, location: location)
assert Accounts.get_lab!(lab.id) == lab
end
test "create_lab/1 with valid data creates a lab" do
location = insert(:location)
assert {:ok, %Lab{} = lab} = Accounts.create_lab(@valid_attrs)
assert lab.email == "imagediagnostics@gmail.com"
assert lab.name_of_lab == "some lab"
assert lab.phone == "some phone"
assert lab.cac_reg_number == "RV919920202"
assert lab.head_scientist_licence_code == "829928838838"
assert lab.address == "some address"
assert lab.verified == true
assert lab.active == true
assert lab.suspended == false
assert lab.location_id == location.id
end
test "create_lab/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_lab(@invalid_attrs)
end
test "update_lab/2 with valid data updates the lab" do
location = insert(:location)
lab = insert(:lab)
assert {:ok, %Lab{} = lab} = Accounts.update_lab(lab, @update_attrs)
assert lab.email == "imagediagnostics@gmail.com"
assert lab.name_of_lab == "some lab"
assert lab.phone == "08178891028"
assert lab.cac_reg_number == "RV9199"
assert lab.head_scientist_licence_code == "829928838838"
assert lab.address == "some address"
assert lab.verified == true
assert lab.active == true
assert lab.suspended == false
assert lab.location_id == location.id
end
test "update_lab/2 with invalid data returns error changeset" do
lab = insert(:lab)
assert {:error, %Ecto.Changeset{}} = Accounts.update_lab(lab, @invalid_attrs)
assert lab == Accounts.get_lab!(lab.id)
end
test "delete_lab/1 deletes the lab" do
lab = insert(:lab)
assert {:ok, %lab{}} = Accounts.delete_lab(lab)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_lab!(lab.id) end
end
end
but i get this error when i run the test
== Compilation error in file test/my_app/accounts_test.exs ==
** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.534.0>.
When using ownership, you must manage connections in one
of the four ways:
* By explicitly checking out a connection
* By explicitly allowing a spawned process
* By running the pool in shared mode
* By using :caller option with allowed process
The first two options require every new process to explicitly
check a connection out or be allowed by calling checkout or
allow respectively.
The third option requires a {:shared, pid} mode to be set.
If using shared mode in tests, make sure your tests are not
async.
The fourth option requires [caller: pid] to be used when
checking out a connection from the pool. The caller process
should already be allowed on a connection.
If you are reading this error, it means you have not done one
of the steps above or that the owner process has crashed.
See Ecto.Adapters.SQL.Sandbox docs for more information.
(ecto_sql) lib/ecto/adapters/sql.ex:609: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto) lib/ecto/repo/schema.ex:655: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:263: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:164: Ecto.Repo.Schema.insert!/4
test/my_app/accounts_test.exs:582: (module)
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:237: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7