Skip to content

Commit

Permalink
add test to confirm that has_role/2 works with integers too! e.g. has…
Browse files Browse the repository at this point in the history
…_role(conn, 3) > true #1
  • Loading branch information
nelsonic committed Sep 14, 2020
1 parent ffebff5 commit 0aa6124
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rbac.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ defmodule RBAC do

@doc """
`has_role/2 confirms if the person has the given role
e.g:
has_role(conn, "home_admin") > true
has_role(conn, "potus") > false
"""
def has_role(conn, role_name) do
role = get_role_from_cache(role_name)
Expand Down
15 changes: 15 additions & 0 deletions test/rbac_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,19 @@ defmodule RBACTest do

assert not RBAC.has_role(fake_conn, "non_existent_role")
end


test "RBAC.has_role/1 works with integers too!" do
init()

fake_conn = %{
assigns: %{
person: %{
roles: "1,2,3"
}
}
}

assert RBAC.has_role(fake_conn, 3)
end
end

0 comments on commit 0aa6124

Please sign in to comment.