fixed errors found by tests; fixed tests
This commit is contained in:
parent
42c7a49e88
commit
6c5d6ce046
5 changed files with 93 additions and 37 deletions
|
@ -1,4 +1,5 @@
|
||||||
<%= form_for @changeset, "#", [
|
<%= form_for @changeset, "#", [
|
||||||
|
id: "property-form",
|
||||||
phx_target: @myself,
|
phx_target: @myself,
|
||||||
phx_change: "validate",
|
phx_change: "validate",
|
||||||
phx_submit: "save"
|
phx_submit: "save"
|
||||||
|
|
|
@ -17,18 +17,29 @@ defmodule Bones73kWeb.PropertyLive.Show do
|
||||||
property = Properties.get_property!(id)
|
property = Properties.get_property!(id)
|
||||||
|
|
||||||
if Roles.can?(current_user, property, live_action) do
|
if Roles.can?(current_user, property, live_action) do
|
||||||
{:noreply,
|
socket
|
||||||
socket
|
|> assign(:property, property)
|
||||||
|> assign(:property, property)
|
|> assign(:page_title, page_title(live_action))
|
||||||
|> assign(:page_title, page_title(live_action))}
|
|> assign(:modal_return_to, Routes.property_show_path(socket, :show, property))
|
||||||
|
|> live_noreply()
|
||||||
else
|
else
|
||||||
{:noreply,
|
socket
|
||||||
socket
|
|> put_flash(:error, "Unauthorised")
|
||||||
|> put_flash(:error, "Unauthorised")
|
|> redirect(to: "/")
|
||||||
|> redirect(to: "/")}
|
|> live_noreply()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info({:close_modal, _}, %{assigns: %{modal_return_to: to}} = socket) do
|
||||||
|
socket |> copy_flash() |> push_patch(to: to) |> live_noreply()
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info({:put_flash_message, {flash_type, msg}}, socket) do
|
||||||
|
socket |> put_flash(flash_type, msg) |> live_noreply()
|
||||||
|
end
|
||||||
|
|
||||||
defp page_title(:show), do: "Show Property"
|
defp page_title(:show), do: "Show Property"
|
||||||
defp page_title(:edit), do: "Edit Property"
|
defp page_title(:edit), do: "Edit Property"
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
id: @property.id,
|
id: @property.id,
|
||||||
title: @page_title,
|
title: @page_title,
|
||||||
action: @live_action,
|
action: @live_action,
|
||||||
property: @property,
|
property: @property %>
|
||||||
return_to: Routes.property_show_path(@socket, :show, @property) %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<table class="table table-nonfluid">
|
<table class="table table-nonfluid">
|
||||||
|
|
|
@ -54,14 +54,23 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
||||||
|> form("#property-form", property: @invalid_attrs)
|
|> form("#property-form", property: @invalid_attrs)
|
||||||
|> render_change() =~ "can't be blank"
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
{:ok, _, html} =
|
# update form attrs
|
||||||
index_live
|
index_live
|
||||||
|> form("#property-form", property: @create_attrs)
|
|> form("#property-form", property: @update_attrs)
|
||||||
|> render_submit()
|
|> render_change()
|
||||||
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
|
|
||||||
|
|
||||||
|
# submit new form attrs
|
||||||
|
index_live
|
||||||
|
|> form("#property-form", property: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
# send modal close event & observe results
|
||||||
|
send(index_live.pid, {:close_modal, true})
|
||||||
|
html = render(index_live)
|
||||||
|
|
||||||
|
assert_patched(index_live, Routes.property_index_path(conn, :index))
|
||||||
assert html =~ "Property created successfully"
|
assert html =~ "Property created successfully"
|
||||||
assert html =~ "some description"
|
assert html =~ "some updated description"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates property in listing", %{conn: conn, property: property} do
|
test "updates property in listing", %{conn: conn, property: property} do
|
||||||
|
@ -76,12 +85,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
||||||
|> form("#property-form", property: @invalid_attrs)
|
|> form("#property-form", property: @invalid_attrs)
|
||||||
|> render_change() =~ "can't be blank"
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
{:ok, _, html} =
|
# update form attrs
|
||||||
index_live
|
index_live
|
||||||
|> form("#property-form", property: @update_attrs)
|
|> form("#property-form", property: @update_attrs)
|
||||||
|> render_submit()
|
|> render_change()
|
||||||
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
|
|
||||||
|
|
||||||
|
# submit new form attrs
|
||||||
|
index_live
|
||||||
|
|> form("#property-form", property: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
# send modal close event & observe results
|
||||||
|
send(index_live.pid, {:close_modal, true})
|
||||||
|
html = render(index_live)
|
||||||
|
|
||||||
|
assert_patched(index_live, Routes.property_index_path(conn, :index))
|
||||||
assert html =~ "Property updated successfully"
|
assert html =~ "Property updated successfully"
|
||||||
assert html =~ "some updated description"
|
assert html =~ "some updated description"
|
||||||
end
|
end
|
||||||
|
@ -130,12 +148,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
||||||
|> form("#property-form", property: @invalid_attrs)
|
|> form("#property-form", property: @invalid_attrs)
|
||||||
|> render_change() =~ "can't be blank"
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
{:ok, _, html} =
|
# update form attrs
|
||||||
index_live
|
index_live
|
||||||
|> form("#property-form", property: @update_attrs)
|
|> form("#property-form", property: @update_attrs)
|
||||||
|> render_submit()
|
|> render_change()
|
||||||
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
|
|
||||||
|
|
||||||
|
# submit new form attrs
|
||||||
|
index_live
|
||||||
|
|> form("#property-form", property: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
# send modal close event & observe results
|
||||||
|
send(index_live.pid, {:close_modal, true})
|
||||||
|
html = render(index_live)
|
||||||
|
|
||||||
|
assert_patched(index_live, Routes.property_index_path(conn, :index))
|
||||||
assert html =~ "Property updated successfully"
|
assert html =~ "Property updated successfully"
|
||||||
assert html =~ "some updated description"
|
assert html =~ "some updated description"
|
||||||
end
|
end
|
||||||
|
@ -257,12 +284,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
||||||
|> form("#property-form", property: @invalid_attrs)
|
|> form("#property-form", property: @invalid_attrs)
|
||||||
|> render_change() =~ "can't be blank"
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
{:ok, _, html} =
|
# update form attrs
|
||||||
show_live
|
show_live
|
||||||
|> form("#property-form", property: @update_attrs)
|
|> form("#property-form", property: @update_attrs)
|
||||||
|> render_submit()
|
|> render_change()
|
||||||
|> follow_redirect(conn, Routes.property_show_path(conn, :show, property))
|
|
||||||
|
|
||||||
|
# submit new form attrs
|
||||||
|
show_live
|
||||||
|
|> form("#property-form", property: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
# send modal close event & observe results
|
||||||
|
send(show_live.pid, {:close_modal, true})
|
||||||
|
html = render(show_live)
|
||||||
|
|
||||||
|
assert_patched(show_live, Routes.property_show_path(conn, :show, property))
|
||||||
assert html =~ "Property updated successfully"
|
assert html =~ "Property updated successfully"
|
||||||
assert html =~ "some updated description"
|
assert html =~ "some updated description"
|
||||||
end
|
end
|
||||||
|
@ -293,12 +329,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
||||||
|> form("#property-form", property: @invalid_attrs)
|
|> form("#property-form", property: @invalid_attrs)
|
||||||
|> render_change() =~ "can't be blank"
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
{:ok, _, html} =
|
# update form attrs
|
||||||
show_live
|
show_live
|
||||||
|> form("#property-form", property: @update_attrs)
|
|> form("#property-form", property: @update_attrs)
|
||||||
|> render_submit()
|
|> render_change()
|
||||||
|> follow_redirect(conn, Routes.property_show_path(conn, :show, property))
|
|
||||||
|
|
||||||
|
# submit new form attrs
|
||||||
|
show_live
|
||||||
|
|> form("#property-form", property: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
# send modal close event & observe results
|
||||||
|
send(show_live.pid, {:close_modal, true})
|
||||||
|
html = render(show_live)
|
||||||
|
|
||||||
|
assert_patched(show_live, Routes.property_show_path(conn, :show, property))
|
||||||
assert html =~ "Property updated successfully"
|
assert html =~ "Property updated successfully"
|
||||||
assert html =~ "some updated description"
|
assert html =~ "some updated description"
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,7 +36,7 @@ defmodule Bones73k.AccountsFixtures do
|
||||||
# {:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
# {:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
||||||
# [_, token, _] = String.split(captured.body, "[TOKEN]")
|
# [_, token, _] = String.split(captured.body, "[TOKEN]")
|
||||||
# token
|
# token
|
||||||
%Bamboo.Email{} = email = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
{:ok, %Bamboo.Email{} = email} = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
||||||
[_, token, _] = String.split(email.text_body, "[TOKEN]")
|
[_, token, _] = String.split(email.text_body, "[TOKEN]")
|
||||||
token
|
token
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue