adjust makefile and refactor test
This commit is contained in:
@@ -3,28 +3,36 @@
|
||||
defmodule FirehoseWeb.BlogTest do
|
||||
use FirehoseWeb.ConnCase
|
||||
|
||||
defp goto_engineering_page(conn, suffix \\ "") do
|
||||
path = "/blog/engineering" <> suffix
|
||||
conn = get(conn, path)
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "Engineering Blog"
|
||||
assert body =~ "firehose"
|
||||
body
|
||||
end
|
||||
|
||||
defp goto_engineering_post_page(conn, suffix) do
|
||||
path = "/blog/engineering" <> suffix
|
||||
conn = get(conn, path)
|
||||
body = html_response(conn, 200)
|
||||
assert body =~ "firehose"
|
||||
body
|
||||
end
|
||||
|
||||
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"
|
||||
goto_engineering_page(conn)
|
||||
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)
|
||||
body = goto_engineering_post_page(conn, "/hello-world")
|
||||
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)
|
||||
body = goto_engineering_post_page(conn, "/tag/elixir")
|
||||
assert body =~ ~s(tagged "elixir")
|
||||
assert body =~ "Hello World"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,18 +43,18 @@ defmodule FirehoseWeb.BlogTest do
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=abc falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=abc")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=-1 falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=-1")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering?page=0 falls back to page 1", %{conn: conn} do
|
||||
conn = get(conn, "/blog/engineering?page=0")
|
||||
assert html_response(conn, 200) =~ "Engineering Blog"
|
||||
body = goto_engineering_page(conn, "?page=0")
|
||||
assert body =~ "Engineering Blog"
|
||||
end
|
||||
|
||||
test "GET /blog/engineering/nonexistent-post returns 404", %{conn: conn} do
|
||||
|
||||
@@ -16,9 +16,10 @@ defmodule Firehose.DataCase do
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
alias Firehose.Repo
|
||||
|
||||
import Ecto
|
||||
|
||||
Reference in New Issue
Block a user