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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user