Skip to content

Instantly share code, notes, and snippets.

@Fadhil
Last active May 5, 2016 14:36
Show Gist options
  • Save Fadhil/dc427e9d8c01f17576fe3ee7b17d7201 to your computer and use it in GitHub Desktop.
Save Fadhil/dc427e9d8c01f17576fe3ee7b17d7201 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment