diff --git a/lib/phoenixRealWorld_web/live/article_live/form_component.ex b/lib/phoenixRealWorld_web/live/article_live/form_component.ex index 29ee691..37a0045 100644 --- a/lib/phoenixRealWorld_web/live/article_live/form_component.ex +++ b/lib/phoenixRealWorld_web/live/article_live/form_component.ex @@ -65,6 +65,7 @@ defmodule PhoenixRealWorldWeb.ArticleLive.FormComponent do end defp save_article(socket, :new, article_params) do + article_params = Map.put(article_params, "user_id", socket.assigns.current_user.id) case Blogs.create_article(article_params) do {:ok, article} -> notify_parent({:saved, article}) diff --git a/lib/phoenixRealWorld_web/live/article_live/index.html.heex b/lib/phoenixRealWorld_web/live/article_live/index.html.heex index 38dfa69..16ca11d 100644 --- a/lib/phoenixRealWorld_web/live/article_live/index.html.heex +++ b/lib/phoenixRealWorld_web/live/article_live/index.html.heex @@ -18,16 +18,16 @@
<.link navigate={~p"/articles/#{article}"}>Show
- <.link patch={~p"/articles/#{article}/edit"}>Edit + <%!-- <.link patch={~p"/articles/#{article}/edit"}>Edit --%> - <:action :let={{id, article}}> + <%!-- <:action :let={{id, article}}> <.link phx-click={JS.push("delete", value: %{id: article.id}) |> hide("##{id}")} data-confirm="Are you sure?" > Delete - + --%> <.modal :if={@live_action in [:new, :edit]} id="article-modal" show on_cancel={JS.patch(~p"/articles")}> @@ -37,6 +37,7 @@ title={@page_title} action={@live_action} article={@article} + current_user={@current_user} patch={~p"/articles"} /> diff --git a/test/phoenixRealWorld_web/live/article_live_test.exs b/test/phoenixRealWorld_web/live/article_live_test.exs index 6fdf6cb..4458021 100644 --- a/test/phoenixRealWorld_web/live/article_live_test.exs +++ b/test/phoenixRealWorld_web/live/article_live_test.exs @@ -24,7 +24,12 @@ defmodule PhoenixRealWorldWeb.ArticleLiveTest do end test "saves new article", %{conn: conn} do - {:ok, index_live, _html} = live(conn, ~p"/articles") + # {:ok, index_live, _html} = live(conn, ~p"/articles") + #↓追加 + {:ok, index_live, _html} = + conn + |> log_in_user(user_fixture()) + |> live(~p"/articles") assert index_live |> element("a", "New Article") |> render_click() =~ "New Article" @@ -46,35 +51,35 @@ defmodule PhoenixRealWorldWeb.ArticleLiveTest do assert html =~ "some title" end - test "updates article in listing", %{conn: conn, article: article} do - {:ok, index_live, _html} = live(conn, ~p"/articles") + # test "updates article in listing", %{conn: conn, article: article} do + # {:ok, index_live, _html} = live(conn, ~p"/articles") - assert index_live |> element("#articles-#{article.id} a", "Edit") |> render_click() =~ - "Edit Article" + # assert index_live |> element("#articles-#{article.id} a", "Edit") |> render_click() =~ + # "Edit Article" - assert_patch(index_live, ~p"/articles/#{article}/edit") + # assert_patch(index_live, ~p"/articles/#{article}/edit") - assert index_live - |> form("#article-form", article: @invalid_attrs) - |> render_change() =~ "can't be blank" + # assert index_live + # |> form("#article-form", article: @invalid_attrs) + # |> render_change() =~ "can't be blank" - assert index_live - |> form("#article-form", article: @update_attrs) - |> render_submit() + # assert index_live + # |> form("#article-form", article: @update_attrs) + # |> render_submit() - assert_patch(index_live, ~p"/articles") + # assert_patch(index_live, ~p"/articles") - html = render(index_live) - assert html =~ "Article updated successfully" - assert html =~ "some updated title" - end + # html = render(index_live) + # assert html =~ "Article updated successfully" + # assert html =~ "some updated title" + # end - test "deletes article in listing", %{conn: conn, article: article} do - {:ok, index_live, _html} = live(conn, ~p"/articles") + # test "deletes article in listing", %{conn: conn, article: article} do + # {:ok, index_live, _html} = live(conn, ~p"/articles") - assert index_live |> element("#articles-#{article.id} a", "Delete") |> render_click() - refute has_element?(index_live, "#articles-#{article.id}") - end + # assert index_live |> element("#articles-#{article.id} a", "Delete") |> render_click() + # refute has_element?(index_live, "#articles-#{article.id}") + # end end describe "Show" do