コントローラー側では 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'