I’m having some further problems with the generated tests for my controller.
I ran
mix phx.gen.json Propsects Person persons {with my data parameters} --web Prospects
and the migration, schema and controller files (with tests) were generated. I added the resource to my Router and ran mix.phx.routes to verify with the following results:
mix phx.routes
page_path GET / ScandimensionWeb.PageController :index
admin_path GET /admin ScandimensionWeb.AdminController :index
user_path GET /api/users ScandimensionWeb.UserController :index
user_path GET /api/users/:id ScandimensionWeb.UserController :show
user_path POST /api/users ScandimensionWeb.UserController :create
user_path PATCH /api/users/:id ScandimensionWeb.UserController :update
PUT /api/users/:id ScandimensionWeb.UserController :update
user_path DELETE /api/users/:id ScandimensionWeb.UserController :delete
user_path POST /api/users/sign_in ScandimensionWeb.UserController :sign_in
person_path GET /prospects/persons ScandimensionWeb.PersonController :index
person_path GET /prospects/persons/:id/edit ScandimensionWeb.PersonController :edit
person_path GET /prospects/persons/new ScandimensionWeb.PersonController :new
person_path GET /prospects/persons/:id ScandimensionWeb.PersonController :show
person_path POST /prospects/persons ScandimensionWeb.PersonController :create
person_path PATCH /prospects/persons/:id ScandimensionWeb.PersonController :update
PUT /prospects/persons/:id ScandimensionWeb.PersonController :update
person_path DELETE /prospects/persons/:id ScandimensionWeb.PersonController :delete
websocket WS /socket/websocket ScandimensionWeb.UserSocket
When I run mix test, the new PersonControllerTest fails on each call to:
Routes.prospects_person_path(conn, :index))
with the following error message:
** (UndefinedFunctionError) function ScandimensionWeb.Router.Helpers.prospects_person_path/2 is undefined or private
code: conn = post(conn, Routes.prospects_person_path(conn, :create), person: @create_attrs)
stacktrace:
(scandimension) ScandimensionWeb.Router.Helpers.prospects_person_path(%Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :…}, assigns: %{}, before_send: , body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: “www.example.com”, method: “GET”, owner: #PID<0.439.0>, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: , path_params: %{}, port: 80, private: %{phoenix_recycled: true, plug_skip_csrf_protection: true}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: “”, remote_ip: {127, 0, 0, 1}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [{“accept”, “application/json”}], request_path: “/”, resp_body: nil, resp_cookies: %{}, resp_headers: [{“cache-control”, “max-age=0, private, must-revalidate”}], scheme: :http, script_name: , secret_key_base: nil, state: :unset, status: nil}, :create)
test/scandimension_web/controllers/prospects/person_controller_test.exs:43: (test)
I checked the helpers via iex:
iex(4)> ScandimensionWeb.Router.Helpers.
admin_path/2 admin_path/3 admin_url/2 admin_url/3
page_path/2 page_path/3 page_url/2 page_url/3
path/2 person_path/2 person_path/3 person_path/4
person_url/2 person_url/3 person_url/4 static_path/2
static_url/2 url/1 user_path/2 user_path/3
user_path/4 user_url/2 user_url/3 user_url/4
And agree that prospects_person_path is not defined, but I’m not certain how to fix this.
Any guidance?
Thanks,