Allow direct access to draft and scheduled posts by slug

This commit is contained in:
Willem van den Ende
2026-04-01 20:39:19 +00:00
parent 370275f7b5
commit 20f12847d6
5 changed files with 23 additions and 11 deletions
+16 -4
View File
@@ -125,10 +125,14 @@ defmodule Blogex.BlogTest do
end
end
test "raises for draft post id", %{blog: blog} do
assert_raise Blogex.NotFoundError, fn ->
blog.get_post!("draft-post")
end
test "returns a future-dated published post by slug", %{blog: blog} do
post = blog.get_post!("future-post")
assert post.id == "future-post"
end
test "returns a draft post by slug", %{blog: blog} do
post = blog.get_post!("draft-post")
assert post.id == "draft-post"
end
end
@@ -136,6 +140,14 @@ defmodule Blogex.BlogTest do
test "returns nil for unknown id", %{blog: blog} do
assert blog.get_post("nope") == nil
end
test "returns a future-dated post", %{blog: blog} do
assert %{id: "future-post"} = blog.get_post("future-post")
end
test "returns a draft post", %{blog: blog} do
assert %{id: "draft-post"} = blog.get_post("draft-post")
end
end
describe "paginate/2" do
+2 -2
View File
@@ -70,10 +70,10 @@ defmodule Blogex.RouterTest do
assert conn.status == 404
end
test "returns 404 for draft post" do
test "returns 200 for draft post accessed by slug" do
conn = call(:get, "/draft")
assert conn.status == 404
assert conn.status == 200
end
end
+2 -2
View File
@@ -78,12 +78,12 @@ defmodule Blogex.Test.FakeBlog do
end
def get_post!(id) do
Enum.find(all_posts(), &(&1.id == id)) ||
Enum.find(unfiltered_posts(), &(&1.id == id)) ||
raise Blogex.NotFoundError, "post #{inspect(id)} not found"
end
def get_post(id) do
Enum.find(all_posts(), &(&1.id == id))
Enum.find(unfiltered_posts(), &(&1.id == id))
end
def paginate(page \\ 1, per_page \\ 10) do