Phoenix:Mix phoenix.gen.html生成失败的测试

时间:2017-04-13 10:42:16

标签: elixir phoenix-framework

我运行 SELECT (SELECT sum(transaction_item.item_price) from transaction_item where transaction_item.entry_id IN (select group_concat(entry_id) from transaction_item group by entry_id)) AS new ,然后mix phoenix.gen.html Topic topics title used:boolean运行迁移。

我将此添加到我的路线

mix ecto.migrate

之后我运行了主题控制器的测试,其中一些失败了:

defmodule ParrotApi.Router do
  use ParrotApi.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", ParrotApi do
    pipe_through :browser # Use the default browser stack

    resources "/topics", TopicController #<-----------------------------
    get "/", CallController, :index
  end
end

这是我的依赖项列表:

➜  parrot-api git:(master) ✗ mix test test/controllers/topic_controller_test.exs:13
Including tags: [line: "13"]
Excluding tags: [:test]



  1) test renders form for new resources (ParrotApi.TopicControllerTest)
     test/controllers/topic_controller_test.exs:13
     ** (Phoenix.Template.UndefinedError) Could not render "app.html" for ParrotApi.LayoutView, please define a matching clause for render/2 or define a template at "web/templates/layout". No templates were compiled for this module.
     Assigns:

     %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #ParrotApi.Topic<>, valid?: false>, conn: %Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :...}, assigns: %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #ParrotApi.Topic<>, valid?: false>, layout: {ParrotApi.LayoutView, "app.html"}}, before_send: [#Function<0.101282891/1 in Plug.CSRFProtection.call/2>, #Function<4.39648223/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.131660147/1 in Plug.Session.before_send/2>, #Function<1.120807292/1 in Plug.Logger.call/2>], body_params: %{}, cookies: %{}, halted: false, host: "www.example.com", method: "GET", owner: #PID<0.330.0>, params: %{}, path_info: ["topics", "new"], path_params: %{}, peer: {{127, 0, 0, 1}, 111317}, port: 80, private: %{ParrotApi.Router => {[], %{}}, :phoenix_action => :new, :phoenix_controller => ParrotApi.TopicController, :phoenix_endpoint => ParrotApi.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {ParrotApi.LayoutView, :app}, :phoenix_pipelines => [:browser], :phoenix_recycled => true, :phoenix_route => #Function<9.45870687/1 in ParrotApi.Router.match_route/4>, :phoenix_router => ParrotApi.Router, :phoenix_template => "new.html", :phoenix_view => ParrotApi.TopicView, :plug_session => %{}, :plug_session_fetch => :done, :plug_skip_csrf_protection => true}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [], request_path: "/topics/new", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "4885goamao9jhvne2upmbjdmd56iqfdu"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}], scheme: :http, script_name: [], secret_key_base: "JzeH+GcCE+1xgWtHDgHyG8YyZAU5WCcT2GJGLjdpXKbXfsdJF3YnJNYhc7llI75r", state: :unset, status: nil}, template_not_found: ParrotApi.LayoutView, view_module: ParrotApi.TopicView, view_template: "new.html"}

     stacktrace:
       (phoenix) lib/phoenix/template.ex:364: Phoenix.Template.raise_template_not_found/3
       (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
       (phoenix) lib/phoenix/controller.ex:646: Phoenix.Controller.do_render/4
       (parrot_api) web/controllers/topic_controller.ex:1: ParrotApi.TopicController.action/2
       (parrot_api) web/controllers/topic_controller.ex:1: ParrotApi.TopicController.phoenix_controller_pipeline/2
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.instrument/4
       (parrot_api) lib/phoenix/router.ex:261: ParrotApi.Router.dispatch/2
       (parrot_api) web/router.ex:1: ParrotApi.Router.do_call/2
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.phoenix_pipeline/1
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.call/2
       (phoenix) lib/phoenix/test/conn_test.ex:224: Phoenix.ConnTest.dispatch/5
       test/controllers/topic_controller_test.exs:14: (test)



Finished in 0.1 seconds
10 tests, 1 failure, 9 skipped

发生了什么事?

1 个答案:

答案 0 :(得分:0)

必须将此添加到我的test.exs文件中:

config :phoenix, :template_engines,
 slim: PhoenixSlime.Engine,
 slime: PhoenixSlime.Engine