Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created February 24, 2016 15:17
Show Gist options
  • Save bcardarella/ae611b65e1cf891f258c to your computer and use it in GitHub Desktop.
Save bcardarella/ae611b65e1cf891f258c to your computer and use it in GitHub Desktop.
defmodule MyAuthenticator do
def auth(repo, model, id, password) do
user =
model
|> where(id: ^id)
|> preload([:profile])
|> repo.one!()
end
end
defmodule MyAuthenticatorTest do
use ExUnit.Case
defmodule RaiseRepo do
def one!(_),
do: raise Ecto.NoResultsError
end
test "my code" do
assert_raise Ecto.NoResultsError, fn ->
MyAuthenticator.auth(RaiseRepo, User, 1, "password")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment