Last active
November 11, 2015 00:06
-
-
Save e-fu/5b206cb636ccf01253c1 to your computer and use it in GitHub Desktop.
Namespaced and some actions as nested resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Rolester.Admin.AppControllerTest do | |
use Rolester.ConnCase | |
alias Rolester.App | |
alias Rolester.Tenant | |
@valid_attrs %{name: "some content"} | |
@invalid_attrs %{} | |
setup do | |
tenant = %Tenant{name: "some text"} |> Repo.insert! | |
conn = conn() | |
{:ok, conn: conn, tenant: tenant} | |
end | |
test "lists all entries on index", %{conn: conn, tenant: tenant} do | |
conn = get conn, tenant_app_path(conn, :index, tenant) | |
assert html_response(conn, 200) =~ "Listing apps" | |
end | |
test "renders form for new resources", %{conn: conn, tenant: tenant} do | |
conn = get conn, tenant_app_path(conn, :new, tenant) | |
assert html_response(conn, 200) =~ "New app" | |
end | |
test "creates resource and redirects when data is valid", %{conn: conn, tenant: tenant} do | |
conn = post conn, tenant_app_path(conn, :create, tenant), app: @valid_attrs | |
assert redirected_to(conn) == tenant_app_path(conn, :index, tenant) | |
assert Repo.get_by(App, @valid_attrs) | |
end | |
test "does not create resource and renders errors when data is invalid", %{conn: conn, tenant: tenant} do | |
conn = post conn, tenant_app_path(conn, :create, tenant), app: @invalid_attrs | |
assert html_response(conn, 200) =~ "New app" | |
end | |
test "shows chosen resource", %{conn: conn} do | |
app = Repo.insert! %App{} | |
conn = get conn, app_path(conn, :show, app) | |
assert html_response(conn, 200) =~ "Show app" | |
end | |
test "renders page not found when id is nonexistent", %{conn: conn} do | |
assert_raise Ecto.NoResultsError, fn -> | |
get conn, app_path(conn, :show, "4be6ca8d-0897-440a-ad8e-25e2c961f9b6") | |
end | |
end | |
test "renders form for editing chosen resource", %{conn: conn} do | |
app = Repo.insert! %App{} | |
conn = get conn, app_path(conn, :edit, app) | |
assert html_response(conn, 200) =~ "Edit app" | |
end | |
test "updates chosen resource and redirects when data is valid", %{conn: conn, tenant: tenant} do | |
app = Repo.insert! %App{tenant_id: tenant.id} | |
conn = put conn, app_path(conn, :update, app), app: @valid_attrs | |
assert redirected_to(conn) == app_path(conn, :show, app) | |
assert Repo.get_by(App, @valid_attrs) | |
end | |
test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do | |
app = Repo.insert! %App{} | |
conn = put conn, app_path(conn, :update, app), app: @invalid_attrs | |
assert html_response(conn, 200) =~ "Edit app" | |
end | |
test "deletes chosen resource", %{conn: conn, tenant: tenant} do | |
app = Repo.insert! %App{} | |
conn = delete conn, tenant_app_path(conn, :delete, tenant, app) | |
assert redirected_to(conn) == tenant_app_path(conn, :index, tenant) | |
refute Repo.get(App, app.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment