Fix status banner auth check to use current_scope
phx.gen.auth sets current_scope, not current_user. Use !! to ensure boolean for HEEx template and register_and_log_in_user in tests for proper auth session.
This commit is contained in:
parent
88ec475a5b
commit
b6ff541b13
@ -29,7 +29,7 @@ defmodule FirehoseWeb.BlogController do
|
||||
post: post,
|
||||
base_path: blog.base_path(),
|
||||
visibility: visibility,
|
||||
authenticated: conn.assigns[:current_user] != nil
|
||||
authenticated: !!(conn.assigns[:current_scope] && conn.assigns.current_scope.user)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@ -25,23 +25,17 @@ defmodule FirehoseWeb.BlogControllerTest do
|
||||
end
|
||||
|
||||
describe "GET /blog/:blog_id/:slug - status banners" do
|
||||
setup :register_and_log_in_user
|
||||
|
||||
test "authenticated user sees draft banner on draft post", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> init_test_session(%{})
|
||||
|> assign(:current_user, %{id: 1})
|
||||
|> get(~p"/blog/engineering/hello-world")
|
||||
conn = get(conn, ~p"/blog/engineering/hello-world")
|
||||
|
||||
assert html_response(conn, 200) =~ "Draft"
|
||||
assert conn.resp_body =~ "not published"
|
||||
end
|
||||
|
||||
test "authenticated user sees scheduled banner on future post", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> init_test_session(%{})
|
||||
|> assign(:current_user, %{id: 1})
|
||||
|> get(~p"/blog/engineering/future-test-post")
|
||||
conn = get(conn, ~p"/blog/engineering/future-test-post")
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "scheduled for"
|
||||
@ -49,17 +43,15 @@ defmodule FirehoseWeb.BlogControllerTest do
|
||||
end
|
||||
|
||||
test "authenticated user sees no banner on live post", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> init_test_session(%{})
|
||||
|> assign(:current_user, %{id: 1})
|
||||
|> get(~p"/blog/engineering/why-firehose")
|
||||
conn = get(conn, ~p"/blog/engineering/why-firehose")
|
||||
|
||||
response = html_response(conn, 200)
|
||||
refute response =~ "Draft"
|
||||
refute response =~ "scheduled for"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /blog/:blog_id/:slug - no banners for unauthenticated" do
|
||||
test "unauthenticated user sees no banner on draft post", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user