@@ -18,35 +18,58 @@ defmodule AppWeb.ItemControllerTest do
1818 item
1919 end
2020
21- describe "edit item" do
21+ describe "edit item's list " do
2222 setup [ :create_item , :create_list ]
2323
24- test "renders form for editing chosen item's lists" , % {
24+ test "renders form for editing item's lists" , % {
2525 conn: conn ,
26- list: list ,
2726 item: item
2827 } do
2928 conn =
3029 conn
3130 |> assign ( :person , % { id: 1 } )
3231 |> get ( Routes . item_path ( conn , :edit , item ) )
3332
34- assert html_response ( conn , 200 ) =~ "Edit Item's lists "
33+ assert html_response ( conn , 200 ) =~ "Edit Item"
3534 end
3635 end
3736
38- # describe "update item's list" do
39- # setup [:create_item, :create_list]
40- #
41- # test "redirects to index when data is valid", %{conn: conn, list: list} do
42- # conn =
43- # conn
44- # |> assign(:person, %{id: 1})
45- # |> put(Routes.list_path(conn, :update, list), list: @update_attrs)
46- #
47- # assert redirected_to(conn) == Routes.list_path(conn, :index)
48- # end
49- # end
37+ describe "update item's list" do
38+ setup [ :create_item , :create_list ]
39+
40+ test "Add a list to an item" , % {
41+ conn: conn ,
42+ list: list ,
43+ item: item
44+ } do
45+ update_params = % { item_lists: [ list . id ] }
46+
47+ conn =
48+ conn
49+ |> assign ( :person , % { id: 1 } )
50+ |> put ( Routes . item_path ( conn , :update , item ) , item: update_params )
51+
52+ assert length ( Item . get_item! ( item . id ) . lists ) == 1
53+
54+ assert redirected_to ( conn ) == "/"
55+ end
56+
57+ test "Remove list from item" , % {
58+ conn: conn ,
59+ item: item
60+ } do
61+ update_params = % { item_lists: "" }
62+
63+ conn =
64+ conn
65+ |> assign ( :person , % { id: 1 } )
66+ |> put ( Routes . item_path ( conn , :update , item ) , item: update_params )
67+
68+ assert length ( Item . get_item! ( item . id ) . lists ) == 0
69+
70+ assert redirected_to ( conn ) == "/"
71+ end
72+ end
5073
5174 defp create_list ( _ ) do
5275 list = fixture ( :list )
0 commit comments