没有路线与RSPEC匹配

时间:2014-08-09 00:46:52

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

我在其中一个控制器中创建了一个新的put请求,代码如下:

#PUT /items/:item_id/offers/:id/accept
def accept
  @current_item = @current_user.items.find_by_id(params[:item_id])
  @offer = @current_item.offers.find_by_id(params[:id])

  @offer.update_attributes(:final_decision => 'Y')
  # @current_item.update_attribute(:traded,true)
  @offer.item.update_attribute(:traded,true)

  # Cancel other offers made for that item
  @current_item.offers.each do |rejected_offer|
    rejected_offer.destroy unless rejected_offer == @offer
  end

  # Cancel offers of that item to other items
  @current_item.offers_as_offered.each do |rejected_offer|
    rejected_offer.destroy unless rejected_offer == @offer
  end

end

尝试使用以下方法对此进行测试:

it 'should accept' do

  put :accept, item_id: item.id, id: offer.id, access_token: user2.token

  expect(response.status).to eq(201)
end

我总是得到:

Failure/Error: put :accept, item_id: item.id, id: offer.id, access_token: user2.token
ActionController::UrlGenerationError:
  No route matches {:item_id=>"80794", :id=>"62087", :access_token=>"8b3deb96e92dbbee7b3aa25e488b5f40bc33c8ee078177370268520ef66f179a", :controller=>"items", :action=>"accept"}

测试在spec/controllers/offers_controller_spec.rb。我也尝试过使用

"/items/#{item.id}/offers/#{offer.id}/accept"

而不是:accept没有成功。

我的路线是:

resources :items do
  resources :offers, only: [:index, :create, :destroy, :update] do
    put :accept, on: :member
  end
end

任何提示都将不胜感激。

修改

添加了rake路线输出。

accept_item_offer PUT    /items/:item_id/offers/:id/accept(.:format)  offers#accept

0 个答案:

没有答案