fix: Remove duplicate out-of-date templates
This commit is contained in:
parent
e3f540b785
commit
982ab98450
35 changed files with 0 additions and 1142 deletions
|
@ -1,32 +0,0 @@
|
|||
defmodule <%= module %>Channel do
|
||||
use <%= module %>, :channel
|
||||
|
||||
@impl true
|
||||
def join("<%= singular %>:lobby", payload, socket) do
|
||||
if authorized?(payload) do
|
||||
{:ok, socket}
|
||||
else
|
||||
{:error, %{reason: "unauthorized"}}
|
||||
end
|
||||
end
|
||||
|
||||
# Channels can be used in a request/response fashion
|
||||
# by sending replies to requests from the client
|
||||
@impl true
|
||||
def handle_in("ping", payload, socket) do
|
||||
{:reply, {:ok, payload}, socket}
|
||||
end
|
||||
|
||||
# It is also common to receive messages from the client and
|
||||
# broadcast to everyone in the current topic (<%= singular %>:lobby).
|
||||
@impl true
|
||||
def handle_in("shout", payload, socket) do
|
||||
broadcast socket, "shout", payload
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
# Add authorization logic here as required.
|
||||
defp authorized?(_payload) do
|
||||
true
|
||||
end
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
defmodule <%= module %>ChannelTest do
|
||||
use <%= module %>.ChannelCase
|
||||
|
||||
setup do
|
||||
{:ok, _, socket} =
|
||||
<%= module %>.UserSocket
|
||||
|> socket("user_id", %{some: :assign})
|
||||
|> subscribe_and_join(<%= module %>Channel, "<%= singular %>:lobby")
|
||||
|
||||
%{socket: socket}
|
||||
end
|
||||
|
||||
test "ping replies with status ok", %{socket: socket} do
|
||||
ref = push socket, "ping", %{"hello" => "there"}
|
||||
assert_reply ref, :ok, %{"hello" => "there"}
|
||||
end
|
||||
|
||||
test "shout broadcasts to <%= singular %>:lobby", %{socket: socket} do
|
||||
push socket, "shout", %{"hello" => "all"}
|
||||
assert_broadcast "shout", %{"hello" => "all"}
|
||||
end
|
||||
|
||||
test "broadcasts are pushed to the client", %{socket: socket} do
|
||||
broadcast_from! socket, "broadcast", %{"some" => "data"}
|
||||
assert_push "broadcast", %{"some" => "data"}
|
||||
end
|
||||
end
|
|
@ -1,89 +0,0 @@
|
|||
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
@doc """
|
||||
Returns the list of <%= schema.plural %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_<%= schema.plural %>()
|
||||
[%<%= inspect schema.alias %>{}, ...]
|
||||
|
||||
"""
|
||||
def list_<%= schema.plural %> do
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single <%= schema.singular %>.
|
||||
|
||||
Raises if the <%= schema.human_singular %> does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_<%= schema.singular %>!(123)
|
||||
%<%= inspect schema.alias %>{}
|
||||
|
||||
"""
|
||||
def get_<%= schema.singular %>!(id), do: raise "TODO"
|
||||
|
||||
@doc """
|
||||
Creates a <%= schema.singular %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_<%= schema.singular %>(%{field: value})
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> create_<%= schema.singular %>(%{field: bad_value})
|
||||
{:error, ...}
|
||||
|
||||
"""
|
||||
def create_<%= schema.singular %>(attrs \\ %{}) do
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a <%= schema.singular %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_<%= schema.singular %>(<%= schema.singular %>, %{field: new_value})
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> update_<%= schema.singular %>(<%= schema.singular %>, %{field: bad_value})
|
||||
{:error, ...}
|
||||
|
||||
"""
|
||||
def update_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>, attrs) do
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a <%= inspect schema.alias %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
{:error, ...}
|
||||
|
||||
"""
|
||||
def delete_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>) do
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a data structure for tracking <%= schema.singular %> changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_<%= schema.singular %>(<%= schema.singular %>)
|
||||
%Todo{...}
|
||||
|
||||
"""
|
||||
def change_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>, _attrs \\ %{}) do
|
||||
raise "TODO"
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
defmodule <%= inspect context.module %> do
|
||||
@moduledoc """
|
||||
The <%= context.name %> context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias <%= inspect schema.repo %>
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
defmodule <%= inspect context.module %>Test do
|
||||
use <%= inspect context.base_module %>.DataCase
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
|
||||
def <%= schema.singular %>_fixture(attrs \\ %{}) do
|
||||
{:ok, <%= schema.singular %>} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
<%= schema.params.create |> Enum.map(fn {key, val} -> " #{key}: #{inspect(val)}" end) |> Enum.join(",\n") %>
|
||||
})
|
||||
|> <%= inspect context.module %>.create_<%= schema.singular %>()
|
||||
|
||||
<%= schema.singular %>
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
defmodule <%= inspect context.module %>Fixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `<%= inspect context.module %>` context.
|
||||
"""
|
||||
end
|
|
@ -1,96 +0,0 @@
|
|||
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
@doc """
|
||||
Returns the list of <%= schema.plural %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_<%= schema.plural %>()
|
||||
[%<%= inspect schema.alias %>{}, ...]
|
||||
|
||||
"""
|
||||
def list_<%= schema.plural %> do
|
||||
Repo.all(<%= inspect schema.alias %>)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single <%= schema.singular %>.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the <%= schema.human_singular %> does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_<%= schema.singular %>!(123)
|
||||
%<%= inspect schema.alias %>{}
|
||||
|
||||
iex> get_<%= schema.singular %>!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_<%= schema.singular %>!(id), do: Repo.get!(<%= inspect schema.alias %>, id)
|
||||
|
||||
@doc """
|
||||
Creates a <%= schema.singular %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_<%= schema.singular %>(%{field: value})
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> create_<%= schema.singular %>(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_<%= schema.singular %>(attrs \\ %{}) do
|
||||
%<%= inspect schema.alias %>{}
|
||||
|> <%= inspect schema.alias %>.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a <%= schema.singular %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_<%= schema.singular %>(<%= schema.singular %>, %{field: new_value})
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> update_<%= schema.singular %>(<%= schema.singular %>, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>, attrs) do
|
||||
<%= schema.singular %>
|
||||
|> <%= inspect schema.alias %>.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a <%= schema.singular %>.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
{:ok, %<%= inspect schema.alias %>{}}
|
||||
|
||||
iex> delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>) do
|
||||
Repo.delete(<%= schema.singular %>)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking <%= schema.singular %> changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_<%= schema.singular %>(<%= schema.singular %>)
|
||||
%Ecto.Changeset{data: %<%= inspect schema.alias %>{}}
|
||||
|
||||
"""
|
||||
def change_<%= schema.singular %>(%<%= inspect schema.alias %>{} = <%= schema.singular %>, attrs \\ %{}) do
|
||||
<%= inspect schema.alias %>.changeset(<%= schema.singular %>, attrs)
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
describe "<%= schema.plural %>" do
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
import <%= inspect context.module %>Fixtures
|
||||
|
||||
@invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %>
|
||||
|
||||
test "list_<%= schema.plural %>/0 returns all <%= schema.plural %>" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
assert <%= inspect context.alias %>.list_<%= schema.plural %>() == [<%= schema.singular %>]
|
||||
end
|
||||
|
||||
test "get_<%= schema.singular %>!/1 returns the <%= schema.singular %> with given id" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
assert <%= inspect context.alias %>.get_<%= schema.singular %>!(<%= schema.singular %>.id) == <%= schema.singular %>
|
||||
end
|
||||
|
||||
test "create_<%= schema.singular %>/1 with valid data creates a <%= schema.singular %>" do
|
||||
valid_attrs = <%= inspect schema.params.create %>
|
||||
|
||||
assert {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} = <%= inspect context.alias %>.create_<%= schema.singular %>(valid_attrs)<%= for {field, value} <- schema.params.create do %>
|
||||
assert <%= schema.singular %>.<%= field %> == <%= Mix.Phoenix.Schema.value(schema, field, value) %><% end %>
|
||||
end
|
||||
|
||||
test "create_<%= schema.singular %>/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = <%= inspect context.alias %>.create_<%= schema.singular %>(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_<%= schema.singular %>/2 with valid data updates the <%= schema.singular %>" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
update_attrs = <%= inspect schema.params.update %>
|
||||
|
||||
assert {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} = <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, update_attrs)<%= for {field, value} <- schema.params.update do %>
|
||||
assert <%= schema.singular %>.<%= field %> == <%= Mix.Phoenix.Schema.value(schema, field, value) %><% end %>
|
||||
end
|
||||
|
||||
test "update_<%= schema.singular %>/2 with invalid data returns error changeset" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, @invalid_attrs)
|
||||
assert <%= schema.singular %> == <%= inspect context.alias %>.get_<%= schema.singular %>!(<%= schema.singular %>.id)
|
||||
end
|
||||
|
||||
test "delete_<%= schema.singular %>/1 deletes the <%= schema.singular %>" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
assert {:ok, %<%= inspect schema.alias %>{}} = <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
assert_raise Ecto.NoResultsError, fn -> <%= inspect context.alias %>.get_<%= schema.singular %>!(<%= schema.singular %>.id) end
|
||||
end
|
||||
|
||||
test "change_<%= schema.singular %>/1 returns a <%= schema.singular %> changeset" do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
assert %Ecto.Changeset{} = <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>)
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
defmodule <%= inspect schema.module %> do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
embedded_schema do
|
||||
<%= for {k, v} <- schema.types do %> field <%= inspect k %>, <%= inspect v %><%= schema.defaults[k] %>
|
||||
<% end %> end
|
||||
|
||||
@doc false
|
||||
def changeset(%<%= inspect schema.alias %>{} = <%= schema.singular %>, attrs) do
|
||||
<%= schema.singular %>
|
||||
|> cast(attrs, [<%= Enum.map_join(schema.attrs, ", ", &inspect(elem(&1, 0))) %>])
|
||||
|> validate_required([<%= Enum.map_join(schema.attrs, ", ", &inspect(elem(&1, 0))) %>])
|
||||
end
|
||||
end
|
|
@ -1,62 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Controller do
|
||||
use <%= inspect context.module %>, :controller
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
def index(conn, _params) do
|
||||
<%= schema.plural %> = <%= inspect context.alias %>.list_<%= schema.plural %>()
|
||||
render(conn, "index.html", <%= schema.plural %>: <%= schema.plural %>)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(%<%= inspect schema.alias %>{})
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{<%= inspect schema.singular %> => <%= schema.singular %>_params}) do
|
||||
case <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do
|
||||
{:ok, <%= schema.singular %>} ->
|
||||
conn
|
||||
|> put_flash(:info, "<%= schema.human_singular %> created successfully.")
|
||||
|> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
render(conn, "show.html", <%= schema.singular %>: <%= schema.singular %>)
|
||||
end
|
||||
|
||||
def edit(conn, %{"id" => id}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>)
|
||||
render(conn, "edit.html", <%= schema.singular %>: <%= schema.singular %>, changeset: changeset)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, <%= inspect schema.singular %> => <%= schema.singular %>_params}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
|
||||
case <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, <%= schema.singular %>_params) do
|
||||
{:ok, <%= schema.singular %>} ->
|
||||
conn
|
||||
|> put_flash(:info, "<%= schema.human_singular %> updated successfully.")
|
||||
|> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "edit.html", <%= schema.singular %>: <%= schema.singular %>, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
{:ok, _<%= schema.singular %>} = <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "<%= schema.human_singular %> deleted successfully.")
|
||||
|> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :index))
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ControllerTest do
|
||||
use <%= inspect context.module %>.ConnCase
|
||||
|
||||
import <%= inspect context.module %>Fixtures
|
||||
|
||||
@create_attrs <%= inspect schema.params.create %>
|
||||
@update_attrs <%= inspect schema.params.update %>
|
||||
@invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %>
|
||||
|
||||
describe "index" do
|
||||
test "lists all <%= schema.plural %>", %{conn: conn} do
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing <%= schema.human_plural %>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new <%= schema.singular %>" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create <%= schema.singular %>" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show <%= schema.human_singular %>"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit <%= schema.singular %>" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "renders form for editing chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :edit, <%= schema.singular %>))
|
||||
assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update <%= schema.singular %>" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>)
|
||||
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))<%= if schema.string_attr do %>
|
||||
assert html_response(conn, 200) =~ <%= inspect Mix.Phoenix.Schema.default_param(schema, :update) %><% else %>
|
||||
assert html_response(conn, 200)<% end %>
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete <%= schema.singular %>" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = delete(conn, Routes.<%= schema.route_helper %>_path(conn, :delete, <%= schema.singular %>))
|
||||
assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_<%= schema.singular %>(_) do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
%{<%= schema.singular %>: <%= schema.singular %>}
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
<h1>Edit <%= schema.human_singular %></h1>
|
||||
|
||||
<%%= render "form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :update, @<%= schema.singular %>)) %>
|
||||
|
||||
<span><%%= link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) %></span>
|
|
@ -1,15 +0,0 @@
|
|||
<%%= form_for @changeset, @action, fn f -> %>
|
||||
<%%= if @changeset.action do %>
|
||||
<div class="alert alert-danger">
|
||||
<p>Oops, something went wrong! Please check the errors below.</p>
|
||||
</div>
|
||||
<%% end %>
|
||||
<%= for {label, input, error} <- inputs, input do %>
|
||||
<%= label %>
|
||||
<%= input %>
|
||||
<%= error %>
|
||||
<% end %>
|
||||
<div>
|
||||
<%%= submit "Save" %>
|
||||
</div>
|
||||
<%% end %>
|
|
@ -1,26 +0,0 @@
|
|||
<h1>Listing <%= schema.human_plural %></h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<%= for {k, _} <- schema.attrs do %> <th><%= Phoenix.Naming.humanize(Atom.to_string(k)) %></th>
|
||||
<% end %>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%%= for <%= schema.singular %> <- @<%= schema.plural %> do %>
|
||||
<tr>
|
||||
<%= for {k, _} <- schema.attrs do %> <td><%%= <%= schema.singular %>.<%= k %> %></td>
|
||||
<% end %>
|
||||
<td>
|
||||
<span><%%= link "Show", to: Routes.<%= schema.route_helper %>_path(@conn, :show, <%= schema.singular %>) %></span>
|
||||
<span><%%= link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, <%= schema.singular %>) %></span>
|
||||
<span><%%= link "Delete", to: Routes.<%= schema.route_helper %>_path(@conn, :delete, <%= schema.singular %>), method: :delete, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<%% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%%= link "New <%= schema.human_singular %>", to: Routes.<%= schema.route_helper %>_path(@conn, :new) %></span>
|
|
@ -1,5 +0,0 @@
|
|||
<h1>New <%= schema.human_singular %></h1>
|
||||
|
||||
<%%= render "form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :create)) %>
|
||||
|
||||
<span><%%= link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) %></span>
|
|
@ -1,13 +0,0 @@
|
|||
<h1>Show <%= schema.human_singular %></h1>
|
||||
|
||||
<ul>
|
||||
<%= for {k, _} <- schema.attrs do %>
|
||||
<li>
|
||||
<strong><%= Phoenix.Naming.humanize(Atom.to_string(k)) %>:</strong>
|
||||
<%%= @<%= schema.singular %>.<%= k %> %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<span><%%= link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, @<%= schema.singular %>) %></span>
|
||||
<span><%%= link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) %></span>
|
|
@ -1,3 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View do
|
||||
use <%= inspect context.module %>, :view
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.ChangesetView do
|
||||
use <%= inspect context.module %>, :view
|
||||
|
||||
@doc """
|
||||
Traverses and translates changeset errors.
|
||||
|
||||
See `Ecto.Changeset.traverse_errors/2` and
|
||||
`<%= inspect context.module %>.ErrorHelpers.translate_error/1` for more details.
|
||||
"""
|
||||
def translate_errors(changeset) do
|
||||
Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
|
||||
end
|
||||
|
||||
def render("error.json", %{changeset: changeset}) do
|
||||
# When encoded, the changeset returns its errors
|
||||
# as a JSON object. So we just pass it forward.
|
||||
%{errors: translate_errors(changeset)}
|
||||
end
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Controller do
|
||||
use <%= inspect context.module %>, :controller
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
action_fallback <%= inspect context.module %>.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
<%= schema.plural %> = <%= inspect context.alias %>.list_<%= schema.plural %>()
|
||||
render(conn, "index.json", <%= schema.plural %>: <%= schema.plural %>)
|
||||
end
|
||||
|
||||
def create(conn, %{<%= inspect schema.singular %> => <%= schema.singular %>_params}) do
|
||||
with {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} <- <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> put_resp_header("location", Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
|
||||
|> render("show.json", <%= schema.singular %>: <%= schema.singular %>)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
render(conn, "show.json", <%= schema.singular %>: <%= schema.singular %>)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, <%= inspect schema.singular %> => <%= schema.singular %>_params}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
|
||||
with {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} <- <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, <%= schema.singular %>_params) do
|
||||
render(conn, "show.json", <%= schema.singular %>: <%= schema.singular %>)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
|
||||
with {:ok, %<%= inspect schema.alias %>{}} <- <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ControllerTest do
|
||||
use <%= inspect context.module %>.ConnCase
|
||||
|
||||
import <%= inspect context.module %>Fixtures
|
||||
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
@create_attrs %{
|
||||
<%= schema.params.create |> Enum.map(fn {key, val} -> " #{key}: #{inspect(val)}" end) |> Enum.join(",\n") %>
|
||||
}
|
||||
@update_attrs %{
|
||||
<%= schema.params.update |> Enum.map(fn {key, val} -> " #{key}: #{inspect(val)}" end) |> Enum.join(",\n") %>
|
||||
}
|
||||
@invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %>
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all <%= schema.plural %>", %{conn: conn} do
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create <%= schema.singular %>" do
|
||||
test "renders <%= schema.singular %> when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
|
||||
|
||||
assert %{
|
||||
"id" => id<%= for {key, val} <- schema.params.create |> Phoenix.json_library().encode!() |> Phoenix.json_library().decode!() do %>,
|
||||
"<%= key %>" => <%= inspect(val) %><% end %>
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update <%= schema.singular %>" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "renders <%= schema.singular %> when data is valid", %{conn: conn, <%= schema.singular %>: %<%= inspect schema.alias %>{id: id} = <%= schema.singular %>} do
|
||||
conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id))
|
||||
|
||||
assert %{
|
||||
"id" => id<%= for {key, val} <- schema.params.update |> Phoenix.json_library().encode!() |> Phoenix.json_library().decode!() do %>,
|
||||
"<%= key %>" => <%= inspect(val) %><% end %>
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete <%= schema.singular %>" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
conn = delete(conn, Routes.<%= schema.route_helper %>_path(conn, :delete, <%= schema.singular %>))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_<%= schema.singular %>(_) do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
%{<%= schema.singular %>: <%= schema.singular %>}
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.FallbackController do
|
||||
@moduledoc """
|
||||
Translates controller action results into valid `Plug.Conn` responses.
|
||||
|
||||
See `Phoenix.Controller.action_fallback/1` for more details.
|
||||
"""
|
||||
use <%= inspect context.module %>, :controller
|
||||
|
||||
<%= if schema.generate? do %># This clause handles errors returned by Ecto's insert/update/delete.
|
||||
def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> put_view(<%= inspect context.module %>.ChangesetView)
|
||||
|> render("error.json", changeset: changeset)
|
||||
end
|
||||
|
||||
<% end %># This clause is an example of how to handle resources that cannot be found.
|
||||
def call(conn, {:error, :not_found}) do
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> put_view(<%= inspect context.module %>.ErrorView)
|
||||
|> render(:"404")
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View do
|
||||
use <%= inspect context.module %>, :view
|
||||
alias <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View
|
||||
|
||||
def render("index.json", %{<%= schema.plural %>: <%= schema.plural %>}) do
|
||||
%{data: render_many(<%= schema.plural %>, <%= inspect schema.alias %>View, "<%= schema.singular %>.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{<%= schema.singular %>: <%= schema.singular %>}) do
|
||||
%{data: render_one(<%= schema.singular %>, <%= inspect schema.alias %>View, "<%= schema.singular %>.json")}
|
||||
end
|
||||
|
||||
def render("<%= schema.singular %>.json", %{<%= schema.singular %>: <%= schema.singular %>}) do
|
||||
%{id: <%= schema.singular %>.id<%= for {k, _} <- schema.attrs do %>,
|
||||
<%= k %>: <%= schema.singular %>.<%= k %><% end %>}
|
||||
end
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent do
|
||||
use <%= inspect context.module %>, :live_component
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
|
||||
@impl true
|
||||
def update(%{<%= schema.singular %>: <%= schema.singular %>} = assigns, socket) do
|
||||
changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>)
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign(:changeset, changeset)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate", %{"<%= schema.singular %>" => <%= schema.singular %>_params}, socket) do
|
||||
changeset =
|
||||
socket.assigns.<%= schema.singular %>
|
||||
|> <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
end
|
||||
|
||||
def handle_event("save", %{"<%= schema.singular %>" => <%= schema.singular %>_params}, socket) do
|
||||
save_<%= schema.singular %>(socket, socket.assigns.action, <%= schema.singular %>_params)
|
||||
end
|
||||
|
||||
defp save_<%= schema.singular %>(socket, :edit, <%= schema.singular %>_params) do
|
||||
case <%= inspect context.alias %>.update_<%= schema.singular %>(socket.assigns.<%= schema.singular %>, <%= schema.singular %>_params) do
|
||||
{:ok, _<%= schema.singular %>} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "<%= schema.human_singular %> updated successfully")
|
||||
|> push_redirect(to: socket.assigns.return_to)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp save_<%= schema.singular %>(socket, :new, <%= schema.singular %>_params) do
|
||||
case <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do
|
||||
{:ok, _<%= schema.singular %>} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "<%= schema.human_singular %> created successfully")
|
||||
|> push_redirect(to: socket.assigns.return_to)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, changeset: changeset)}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
<h2><%%= @title %></h2>
|
||||
|
||||
<%%= f = form_for @changeset, "#",
|
||||
id: "<%= schema.singular %>-form",
|
||||
phx_target: @myself,
|
||||
phx_change: "validate",
|
||||
phx_submit: "save" %>
|
||||
<%= for {label, input, error} <- inputs, input do %>
|
||||
<%= label %>
|
||||
<%= input %>
|
||||
<%= error %>
|
||||
<% end %>
|
||||
<%%= submit "Save", phx_disable_with: "Saving..." %>
|
||||
</form>
|
|
@ -1,46 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Index do
|
||||
use <%= inspect context.module %>, :live_view
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
alias <%= inspect schema.module %>
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, assign(socket, :<%= schema.collection %>, list_<%= schema.plural %>())}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit <%= schema.human_singular %>")
|
||||
|> assign(:<%= schema.singular %>, <%= inspect context.alias %>.get_<%= schema.singular %>!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New <%= schema.human_singular %>")
|
||||
|> assign(:<%= schema.singular %>, %<%= inspect schema.alias %>{})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing <%= schema.human_plural %>")
|
||||
|> assign(:<%= schema.singular %>, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
|
||||
{:ok, _} = <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>)
|
||||
|
||||
{:noreply, assign(socket, :<%= schema.collection %>, list_<%=schema.plural %>())}
|
||||
end
|
||||
|
||||
defp list_<%= schema.plural %> do
|
||||
<%= inspect context.alias %>.list_<%= schema.plural %>()
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
<h1>Listing <%= schema.human_plural %></h1>
|
||||
|
||||
<%%= if @live_action in [:new, :edit] do %>
|
||||
<%%= live_modal @socket, <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent,
|
||||
id: @<%= schema.singular %>.id || :new,
|
||||
title: @page_title,
|
||||
action: @live_action,
|
||||
<%= schema.singular %>: @<%= schema.singular %>,
|
||||
return_to: Routes.<%= schema.route_helper %>_index_path(@socket, :index) %>
|
||||
<%% end %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<%= for {k, _} <- schema.attrs do %> <th><%= Phoenix.Naming.humanize(Atom.to_string(k)) %></th>
|
||||
<% end %>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="<%= schema.plural %>">
|
||||
<%%= for <%= schema.singular %> <- @<%= schema.collection %> do %>
|
||||
<tr id="<%= schema.singular %>-<%%= <%= schema.singular %>.id %>">
|
||||
<%= for {k, _} <- schema.attrs do %> <td><%%= <%= schema.singular %>.<%= k %> %></td>
|
||||
<% end %>
|
||||
<td>
|
||||
<span><%%= live_redirect "Show", to: Routes.<%= schema.route_helper %>_show_path(@socket, :show, <%= schema.singular %>) %></span>
|
||||
<span><%%= live_patch "Edit", to: Routes.<%= schema.route_helper %>_index_path(@socket, :edit, <%= schema.singular %>) %></span>
|
||||
<span><%%= link "Delete", to: "#", phx_click: "delete", phx_value_id: <%= schema.singular %>.id, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<%% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%%= live_patch "New <%= schema.human_singular %>", to: Routes.<%= schema.route_helper %>_index_path(@socket, :new) %></span>
|
|
@ -1,23 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.LiveHelpers do
|
||||
import Phoenix.LiveView.Helpers
|
||||
|
||||
@doc """
|
||||
Renders a component inside the `<%= inspect context.module %>.ModalComponent` component.
|
||||
|
||||
The rendered modal receives a `:return_to` option to properly update
|
||||
the URL when the modal is closed.
|
||||
|
||||
## Examples
|
||||
|
||||
<%%= live_modal @socket, <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent,
|
||||
id: @<%= schema.singular %>.id || :new,
|
||||
action: @live_action,
|
||||
<%= schema.singular %>: @<%= schema.singular %>,
|
||||
return_to: Routes.<%= schema.singular %>_index_path(@socket, :index) %>
|
||||
"""
|
||||
def live_modal(socket, component, opts) do
|
||||
path = Keyword.fetch!(opts, :return_to)
|
||||
modal_opts = [id: :modal, return_to: path, component: component, opts: opts]
|
||||
live_component(socket, <%= inspect context.module %>.ModalComponent, modal_opts)
|
||||
end
|
||||
end
|
|
@ -1,110 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>LiveTest do
|
||||
use <%= inspect context.module %>.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import <%= inspect context.module %>Fixtures
|
||||
|
||||
@create_attrs <%= inspect schema.params.create %>
|
||||
@update_attrs <%= inspect schema.params.update %>
|
||||
@invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %>
|
||||
|
||||
defp create_<%= schema.singular %>(_) do
|
||||
<%= schema.singular %> = <%= schema.singular %>_fixture()
|
||||
%{<%= schema.singular %>: <%= schema.singular %>}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "lists all <%= schema.plural %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing <%= schema.human_plural %>"<%= if schema.string_attr do %>
|
||||
assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %>
|
||||
end
|
||||
|
||||
test "saves new <%= schema.singular %>", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New <%= schema.human_singular %>") |> render_click() =~
|
||||
"New <%= schema.human_singular %>"
|
||||
|
||||
assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert html =~ "<%= schema.human_singular %> created successfully"<%= if schema.string_attr do %>
|
||||
assert html =~ "some <%= schema.string_attr %>"<% end %>
|
||||
end
|
||||
|
||||
test "updates <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Edit") |> render_click() =~
|
||||
"Edit <%= schema.human_singular %>"
|
||||
|
||||
assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :edit, <%= schema.singular %>))
|
||||
|
||||
assert index_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %>
|
||||
assert html =~ "some updated <%= schema.string_attr %>"<% end %>
|
||||
end
|
||||
|
||||
test "deletes <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#<%= schema.singular %>-#{<%= schema.singular %>.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_<%= schema.singular %>]
|
||||
|
||||
test "displays <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
|
||||
|
||||
assert html =~ "Show <%= schema.human_singular %>"<%= if schema.string_attr do %>
|
||||
assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %>
|
||||
end
|
||||
|
||||
test "updates <%= schema.singular %> within modal", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit <%= schema.human_singular %>"
|
||||
|
||||
assert_patch(show_live, Routes.<%= schema.route_helper %>_show_path(conn, :edit, <%= schema.singular %>))
|
||||
|
||||
assert show_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>))
|
||||
|
||||
assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %>
|
||||
assert html =~ "some updated <%= schema.string_attr %>"<% end %>
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.ModalComponent do
|
||||
use <%= inspect context.module %>, :live_component
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~L"""
|
||||
<div id="<%%= @id %>" class="phx-modal"
|
||||
phx-capture-click="close"
|
||||
phx-window-keydown="close"
|
||||
phx-key="escape"
|
||||
phx-target="#<%%= @id %>"
|
||||
phx-page-loading>
|
||||
|
||||
<div class="phx-modal-content">
|
||||
<%%= live_patch raw("×"), to: @return_to, class: "phx-modal-close" %>
|
||||
<%%= live_component @socket, @component, @opts %>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("close", _, socket) do
|
||||
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
defmodule <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Show do
|
||||
use <%= inspect context.module %>, :live_view
|
||||
|
||||
alias <%= inspect context.module %>
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:<%= schema.singular %>, <%= inspect context.alias %>.get_<%= schema.singular %>!(id))}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show <%= schema.human_singular %>"
|
||||
defp page_title(:edit), do: "Edit <%= schema.human_singular %>"
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
<h1>Show <%= schema.human_singular %></h1>
|
||||
|
||||
<%%= if @live_action in [:edit] do %>
|
||||
<%%= live_modal @socket, <%= inspect context.module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent,
|
||||
id: @<%= schema.singular %>.id,
|
||||
title: @page_title,
|
||||
action: @live_action,
|
||||
<%= schema.singular %>: @<%= schema.singular %>,
|
||||
return_to: Routes.<%= schema.route_helper %>_show_path(@socket, :show, @<%= schema.singular %>) %>
|
||||
<%% end %>
|
||||
|
||||
<ul>
|
||||
<%= for {k, _} <- schema.attrs do %>
|
||||
<li>
|
||||
<strong><%= Phoenix.Naming.humanize(Atom.to_string(k)) %>:</strong>
|
||||
<%%= @<%= schema.singular %>.<%= k %> %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<span><%%= live_patch "Edit", to: Routes.<%= schema.route_helper %>_show_path(@socket, :edit, @<%= schema.singular %>), class: "button" %></span>
|
||||
<span><%%= live_redirect "Back", to: Routes.<%= schema.route_helper %>_index_path(@socket, :index) %></span>
|
|
@ -1,10 +0,0 @@
|
|||
defmodule <%= module %> do
|
||||
@moduledoc """
|
||||
Provides presence tracking to channels and processes.
|
||||
|
||||
See the [`Phoenix.Presence`](http://hexdocs.pm/phoenix/Phoenix.Presence.html)
|
||||
docs for more details.
|
||||
"""
|
||||
use Phoenix.Presence, otp_app: <%= inspect otp_app %>,
|
||||
pubsub_server: <%= inspect pubsub_server %>
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
defmodule <%= inspect schema.repo %>.Migrations.Create<%= Macro.camelize(schema.table) %> do
|
||||
use <%= inspect schema.migration_module %>
|
||||
|
||||
def change do
|
||||
create table(:<%= schema.table %><%= if schema.binary_id do %>, primary_key: false<% end %>) do
|
||||
<%= if schema.binary_id do %> add :id, :binary_id, primary_key: true
|
||||
<% end %><%= for {k, v} <- schema.attrs do %> add <%= inspect k %>, <%= inspect v %><%= schema.migration_defaults[k] %>
|
||||
<% end %><%= for {_, i, _, s} <- schema.assocs do %> add <%= inspect(i) %>, references(<%= inspect(s) %>, on_delete: :nothing<%= if schema.binary_id do %>, type: :binary_id<% end %>)
|
||||
<% end %>
|
||||
timestamps()
|
||||
end
|
||||
<%= for index <- schema.indexes do %>
|
||||
<%= index %><% end %>
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
defmodule <%= inspect schema.module %> do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
<%= if schema.binary_id do %>
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id<% end %>
|
||||
schema <%= inspect schema.table %> do
|
||||
<%= for {k, v} <- schema.types do %> field <%= inspect k %>, <%= inspect v %><%= schema.defaults[k] %>
|
||||
<% end %><%= for {_, k, _, _} <- schema.assocs do %> field <%= inspect k %>, <%= if schema.binary_id do %>:binary_id<% else %>:id<% end %>
|
||||
<% end %>
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(<%= schema.singular %>, attrs) do
|
||||
<%= schema.singular %>
|
||||
|> cast(attrs, [<%= Enum.map_join(schema.attrs, ", ", &inspect(elem(&1, 0))) %>])
|
||||
|> validate_required([<%= Enum.map_join(schema.attrs, ", ", &inspect(elem(&1, 0))) %>])
|
||||
<%= for k <- schema.uniques do %> |> unique_constraint(<%= inspect k %>)
|
||||
<% end %> end
|
||||
end
|
Loading…
Reference in a new issue