Static blog with front page summary
Goal: have a personal blog, and try out another point in the 'modular app design with elixir' space. Designing OTP systems with elixir had some interesting ideas.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
defmodule FirehoseWeb.BlogTest do
|
||||
use FirehoseWeb.ConnCase
|
||||
|
||||
describe "engineering blog (HTML)" do
|
||||
test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Engineering Blog"
|
||||
assert body =~ "Hello World"
|
||||
# Verify app layout is present (navbar)
|
||||
assert body =~ "firehose"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/:slug returns HTML post with layout", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering/hello-world")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Hello World"
|
||||
assert body =~ "firehose"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/tag/:tag returns HTML tag page", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering/tag/elixir")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ ~s(tagged "elixir")
|
||||
assert body =~ "Hello World"
|
||||
end
|
||||
end
|
||||
|
||||
describe "release notes blog (HTML)" do
|
||||
test "GET /blog/releases returns HTML index", %{conn: conn} do
|
||||
conn = get(conn, "/blog/releases")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Release Notes"
|
||||
assert body =~ "v0.1.0 Released"
|
||||
end
|
||||
|
||||
test "GET /blog/releases/:slug returns HTML post", %{conn: conn} do
|
||||
conn = get(conn, "/blog/releases/v0-1-0")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "v0.1.0 Released"
|
||||
end
|
||||
end
|
||||
|
||||
describe "engineering blog (JSON API)" do
|
||||
test "GET /api/blog/engineering returns post index", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/engineering")
|
||||
assert %{"blog" => "engineering", "posts" => posts} = json_response(conn, 200)
|
||||
assert is_list(posts)
|
||||
assert length(posts) > 0
|
||||
end
|
||||
|
||||
test "GET /api/blog/engineering/:slug returns a post", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/engineering/hello-world")
|
||||
assert %{"id" => "hello-world", "title" => "Hello World"} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "GET /api/blog/engineering/:slug returns 404 for missing post", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/engineering/nonexistent")
|
||||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "GET /api/blog/engineering/feed.xml returns RSS", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/engineering/feed.xml")
|
||||
assert response_content_type(conn, :xml)
|
||||
assert response(conn, 200) =~ "<rss"
|
||||
end
|
||||
end
|
||||
|
||||
describe "release notes blog (JSON API)" do
|
||||
test "GET /api/blog/releases returns post index", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/releases")
|
||||
assert %{"blog" => "release_notes", "posts" => posts} = json_response(conn, 200)
|
||||
assert is_list(posts)
|
||||
assert length(posts) > 0
|
||||
end
|
||||
|
||||
test "GET /api/blog/releases/:slug returns a post", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/releases/v0-1-0")
|
||||
assert %{"id" => "v0-1-0", "title" => "v0.1.0 Released"} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "GET /api/blog/releases/feed.xml returns RSS", %{conn: conn} do
|
||||
conn = get(conn, "/api/blog/releases/feed.xml")
|
||||
assert response_content_type(conn, :xml)
|
||||
assert response(conn, 200) =~ "<rss"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
defmodule FirehoseWeb.ErrorHTMLTest do
|
||||
use FirehoseWeb.ConnCase, async: true
|
||||
|
||||
# Bring render_to_string/4 for testing custom views
|
||||
import Phoenix.Template, only: [render_to_string: 4]
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(FirehoseWeb.ErrorHTML, "404", "html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(FirehoseWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
defmodule FirehoseWeb.ErrorJSONTest do
|
||||
use FirehoseWeb.ConnCase, async: true
|
||||
|
||||
test "renders 404" do
|
||||
assert FirehoseWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}}
|
||||
end
|
||||
|
||||
test "renders 500" do
|
||||
assert FirehoseWeb.ErrorJSON.render("500.json", %{}) ==
|
||||
%{errors: %{detail: "Internal Server Error"}}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule FirehoseWeb.PageControllerTest do
|
||||
use FirehoseWeb.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, ~p"/")
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Drinking from the firehose"
|
||||
assert body =~ "Willem van den Ende"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user