parent
1237f90cba
commit
d14b9c8160
@ -1,7 +1,15 @@ |
||||
defmodule ExplorerWeb.PageController do |
||||
use ExplorerWeb, :controller |
||||
import Ecto.Query |
||||
alias Explorer.Block |
||||
alias Explorer.Repo |
||||
|
||||
def index(conn, _params) do |
||||
render conn, "index.html" |
||||
blocks = Block |
||||
|> order_by(desc: :inserted_at) |
||||
|> limit(5) |
||||
|> Repo.all |
||||
|
||||
render(conn, "index.html", blocks: blocks) |
||||
end |
||||
end |
||||
|
@ -1,8 +1,23 @@ |
||||
defmodule ExplorerWeb.PageControllerTest do |
||||
use ExplorerWeb.ConnCase |
||||
|
||||
test "GET /", %{conn: conn} do |
||||
describe "GET index/2" do |
||||
test "returns a welcome message", %{conn: conn} do |
||||
conn = get conn, "/" |
||||
assert html_response(conn, 200) =~ "Welcome" |
||||
end |
||||
|
||||
test "returns a block", %{conn: conn} do |
||||
block = insert(:block, %{number: 23}) |
||||
conn = get conn, "/" |
||||
assert(List.first(conn.assigns.blocks) == block) |
||||
end |
||||
|
||||
test "excludes all but the most recent five blocks", %{conn: conn} do |
||||
old_block = insert(:block) |
||||
insert_list(5, :block) |
||||
conn = get conn, "/" |
||||
refute(Enum.member?(conn.assigns.blocks, old_block)) |
||||
end |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue