在rails引擎rspec请求规范中找不到路由

时间:2013-08-19 15:36:51

标签: ruby-on-rails ruby ruby-on-rails-3 rspec

我正在使用forem rails引擎,我无法编写rspec 请求规范,因为我尝试使用的路由无法找到(根据rspec)。我想使用请求规范发出POST请求来创建对主题的回复。

请求规范中的以下内容不起作用:

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"

如何编写我的请求规范以创建对主题的回复?

1 个答案:

答案 0 :(得分:0)

我猜使用字符串ID不被认为是一种好习惯。尝试使用整数ID而不是字符串。但是,如果您仍想使用字符串ID,我认为this链接可以帮助您。