【问题标题】:RSpec API service passing arrayRSpec API 服务传递数组
【发布时间】:2012-10-23 14:18:56
【问题描述】:

我做了几个测试来检查我的 API 服务。在一项测试中,我将两个参数传递给 api/v1/pages/1 并且工作正常;这是代码

put "api/v1/pages/#{@page.id}", { "title" => "new title", "description" => "new description"} last_response.status.should eql(200)

现在我在将对象数组传递给服务时遇到问题。我尝试了一些东西,但没有成功。

 @index = build(:index) //factory girl
 @contact = build(:contact)
 put "api/v1/pages/1/menu" ,[ //need to pass @index and @contact, and/or @index.name, @contact.name]

【问题讨论】:

  • 你能把rake routes的相关部分粘贴过来吗?
  • PUT /api/v1/pages/:portfolio_id/menu(.:format) api/v1/pages#edit_menu_items {:format=>"json"}

标签: ruby-on-rails json rspec


【解决方案1】:

试试

@index = build(:index) //factory girl
@contact = build(:contact)
put "api/v1/pages/1/menu", :index => @index, :contact => @contact

Rails 应该在两侧编组您的对象。

【讨论】:

  • 看起来它仍然没有正确传递,它给我抛出未定义的方法 `each' for nil:NilClass
  • 请粘贴 rspec 的输出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-05
  • 2011-02-02
  • 2017-05-06
  • 2014-12-17
相关资源
最近更新 更多