Survival instructions editable.
This commit is contained in:
@@ -223,4 +223,113 @@ defmodule Runosaari.Pages do
|
|||||||
def change_info(%Info{} = info, attrs \\ %{}) do
|
def change_info(%Info{} = info, attrs \\ %{}) do
|
||||||
Info.changeset(info, attrs)
|
Info.changeset(info, attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias Runosaari.Pages.Survival
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of survival_items.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> list_survival_items()
|
||||||
|
[%Survival{}, ...]
|
||||||
|
|
||||||
|
"""
|
||||||
|
def list_survival_items do
|
||||||
|
Repo.all(Survival)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of survival_items.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> list_survival_items()
|
||||||
|
[%Survival{}, ...]
|
||||||
|
|
||||||
|
"""
|
||||||
|
def list_sorted_survival_items do
|
||||||
|
Repo.all(Survival |> order_by(:seqnum))
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets a single survival.
|
||||||
|
|
||||||
|
Raises `Ecto.NoResultsError` if the Survival does not exist.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> get_survival!(123)
|
||||||
|
%Survival{}
|
||||||
|
|
||||||
|
iex> get_survival!(456)
|
||||||
|
** (Ecto.NoResultsError)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def get_survival!(id), do: Repo.get!(Survival, id)
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Creates a survival.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> create_survival(%{field: value})
|
||||||
|
{:ok, %Survival{}}
|
||||||
|
|
||||||
|
iex> create_survival(%{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def create_survival(attrs \\ %{}) do
|
||||||
|
%Survival{}
|
||||||
|
|> Survival.changeset(attrs)
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Updates a survival.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> update_survival(survival, %{field: new_value})
|
||||||
|
{:ok, %Survival{}}
|
||||||
|
|
||||||
|
iex> update_survival(survival, %{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def update_survival(%Survival{} = survival, attrs) do
|
||||||
|
survival
|
||||||
|
|> Survival.changeset(attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Deletes a survival.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> delete_survival(survival)
|
||||||
|
{:ok, %Survival{}}
|
||||||
|
|
||||||
|
iex> delete_survival(survival)
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def delete_survival(%Survival{} = survival) do
|
||||||
|
Repo.delete(survival)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns an `%Ecto.Changeset{}` for tracking survival changes.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> change_survival(survival)
|
||||||
|
%Ecto.Changeset{data: %Survival{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def change_survival(%Survival{} = survival, attrs \\ %{}) do
|
||||||
|
Survival.changeset(survival, attrs)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
18
lib/runosaari/pages/survival.ex
Normal file
18
lib/runosaari/pages/survival.ex
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
defmodule Runosaari.Pages.Survival do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "survival_items" do
|
||||||
|
field :content, :string
|
||||||
|
field :seqnum, :integer
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(survival, attrs) do
|
||||||
|
survival
|
||||||
|
|> cast(attrs, [:content, :seqnum])
|
||||||
|
|> validate_required([:content, :seqnum])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,7 +6,16 @@ defmodule RunosaariWeb.InfoController do
|
|||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
info_paragraphs = Pages.list_sorted_info_paragraphs()
|
info_paragraphs = Pages.list_sorted_info_paragraphs()
|
||||||
render(conn, "index.html", info_paragraphs: info_paragraphs)
|
survival_items = Pages.list_sorted_survival_items()
|
||||||
|
|
||||||
|
render(
|
||||||
|
conn,
|
||||||
|
"index.html",
|
||||||
|
Map.new(
|
||||||
|
info_paragraphs: info_paragraphs,
|
||||||
|
survival_items: survival_items
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin(conn, _params) do
|
def admin(conn, _params) do
|
||||||
@@ -21,7 +30,7 @@ defmodule RunosaariWeb.InfoController do
|
|||||||
|
|
||||||
def create(conn, %{"info" => info_params}) do
|
def create(conn, %{"info" => info_params}) do
|
||||||
case Pages.create_info(info_params) do
|
case Pages.create_info(info_params) do
|
||||||
{:ok, info} ->
|
{:ok} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Info created successfully.")
|
|> put_flash(:info, "Info created successfully.")
|
||||||
|> redirect(to: Routes.admin_info_path(conn, :admin))
|
|> redirect(to: Routes.admin_info_path(conn, :admin))
|
||||||
|
|||||||
67
lib/runosaari_web/controllers/survival_controller.ex
Normal file
67
lib/runosaari_web/controllers/survival_controller.ex
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
defmodule RunosaariWeb.SurvivalController do
|
||||||
|
use RunosaariWeb, :controller
|
||||||
|
|
||||||
|
alias Runosaari.Pages
|
||||||
|
alias Runosaari.Pages.Survival
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
survival_items = Pages.list_survival_items()
|
||||||
|
render(conn, "admin.html", survival_items: survival_items)
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin(conn, _params) do
|
||||||
|
survival_items = Pages.list_survival_items()
|
||||||
|
render(conn, "admin.html", survival_items: survival_items)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new(conn, _params) do
|
||||||
|
changeset = Pages.change_survival(%Survival{})
|
||||||
|
render(conn, "new.html", changeset: changeset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(conn, %{"survival" => survival_params}) do
|
||||||
|
case Pages.create_survival(survival_params) do
|
||||||
|
{:ok, survival} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Survival created successfully.")
|
||||||
|
|> redirect(to: Routes.admin_survival_path(conn, :show, survival))
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
render(conn, "new.html", changeset: changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show(conn, %{"id" => id}) do
|
||||||
|
survival = Pages.get_survival!(id)
|
||||||
|
render(conn, "show.html", survival: survival)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit(conn, %{"id" => id}) do
|
||||||
|
survival = Pages.get_survival!(id)
|
||||||
|
changeset = Pages.change_survival(survival)
|
||||||
|
render(conn, "edit.html", survival: survival, changeset: changeset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(conn, %{"id" => id, "survival" => survival_params}) do
|
||||||
|
survival = Pages.get_survival!(id)
|
||||||
|
|
||||||
|
case Pages.update_survival(survival, survival_params) do
|
||||||
|
{:ok, survival} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Survival updated successfully.")
|
||||||
|
|> redirect(to: Routes.admin_survival_path(conn, :show, survival))
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
render(conn, "edit.html", survival: survival, changeset: changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(conn, %{"id" => id}) do
|
||||||
|
survival = Pages.get_survival!(id)
|
||||||
|
{:ok, _survival} = Pages.delete_survival(survival)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Survival deleted successfully.")
|
||||||
|
|> redirect(to: Routes.admin_survival_path(conn, :admin))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -38,6 +38,8 @@ defmodule RunosaariWeb.Router do
|
|||||||
resources "/visitors", VisitorController, except: [:new, :create]
|
resources "/visitors", VisitorController, except: [:new, :create]
|
||||||
resources "/info", InfoController, except: [:index]
|
resources "/info", InfoController, except: [:index]
|
||||||
get "/info", InfoController, :admin
|
get "/info", InfoController, :admin
|
||||||
|
resources "/survival", SurvivalController, except: [:index]
|
||||||
|
get "/survival", SurvivalController, :admin
|
||||||
end
|
end
|
||||||
|
|
||||||
# Other scopes may use custom stacks.
|
# Other scopes may use custom stacks.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
<h1>Muokkaa kappaletta</h1>
|
<h1>Muokkaa kappaletta</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_index_path(@conn, :update, @index)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_index_path(@conn, :update, @index)) %>
|
||||||
|
|
||||||
<span><%= link "Takaisin", to: Routes.admin_index_path(@conn, :admin) %></span>
|
<span><%= link "Takaisin", to: Routes.admin_index_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
<h1>Muokkaa kappaletta</h1>
|
<h1>Muokkaa kappaletta</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_info_path(@conn, :update, @info)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_info_path(@conn, :update, @info)) %>
|
||||||
|
|
||||||
<span><%= link "Takaisin", to: Routes.admin_info_path(@conn, :admin) %></span>
|
<span><%= link "Takaisin", to: Routes.admin_info_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
|
|||||||
@@ -18,18 +18,8 @@
|
|||||||
</p>
|
</p>
|
||||||
<h2><i>[TULOSSA]</i> <br />SURVIVAL-ohjeet saariston syrjäseudulle</h2>
|
<h2><i>[TULOSSA]</i> <br />SURVIVAL-ohjeet saariston syrjäseudulle</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Tietoa majoitusmahdollisuuksista ja ravitsemuspalveluista</li>
|
<%= for survival <- @survival_items do %>
|
||||||
<li>
|
<li><%= survival.content %>
|
||||||
Tarjolla telttailumahdollisuus ja mahdollisesti yksinkertaista
|
<% end %>
|
||||||
yhteismajoitusta Livonsaaren yhteisökylän mailla, 1 km
|
|
||||||
Seurantalolta.
|
|
||||||
</li>
|
|
||||||
<li>Livonsaaren osuuskauppa palvelee: Infopiste</li>
|
|
||||||
<li>
|
|
||||||
Majoituspalvelut Velkualla: Wanha Salakuljettaja, Saaristohotelli
|
|
||||||
Vaihela
|
|
||||||
</li>
|
|
||||||
<li>Bussi- ja kimppataksikuljetukset</li>
|
|
||||||
<li>Kartta</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<h1>New Info</h1>
|
<h1>Uusi info kappale</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_info_path(@conn, :create)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_info_path(@conn, :create)) %>
|
||||||
|
|
||||||
<span><%= link "Back", to: Routes.admin_info_path(@conn, :admin) %></span>
|
<span><%= link "Takasin", to: Routes.admin_info_path(@conn, :admin) %></span>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
<h1>Muokkaa näytöksen tietoja</h1>
|
<h1>Muokkaa näytöksen tietoja</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performance_path(@conn, :update, @performance)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performance_path(@conn, :update, @performance)) %>
|
||||||
|
|
||||||
<span><%= link "Takaisin", to: Routes.admin_performance_path(@conn, :admin) %></span>
|
<span><%= link "Takaisin", to: Routes.admin_performance_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
<h1>Muokkaa esiintyjän tietoja</h1>
|
<h1>Muokkaa esiintyjän tietoja</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performer_path(@conn, :update, @performer)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performer_path(@conn, :update, @performer)) %>
|
||||||
|
|
||||||
<span><%= link "Takaisin", to: Routes.admin_performer_path(@conn, :admin) %></span>
|
<span><%= link "Takaisin", to: Routes.admin_performer_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
|
|||||||
30
lib/runosaari_web/templates/survival/admin.html.eex
Normal file
30
lib/runosaari_web/templates/survival/admin.html.eex
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>HALLINTA - Survival listan kohdat</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Sisältö</th>
|
||||||
|
<th>Priotiteetti</th>
|
||||||
|
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<%= for survival <- @survival_items do %>
|
||||||
|
<tr>
|
||||||
|
<td><%= survival.content %></td>
|
||||||
|
<td><%= survival.seqnum %></td>
|
||||||
|
|
||||||
|
<td class="actions">
|
||||||
|
<span><%= link "Lisätietoja", to: Routes.admin_survival_path(@conn, :show, survival) %></span>
|
||||||
|
<span><%= link "Muokkaa", to: Routes.admin_survival_path(@conn, :edit, survival) %></span>
|
||||||
|
<span><%= link "Poista", to: Routes.admin_survival_path(@conn, :delete, survival), method: :delete, data: [confirm: "Oletko varma?"] %></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<span><%= link "Luo uusi survival kohta", to: Routes.admin_survival_path(@conn, :new) %></span>
|
||||||
|
</section>
|
||||||
7
lib/runosaari_web/templates/survival/edit.html.eex
Normal file
7
lib/runosaari_web/templates/survival/edit.html.eex
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>Muokkaa survival listan kohtaa</h1>
|
||||||
|
|
||||||
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_survival_path(@conn, :update, @survival)) %>
|
||||||
|
|
||||||
|
<span><%= link "Takaisin", to: Routes.admin_survival_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
19
lib/runosaari_web/templates/survival/form.html.eex
Normal file
19
lib/runosaari_web/templates/survival/form.html.eex
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<%= form_for @changeset, @action, fn f -> %>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<p>Joku kentistä on tyhjä.</p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label f, :content, "Sisältö" %>
|
||||||
|
<%= textarea f, :content %>
|
||||||
|
<%= error_tag f, :content %>
|
||||||
|
|
||||||
|
<%= label f, :seqnum, "Prioritetti (1 on korkein)" %>
|
||||||
|
<%= number_input f, :seqnum %>
|
||||||
|
<%= error_tag f, :seqnum %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= submit "Tallenna" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
5
lib/runosaari_web/templates/survival/new.html.eex
Normal file
5
lib/runosaari_web/templates/survival/new.html.eex
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<h1>Uusi survival listan kohta</h1>
|
||||||
|
|
||||||
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_survival_path(@conn, :create)) %>
|
||||||
|
|
||||||
|
<span><%= link "Takaisin", to: Routes.admin_survival_path(@conn, :admin) %></span>
|
||||||
20
lib/runosaari_web/templates/survival/show.html.eex
Normal file
20
lib/runosaari_web/templates/survival/show.html.eex
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>Survival listan kohdan tiedot</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Sisältö:</strong>
|
||||||
|
<%= @survival.content %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Prioriteetti:</strong>
|
||||||
|
<%= @survival.seqnum %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<span><%= link "Muokkaa", to: Routes.admin_survival_path(@conn, :edit, @survival) %></span>
|
||||||
|
<span><%= link "Takaisin", to: Routes.admin_survival_path(@conn, :admin) %></span>
|
||||||
|
</section>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
<h1>Muokkaa osallistujan tietoja</h1>
|
<h1>Muokkaa osallistujan tietoja</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_visitor_path(@conn, :update, @visitor)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_visitor_path(@conn, :update, @visitor)) %>
|
||||||
|
|
||||||
<span><%= link "Takaisin", to: Routes.admin_visitor_path(@conn, :index) %></span>
|
<span><%= link "Takaisin", to: Routes.admin_visitor_path(@conn, :index) %></span>
|
||||||
|
</section>
|
||||||
|
|||||||
3
lib/runosaari_web/views/survival_view.ex
Normal file
3
lib/runosaari_web/views/survival_view.ex
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
defmodule RunosaariWeb.SurvivalView do
|
||||||
|
use RunosaariWeb, :view
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
defmodule Runosaari.Repo.Migrations.CreateSurvivalItems do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:survival_items) do
|
||||||
|
add :content, :string, size: 3000
|
||||||
|
add :seqnum, :integer
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -124,4 +124,65 @@ defmodule Runosaari.PagesTest do
|
|||||||
assert %Ecto.Changeset{} = Pages.change_info(info)
|
assert %Ecto.Changeset{} = Pages.change_info(info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "survival_items" do
|
||||||
|
alias Runosaari.Pages.Survival
|
||||||
|
|
||||||
|
@valid_attrs %{content: "some content", seqnum: 42}
|
||||||
|
@update_attrs %{content: "some updated content", seqnum: 43}
|
||||||
|
@invalid_attrs %{content: nil, seqnum: nil}
|
||||||
|
|
||||||
|
def survival_fixture(attrs \\ %{}) do
|
||||||
|
{:ok, survival} =
|
||||||
|
attrs
|
||||||
|
|> Enum.into(@valid_attrs)
|
||||||
|
|> Pages.create_survival()
|
||||||
|
|
||||||
|
survival
|
||||||
|
end
|
||||||
|
|
||||||
|
test "list_survival_items/0 returns all survival_items" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert Pages.list_survival_items() == [survival]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "get_survival!/1 returns the survival with given id" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert Pages.get_survival!(survival.id) == survival
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_survival/1 with valid data creates a survival" do
|
||||||
|
assert {:ok, %Survival{} = survival} = Pages.create_survival(@valid_attrs)
|
||||||
|
assert survival.content == "some content"
|
||||||
|
assert survival.seqnum == 42
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_survival/1 with invalid data returns error changeset" do
|
||||||
|
assert {:error, %Ecto.Changeset{}} = Pages.create_survival(@invalid_attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_survival/2 with valid data updates the survival" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert {:ok, %Survival{} = survival} = Pages.update_survival(survival, @update_attrs)
|
||||||
|
assert survival.content == "some updated content"
|
||||||
|
assert survival.seqnum == 43
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_survival/2 with invalid data returns error changeset" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert {:error, %Ecto.Changeset{}} = Pages.update_survival(survival, @invalid_attrs)
|
||||||
|
assert survival == Pages.get_survival!(survival.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_survival/1 deletes the survival" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert {:ok, %Survival{}} = Pages.delete_survival(survival)
|
||||||
|
assert_raise Ecto.NoResultsError, fn -> Pages.get_survival!(survival.id) end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "change_survival/1 returns a survival changeset" do
|
||||||
|
survival = survival_fixture()
|
||||||
|
assert %Ecto.Changeset{} = Pages.change_survival(survival)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ defmodule RunosaariWeb.InfoControllerTest do
|
|||||||
describe "index" do
|
describe "index" do
|
||||||
test "lists all info_paragraphs", %{conn: conn} do
|
test "lists all info_paragraphs", %{conn: conn} do
|
||||||
conn = get(conn, Routes.info_path(conn, :index))
|
conn = get(conn, Routes.info_path(conn, :index))
|
||||||
assert html_response(conn, 200) =~ "Listing Info paragraphs"
|
assert html_response(conn, 200) =~ "Info"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "new info" do
|
describe "new info" do
|
||||||
test "renders form", %{conn: conn} do
|
test "renders form", %{conn: conn} do
|
||||||
conn = get(conn, Routes.info_path(conn, :new))
|
conn = get(conn, Routes.info_path(conn, :new))
|
||||||
assert html_response(conn, 200) =~ "New Info"
|
assert html_response(conn, 200) =~ "Uusi info kappale"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ defmodule RunosaariWeb.InfoControllerTest do
|
|||||||
assert redirected_to(conn) == Routes.info_path(conn, :show, id)
|
assert redirected_to(conn) == Routes.info_path(conn, :show, id)
|
||||||
|
|
||||||
conn = get(conn, Routes.info_path(conn, :show, id))
|
conn = get(conn, Routes.info_path(conn, :show, id))
|
||||||
assert html_response(conn, 200) =~ "Show Info"
|
assert html_response(conn, 200) =~ "Kappaleen tiedot"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders errors when data is invalid", %{conn: conn} do
|
test "renders errors when data is invalid", %{conn: conn} do
|
||||||
conn = post(conn, Routes.info_path(conn, :create), info: @invalid_attrs)
|
conn = post(conn, Routes.info_path(conn, :create), info: @invalid_attrs)
|
||||||
assert html_response(conn, 200) =~ "New Info"
|
assert html_response(conn, 200) =~ "Uusi info kappale"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ defmodule RunosaariWeb.InfoControllerTest do
|
|||||||
|
|
||||||
test "renders form for editing chosen info", %{conn: conn, info: info} do
|
test "renders form for editing chosen info", %{conn: conn, info: info} do
|
||||||
conn = get(conn, Routes.info_path(conn, :edit, info))
|
conn = get(conn, Routes.info_path(conn, :edit, info))
|
||||||
assert html_response(conn, 200) =~ "Edit Info"
|
assert html_response(conn, 200) =~ "Muokkaa kappaletta"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ defmodule RunosaariWeb.InfoControllerTest do
|
|||||||
|
|
||||||
test "renders errors when data is invalid", %{conn: conn, info: info} do
|
test "renders errors when data is invalid", %{conn: conn, info: info} do
|
||||||
conn = put(conn, Routes.info_path(conn, :update, info), info: @invalid_attrs)
|
conn = put(conn, Routes.info_path(conn, :update, info), info: @invalid_attrs)
|
||||||
assert html_response(conn, 200) =~ "Edit Info"
|
assert html_response(conn, 200) =~ "Muokkaa kappaletta"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -75,6 +75,7 @@ defmodule RunosaariWeb.InfoControllerTest do
|
|||||||
test "deletes chosen info", %{conn: conn, info: info} do
|
test "deletes chosen info", %{conn: conn, info: info} do
|
||||||
conn = delete(conn, Routes.info_path(conn, :delete, info))
|
conn = delete(conn, Routes.info_path(conn, :delete, info))
|
||||||
assert redirected_to(conn) == Routes.info_path(conn, :index)
|
assert redirected_to(conn) == Routes.info_path(conn, :index)
|
||||||
|
|
||||||
assert_error_sent 404, fn ->
|
assert_error_sent 404, fn ->
|
||||||
get(conn, Routes.info_path(conn, :show, info))
|
get(conn, Routes.info_path(conn, :show, info))
|
||||||
end
|
end
|
||||||
|
|||||||
93
test/runosaari_web/controllers/survival_controller_test.exs
Normal file
93
test/runosaari_web/controllers/survival_controller_test.exs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
defmodule RunosaariWeb.SurvivalControllerTest do
|
||||||
|
use RunosaariWeb.ConnCase
|
||||||
|
|
||||||
|
alias Runosaari.Pages
|
||||||
|
|
||||||
|
@create_attrs %{content: "some content", seqnum: 42}
|
||||||
|
@update_attrs %{content: "some updated content", seqnum: 43}
|
||||||
|
@invalid_attrs %{content: nil, seqnum: nil}
|
||||||
|
|
||||||
|
def fixture(:survival) do
|
||||||
|
{:ok, survival} = Pages.create_survival(@create_attrs)
|
||||||
|
survival
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "admin" do
|
||||||
|
test "lists all survival_items", %{conn: conn} do
|
||||||
|
conn = get(conn, Routes.admin_survival_path(conn, :admin))
|
||||||
|
assert html_response(conn, 200) =~ "HALLINTA - Survival listan kohdat"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "new survival" do
|
||||||
|
test "renders form", %{conn: conn} do
|
||||||
|
conn = get(conn, Routes.admin_survival_path(conn, :new))
|
||||||
|
assert html_response(conn, 200) =~ "Uusi survival listan kohta"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "create survival" do
|
||||||
|
test "redirects to show when data is valid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.admin_survival_path(conn, :create), survival: @create_attrs)
|
||||||
|
|
||||||
|
assert %{id: id} = redirected_params(conn)
|
||||||
|
assert redirected_to(conn) == Routes.admin_survival_path(conn, :show, id)
|
||||||
|
|
||||||
|
conn = get(conn, Routes.admin_survival_path(conn, :show, id))
|
||||||
|
assert html_response(conn, 200) =~ "Survival listan kohdan tiedot"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders errors when data is invalid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.admin_survival_path(conn, :create), survival: @invalid_attrs)
|
||||||
|
assert html_response(conn, 200) =~ "Uusi survival listan kohta"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "edit survival" do
|
||||||
|
setup [:create_survival]
|
||||||
|
|
||||||
|
test "renders form for editing chosen survival", %{conn: conn, survival: survival} do
|
||||||
|
conn = get(conn, Routes.admin_survival_path(conn, :edit, survival))
|
||||||
|
assert html_response(conn, 200) =~ "Muokkaa survival listan kohtaa"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update survival" do
|
||||||
|
setup [:create_survival]
|
||||||
|
|
||||||
|
test "redirects when data is valid", %{conn: conn, survival: survival} do
|
||||||
|
conn =
|
||||||
|
put(conn, Routes.admin_survival_path(conn, :update, survival), survival: @update_attrs)
|
||||||
|
|
||||||
|
assert redirected_to(conn) == Routes.admin_survival_path(conn, :show, survival)
|
||||||
|
|
||||||
|
conn = get(conn, Routes.admin_survival_path(conn, :show, survival))
|
||||||
|
assert html_response(conn, 200) =~ "some updated content"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders errors when data is invalid", %{conn: conn, survival: survival} do
|
||||||
|
conn =
|
||||||
|
put(conn, Routes.admin_survival_path(conn, :update, survival), survival: @invalid_attrs)
|
||||||
|
|
||||||
|
assert html_response(conn, 200) =~ "Muokkaa survival listan kohtaa"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "delete survival" do
|
||||||
|
setup [:create_survival]
|
||||||
|
|
||||||
|
test "deletes chosen survival", %{conn: conn, survival: survival} do
|
||||||
|
conn = delete(conn, Routes.admin_survival_path(conn, :delete, survival))
|
||||||
|
assert redirected_to(conn) == Routes.admin_survival_path(conn, :admin)
|
||||||
|
|
||||||
|
assert_error_sent 404, fn ->
|
||||||
|
get(conn, Routes.admin_survival_path(conn, :show, survival))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp create_survival(_) do
|
||||||
|
survival = fixture(:survival)
|
||||||
|
%{survival: survival}
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user