Created
February 24, 2016 15:17
-
-
Save bcardarella/ae611b65e1cf891f258c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyAuthenticator do | |
def auth(repo, model, id, password) do | |
user = | |
model | |
|> where(id: ^id) | |
|> preload([:profile]) | |
|> repo.one!() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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