Rspec 2.10.1,Rails 3.2.13 - ActionController :: RoutingError:没有路由匹配

时间:2013-07-12 20:58:32

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

我正在编写一个rspec测试,通过POST将JSON发送到成员路由端点。但是当我这样做时,我得到了“无路由匹配”错误。我不确定是否需要添加一些内容,因为此端点是成员路由,或者我只是缺少一些HTTP请求头,因为我发送的是JSON。请帮忙。

这就是我所拥有的:

规格:

describe "#endpoint" do
 context "type 1" do

  before(:each) do
    post :create, @params.merge(:abc => {:first_user_id => @user1.id, :second_user_id => @user2.id})
    @mashup = assigns(:mashup)
  end

  it "should post the results successfully" do

    units = [...]
    users = [...]
    params = @params.merge(:mashup_outcome => {:status => "success", :assetName => "MashupAssetName", :winningUserId => @user1.id}, :mashup_id => @mashup.id, :version_number => 1, :user_id => @user1.id, :id => @mashup.id ,:users => :users).to_json

     @request.env["CONTENT_TYPE"] = "application/json"

     #had to have a param key for my params below in order to bypass the NoMethodError
     #In actual request body, it's just a JSON
     post :over, :mashup => params


    @mashups.in_progress.should be_false
  end
end

context "type 2" do

  before(:each) do
     ...
  end

  it "should post the results correctly" do 
      ...
  end

end

路线:

namespace :mashup do
  resources :mashups do
    member do
      post :endpoint
    end
end

控制器:

def endpoint
    if @mashup.complete_mashup(params)
      render :json => api_success(@mashup.dpoints)
    else
      render :json => api_error({})
    end
  end

错误:

Failure/Error: post :endpoint, :mashup => params
 ActionController::RoutingError:
   No route matches {:mashup => "{...<JSON>...}", :controller => "api/mashup/mashups", :action => "endpoint"}

0 个答案:

没有答案