assert the size of the list in elixir

Kernel.length/1 will return the size of a list:

length([1,2,3]) #3

You can do this from an Ecto query using:

query = from d in Device, where: d.uuid == ^uuid, select: fragment("count(?)", d.id)
assert  Repo.all(query)== 3

In Ecto 2 you can use Repo.aggregate/4

query = from d in Device, where: d.uuid == ^uuid)
assert Repo.aggregate(query, :count, :id) == 3

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)