Created
February 17, 2016 13:16
-
-
Save sashaafm/2192f3e59ad919e695a0 to your computer and use it in GitHub Desktop.
tests
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
setup %{conn: conn} = config do | |
case config[:login_as] do | |
:client -> | |
user = insert_user username: config[:username] | |
conn = assign conn, :current_user, user | |
{:ok, conn: conn, user: user} | |
:admin -> | |
admin = insert_admin username: config[:username] | |
conn = assign conn, :current_user, admin | |
{:ok, conn: conn, admin: admin} | |
_ -> | |
:ok | |
end | |
end | |
@tag login_as: :client, username: "somename" | |
test "requires admin authentication", %{conn: conn} do | |
Enum.each([ | |
get(conn, admin_path(conn, :index)), | |
get(conn, admin_path(conn, :new)), | |
get(conn, admin_path(conn, :edit, "123")), | |
put(conn, admin_path(conn, :update, "123", %{})), | |
post(conn, admin_path(conn, :create, %{})), | |
delete(conn, admin_path(conn, :delete, "123")), | |
get(conn, admin_path(conn, :get_admin_area)) | |
], fn conn -> | |
assert html_response(conn, 302) | |
assert redirected_to(conn) =~ "/" | |
assert conn.halted | |
end) | |
end | |
@tag login_as: :admin, username: "someadmin" | |
test "get users index", %{conn: conn} do | |
assert (conn.assigns.current_user && | |
conn.assigns.current_user.role == 3) == true | |
conn = get conn, admin_path(conn, :index) | |
assert html_response(conn, 200) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment