- all_posts/0 now excludes posts where date > today - all_tags/0 computed at runtime from filtered posts - posts_by_tag/1 and recent_posts/1 inherit date filtering - Add unfiltered_posts/0 to Blog macro and FakeBlog - Add all_posts_unfiltered/0 to Registry for dashboard use
57 lines
1.3 KiB
Elixir
57 lines
1.3 KiB
Elixir
defmodule Blogex.Test.Setup do
|
|
@moduledoc """
|
|
Reusable setup blocks for blog tests.
|
|
"""
|
|
|
|
import Blogex.Test.PostBuilder
|
|
|
|
@doc """
|
|
Starts a FakeBlog with a standard set of posts.
|
|
Returns `%{blog: module, posts: posts}`.
|
|
"""
|
|
def with_blog(context \\ %{}, opts \\ []) do
|
|
posts = Keyword.get(opts, :posts, default_posts())
|
|
blog_opts = Keyword.drop(opts, [:posts])
|
|
|
|
{:ok, _} = Blogex.Test.FakeBlog.start(posts, blog_opts)
|
|
|
|
Map.merge(context, %{blog: Blogex.Test.FakeBlog, posts: posts})
|
|
end
|
|
|
|
@doc "A small set of posts covering common scenarios."
|
|
def default_posts do
|
|
[
|
|
build(
|
|
id: "newest-post",
|
|
date: ~D[2026-03-10],
|
|
tags: ["elixir", "otp"],
|
|
published: true
|
|
),
|
|
build(
|
|
id: "middle-post",
|
|
date: ~D[2026-02-15],
|
|
tags: ["elixir", "testing"],
|
|
published: true
|
|
),
|
|
build(
|
|
id: "oldest-post",
|
|
date: ~D[2026-01-05],
|
|
tags: ["devops"],
|
|
published: true
|
|
),
|
|
build(
|
|
id: "draft-post",
|
|
date: ~D[2026-03-12],
|
|
tags: ["elixir"],
|
|
published: false
|
|
),
|
|
build(
|
|
id: "future-post",
|
|
date: ~D[2099-01-01],
|
|
tags: ["future-only"],
|
|
published: true
|
|
)
|
|
]
|
|
end
|
|
end
|