Created
May 5, 2016 14:32
-
-
Save Fadhil/73199e13067559f219b67ab8030d084b to your computer and use it in GitHub Desktop.
This file contains 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 Plug.AnonymousTest do | |
use ExUnit.Case, async: true | |
use Plug.Test | |
alias Plug.Session.COOKIE, as: CookieStore | |
require IEx | |
alias Plug.Anonymous | |
defmodule SomeApp do | |
defmodule SomeController do | |
use Plug.Builder | |
plug Plug.Session, | |
store: :cookie, | |
key: "_wankrank_key", | |
signing_salt: "cmwAUEpB", | |
max_age: 86400 | |
plug :fetch_session | |
plug Anonymous | |
end | |
end | |
@default_opts [ | |
store: :cookie, | |
key: "_wankrank_key", | |
signing_salt: "cmwAUEpB", | |
max_age: 86400 | |
] | |
@custom_serializer_opts Plug.Session.init(@default_opts) | |
test "assigns user_id session key" do | |
conn = conn(:get, "/") |> SomeApp.SomeController.call([]) | |
refute get_session(conn, :anonymous_id) == nil | |
end | |
test "returns existing user session key" do | |
conn = conn(:get, "/") |> Plug.Session.call(@custom_serializer_opts) |> fetch_session | |
conn = put_session(conn, :anonymous_id, "some_id") | |
conn = conn |> SomeApp.SomeController.call([]) | |
# conn = put_session(conn, :anonymous_id, "some_id") | |
# conn = conn |> SomeApp.SomeController.call([]) | |
assert get_session(conn, :anonymous_id) == "some_id" | |
end | |
test "raises Error if User is not provided" do | |
conn = conn(:get, "/") |> SomeApp.SomeController.call([]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment