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,
|
post: post,
|
||||||
base_path: blog.base_path(),
|
base_path: blog.base_path(),
|
||||||
visibility: visibility,
|
visibility: visibility,
|
||||||
authenticated: conn.assigns[:current_user] != nil
|
authenticated: !!(conn.assigns[:current_scope] && conn.assigns.current_scope.user)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,23 +25,17 @@ defmodule FirehoseWeb.BlogControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /blog/:blog_id/:slug - status banners" do
|
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
|
test "authenticated user sees draft banner on draft post", %{conn: conn} do
|
||||||
conn =
|
conn = get(conn, ~p"/blog/engineering/hello-world")
|
||||||
conn
|
|
||||||
|> init_test_session(%{})
|
|
||||||
|> assign(:current_user, %{id: 1})
|
|
||||||
|> get(~p"/blog/engineering/hello-world")
|
|
||||||
|
|
||||||
assert html_response(conn, 200) =~ "Draft"
|
assert html_response(conn, 200) =~ "Draft"
|
||||||
assert conn.resp_body =~ "not published"
|
assert conn.resp_body =~ "not published"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "authenticated user sees scheduled banner on future post", %{conn: conn} do
|
test "authenticated user sees scheduled banner on future post", %{conn: conn} do
|
||||||
conn =
|
conn = get(conn, ~p"/blog/engineering/future-test-post")
|
||||||
conn
|
|
||||||
|> init_test_session(%{})
|
|
||||||
|> assign(:current_user, %{id: 1})
|
|
||||||
|> get(~p"/blog/engineering/future-test-post")
|
|
||||||
|
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
assert response =~ "scheduled for"
|
assert response =~ "scheduled for"
|
||||||
@ -49,17 +43,15 @@ defmodule FirehoseWeb.BlogControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "authenticated user sees no banner on live post", %{conn: conn} do
|
test "authenticated user sees no banner on live post", %{conn: conn} do
|
||||||
conn =
|
conn = get(conn, ~p"/blog/engineering/why-firehose")
|
||||||
conn
|
|
||||||
|> init_test_session(%{})
|
|
||||||
|> assign(:current_user, %{id: 1})
|
|
||||||
|> get(~p"/blog/engineering/why-firehose")
|
|
||||||
|
|
||||||
response = html_response(conn, 200)
|
response = html_response(conn, 200)
|
||||||
refute response =~ "Draft"
|
refute response =~ "Draft"
|
||||||
refute response =~ "scheduled for"
|
refute response =~ "scheduled for"
|
||||||
end
|
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
|
test "unauthenticated user sees no banner on draft post", %{conn: conn} do
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user