0

我正在编写一个 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"}
4

0 回答 0