Refactor conn aliasing in controller tests to use pipe chains

Applied refactor_conn_aliasing.sh to eliminate conn shadowing.

Show draft posts in test and dev
This commit is contained in:
Willem van den Ende
2026-03-20 21:36:08 +00:00
parent c18f9cd2e3
commit 9426582abc
7 changed files with 74 additions and 52 deletions
+5
View File
@@ -110,6 +110,11 @@ defmodule Blogex do
* `Blogex.Router` — mountable Plug router
"""
@doc "Returns true if draft posts should be visible (dev/test environments)."
def show_drafts? do
Application.get_env(:blogex, :show_drafts, false)
end
defdelegate blogs, to: Blogex.Registry
defdelegate get_blog!(blog_id), to: Blogex.Registry
defdelegate get_blog(blog_id), to: Blogex.Registry
+8 -2
View File
@@ -73,8 +73,14 @@ defmodule Blogex.Blog do
@doc "Returns the base URL path for this blog."
def base_path, do: @blog_base_path
@doc "Returns all published posts, newest first."
def all_posts, do: Enum.filter(@posts, & &1.published)
@doc "Returns all visible posts, newest first. Drafts are included in dev/test."
def all_posts do
if Blogex.show_drafts?() do
@posts
else
Enum.filter(@posts, & &1.published)
end
end
@doc "Returns the N most recent published posts."
def recent_posts(n \\ 5), do: Enum.take(all_posts(), n)