diff --git a/blogex/lib/blogex/router.ex b/blogex/lib/blogex/router.ex index 5e611eb..383b0d9 100644 --- a/blogex/lib/blogex/router.ex +++ b/blogex/lib/blogex/router.ex @@ -75,11 +75,14 @@ defmodule Blogex.Router do else conn |> put_resp_content_type("application/json") - |> send_resp(200, Jason.encode!(%{ - blog: blog.blog_id(), - tag: tag, - posts: Enum.map(posts, &post_json/1) - })) + |> send_resp( + 200, + Jason.encode!(%{ + blog: blog.blog_id(), + tag: tag, + posts: Enum.map(posts, &post_json/1) + }) + ) end end @@ -121,14 +124,17 @@ defmodule Blogex.Router do else conn |> put_resp_content_type("application/json") - |> send_resp(200, Jason.encode!(%{ - blog: blog.blog_id(), - title: blog.title(), - posts: Enum.map(result.entries, &post_json/1), - page: result.page, - total_pages: result.total_pages, - total_entries: result.total_entries - })) + |> send_resp( + 200, + Jason.encode!(%{ + blog: blog.blog_id(), + title: blog.title(), + posts: Enum.map(result.entries, &post_json/1), + page: result.page, + total_pages: result.total_pages, + total_entries: result.total_entries + }) + ) end end diff --git a/blogex/test/blogex/blog_test.exs b/blogex/test/blogex/blog_test.exs index 6b5afd2..a9b0b2b 100644 --- a/blogex/test/blogex/blog_test.exs +++ b/blogex/test/blogex/blog_test.exs @@ -22,10 +22,11 @@ defmodule Blogex.BlogTest do end test "includes today-dated published posts" do - {:ok, _} = FakeBlog.start([ - build(id: "today", date: Date.utc_today(), published: true), - build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true) - ]) + {:ok, _} = + FakeBlog.start([ + build(id: "today", date: Date.utc_today(), published: true), + build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true) + ]) ids = FakeBlog.all_posts() |> Enum.map(& &1.id) @@ -77,10 +78,11 @@ defmodule Blogex.BlogTest do end test "excludes drafts even if tag matches" do - {:ok, _} = FakeBlog.start([ - build(id: "pub", tags: ["elixir"], published: true), - build(id: "draft", tags: ["elixir"], published: false) - ]) + {:ok, _} = + FakeBlog.start([ + build(id: "pub", tags: ["elixir"], published: true), + build(id: "draft", tags: ["elixir"], published: false) + ]) ids = FakeBlog.posts_by_tag("elixir") |> Enum.map(& &1.id) @@ -103,10 +105,11 @@ defmodule Blogex.BlogTest do end test "excludes tags only appearing on drafts" do - {:ok, _} = FakeBlog.start([ - build(tags: ["visible"], published: true), - build(id: "d", tags: ["hidden"], published: false) - ]) + {:ok, _} = + FakeBlog.start([ + build(tags: ["visible"], published: true), + build(id: "d", tags: ["hidden"], published: false) + ]) refute "hidden" in FakeBlog.all_tags() end diff --git a/blogex/test/blogex/feed_test.exs b/blogex/test/blogex/feed_test.exs index b33b89a..562f041 100644 --- a/blogex/test/blogex/feed_test.exs +++ b/blogex/test/blogex/feed_test.exs @@ -109,10 +109,11 @@ defmodule Blogex.FeedTest do describe "XML escaping" do test "escapes special characters in titles" do - {:ok, _} = FakeBlog.start( - [build(title: "Foo & Bar ")], - title: "A & B" - ) + {:ok, _} = + FakeBlog.start( + [build(title: "Foo & Bar ")], + title: "A & B" + ) xml = Feed.rss(FakeBlog, @base_url) diff --git a/blogex/test/blogex/registry_test.exs b/blogex/test/blogex/registry_test.exs index 795880b..cfc7c72 100644 --- a/blogex/test/blogex/registry_test.exs +++ b/blogex/test/blogex/registry_test.exs @@ -6,19 +6,30 @@ defmodule Blogex.RegistryTest do defmodule AlphaBlog do def blog_id, do: :alpha - def all_posts, do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)] + + def all_posts, + do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)] + def all_tags, do: ["elixir"] def unfiltered_posts, do: [ Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha), - Blogex.Test.PostBuilder.build(id: "a-draft", date: ~D[2026-03-05], blog: :alpha, published: false) + Blogex.Test.PostBuilder.build( + id: "a-draft", + date: ~D[2026-03-05], + blog: :alpha, + published: false + ) ] end defmodule BetaBlog do def blog_id, do: :beta - def all_posts, do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)] + + def all_posts, + do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)] + def all_tags, do: ["devops"] def unfiltered_posts, diff --git a/blogex/test/blogex/router_test.exs b/blogex/test/blogex/router_test.exs index f082674..004bf75 100644 --- a/blogex/test/blogex/router_test.exs +++ b/blogex/test/blogex/router_test.exs @@ -10,15 +10,22 @@ defmodule Blogex.RouterTest do build(id: "first-post", title: "First", tags: ["elixir"], date: ~D[2026-03-10]), build(id: "second-post", title: "Second", tags: ["otp"], date: ~D[2026-02-01]), build(id: "draft", published: false, date: ~D[2026-03-12]), - build(id: "future-post", title: "Future", tags: ["elixir"], date: ~D[2099-01-01], published: true) + build( + id: "future-post", + title: "Future", + tags: ["elixir"], + date: ~D[2099-01-01], + published: true + ) ] - {:ok, _} = FakeBlog.start(posts, - blog_id: :test, - title: "Test Blog", - description: "Test", - base_path: "/blog/test" - ) + {:ok, _} = + FakeBlog.start(posts, + blog_id: :test, + title: "Test Blog", + description: "Test", + base_path: "/blog/test" + ) :ok end diff --git a/blogex/test/support/fake_blog.ex b/blogex/test/support/fake_blog.ex index a62d96b..d9601d5 100644 --- a/blogex/test/support/fake_blog.ex +++ b/blogex/test/support/fake_blog.ex @@ -35,7 +35,9 @@ defmodule Blogex.Test.FakeBlog do } case Agent.start(fn -> state end, name: __MODULE__) do - {:ok, pid} -> {:ok, pid} + {:ok, pid} -> + {:ok, pid} + {:error, {:already_started, pid}} -> Agent.update(__MODULE__, fn _ -> state end) {:ok, pid}