0

コントローラー側では JSON のみをサポートしているため、リクエストに渡された間違ったコンテンツ タイプをテストする RSpec テストを作成しようとしています。

したがって、現在、RSpec は次のように記述されています。

it 'returns a 406 if the request is not for json' do
  request.accept = 'text/html'
  get :show
  expect(response.code).to eq('406')
end

私のコントローラーの show メソッドは次のようになります。

 respond_to :json

 def show

    org_id = Organization.find_by_id(params[:id])

    @organization = Organization.includes([:BunchOfTablesBlah).find(params[:id])

    respond_with(@organization)
end

しかし、そのテストは次のエラーで失敗します:

1) PopulationManagementController は、リクエストが json に対するものではない場合、組織が 406 を返すことを示します。 /spec/controllers/population_management_controller_spec.rb:184:in `ブロック (3 レベル) in'

4

1 に答える 1

1
No route matches {:controller=>"population_management", :action=>"show"}

ActionController#show requires an ID, but you haven't supplied one, thus the routing failure.

Try get :show, :id => '1'

于 2013-02-18T17:54:04.470 に答える