|
| 1 | +defmodule Beanie.RepositoryControllerTest do |
| 2 | + use Beanie.ConnCase |
| 3 | + |
| 4 | + alias Beanie.Repository |
| 5 | + @valid_attrs %{name: "some content"} |
| 6 | + @invalid_attrs %{} |
| 7 | + |
| 8 | + test "lists all entries on index", %{conn: conn} do |
| 9 | + conn = get conn, repository_path(conn, :index) |
| 10 | + assert html_response(conn, 200) =~ "Listing repositories" |
| 11 | + end |
| 12 | + |
| 13 | + test "renders form for new resources", %{conn: conn} do |
| 14 | + conn = get conn, repository_path(conn, :new) |
| 15 | + assert html_response(conn, 200) =~ "New repository" |
| 16 | + end |
| 17 | + |
| 18 | + test "creates resource and redirects when data is valid", %{conn: conn} do |
| 19 | + conn = post conn, repository_path(conn, :create), repository: @valid_attrs |
| 20 | + assert redirected_to(conn) == repository_path(conn, :index) |
| 21 | + assert Repo.get_by(Repository, @valid_attrs) |
| 22 | + end |
| 23 | + |
| 24 | + test "does not create resource and renders errors when data is invalid", %{conn: conn} do |
| 25 | + conn = post conn, repository_path(conn, :create), repository: @invalid_attrs |
| 26 | + assert html_response(conn, 200) =~ "New repository" |
| 27 | + end |
| 28 | + |
| 29 | + test "shows chosen resource", %{conn: conn} do |
| 30 | + repository = Repo.insert! %Repository{} |
| 31 | + conn = get conn, repository_path(conn, :show, repository) |
| 32 | + assert html_response(conn, 200) =~ "Show repository" |
| 33 | + end |
| 34 | + |
| 35 | + test "renders page not found when id is nonexistent", %{conn: conn} do |
| 36 | + assert_error_sent 404, fn -> |
| 37 | + get conn, repository_path(conn, :show, -1) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + test "renders form for editing chosen resource", %{conn: conn} do |
| 42 | + repository = Repo.insert! %Repository{} |
| 43 | + conn = get conn, repository_path(conn, :edit, repository) |
| 44 | + assert html_response(conn, 200) =~ "Edit repository" |
| 45 | + end |
| 46 | + |
| 47 | + test "updates chosen resource and redirects when data is valid", %{conn: conn} do |
| 48 | + repository = Repo.insert! %Repository{} |
| 49 | + conn = put conn, repository_path(conn, :update, repository), repository: @valid_attrs |
| 50 | + assert redirected_to(conn) == repository_path(conn, :show, repository) |
| 51 | + assert Repo.get_by(Repository, @valid_attrs) |
| 52 | + end |
| 53 | + |
| 54 | + test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do |
| 55 | + repository = Repo.insert! %Repository{} |
| 56 | + conn = put conn, repository_path(conn, :update, repository), repository: @invalid_attrs |
| 57 | + assert html_response(conn, 200) =~ "Edit repository" |
| 58 | + end |
| 59 | + |
| 60 | + test "deletes chosen resource", %{conn: conn} do |
| 61 | + repository = Repo.insert! %Repository{} |
| 62 | + conn = delete conn, repository_path(conn, :delete, repository) |
| 63 | + assert redirected_to(conn) == repository_path(conn, :index) |
| 64 | + refute Repo.get(Repository, repository.id) |
| 65 | + end |
| 66 | +end |
0 commit comments