2013-08-19 47 views
1

我使用的是forem引擎引擎,我無法寫rspec 請求規範,因爲我嘗試使用的路由無法找到(根據rspec)。我想使用請求規範來創建POST請求來創建對主題的回覆。找不到路徑引擎rspec請求規範

在請求規範下不起作用:

post "/forums/topics/#{topic.to_param}/posts", :post => { 'text' => 'reply' } 

它失敗

No route matches [POST] "/forums/topics/first-topic/posts" 

這裏的東西怎麼看:耙路線從spec/dummy

Routes for Forem::Engine: 
    POST /topics/:topic_id/posts(.:format)  forem/posts#create 

原木從網站創建一個帖子

Started POST "/forums/topics/welcome-to-forem/posts" for 127.0.0.1 at 2013-08-19 22:23:47 +0800 
Processing by Forem::PostsController#create as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"vnzhdaRDTye1wM5eQEIAW8W/urG/18PJ02oPqcX3pK8=", "post"=>{"text"=>"asdf", "reply_to_id"=>"1"}, "commit"=>"Post Reply", "topic_id"=>"welcome-to-forem"} 

從請求規範中的pry會話 - 顯示路徑被forem識別,但不是主機應用程序。

> forem.recognize_path "/topics/#{topic.to_param}/posts", :method => :post 
=> {:action=>"create", :controller=>"forem/posts", :topic_id=>"first-topic"} 

> Rails.application.routes.recognize_path "/topics/#{topic.to_param}/posts", :method => :post 
ActionController::RoutingError: No route matches "/topics/first-topic/posts" 

如何編寫我的請求規範以創建對主題的回覆?

回答

0

我想使用字符串ID不被認爲是一種好的做法。嘗試使用整數ID而不是字符串。但是如果你仍然想使用字符串ID,我認爲this鏈接可以幫助你。