Compare commits
2 Commits
5a7f651547
...
c848ca17ad
| Author | SHA1 | Date | |
|---|---|---|---|
| c848ca17ad | |||
| ca4eaf6f54 |
@ -18,8 +18,12 @@ defmodule BasicSignupWhitelist do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
false
|
||||
iex> System.put_env("SIGNUP_ALLOWED_EMAILS","*")
|
||||
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
true
|
||||
|
||||
"""
|
||||
def mail_whitelisted(email) do
|
||||
|
||||
@ -1,33 +1,29 @@
|
||||
defmodule BasicSignupWhitelistTest do
|
||||
use ExUnit.Case
|
||||
use ExUnit.Case, async: false
|
||||
doctest BasicSignupWhitelist
|
||||
|
||||
defp allow_signups_for(whitelist) do
|
||||
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
||||
end
|
||||
|
||||
setup do
|
||||
# Save original env var
|
||||
original_env = System.get_env("SIGNUP_ALLOWED_EMAILS")
|
||||
describe "setup in describe block" do
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
# resetting values did not work, so 'just' set it to the effect without this module configured.
|
||||
System.put_env("SIGNUP_ALLOWED_EMAILS", "*")
|
||||
end)
|
||||
|
||||
on_exit(fn ->
|
||||
# Restore original env var after each test
|
||||
case original_env do
|
||||
nil -> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||
value -> System.put_env("SIGNUP_ALLOWED_EMAILS", value)
|
||||
end
|
||||
end)
|
||||
:ok
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
test "When not set, not whitelisted" do
|
||||
System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
end
|
||||
|
||||
test "When not set, not whitelisted" do
|
||||
System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
end
|
||||
|
||||
test "When set to star, whitelisted" do
|
||||
allow_signups_for("*")
|
||||
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
test "When set to star, whitelisted" do
|
||||
allow_signups_for("*")
|
||||
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user