I was trying to perform a get in my TestCase like this:
request.env['CONTENT_TYPE'] = 'application/json'
get :index,:application_name=>"Heka"
Though, it fails with a:
ActionView::MissingTemplate: Missing template alarm_events/index with {:handlers=>[:builder, :haml, :erb, :rjs, :rhtml, :rxml], :locale=>[:en, :en], :formats=>[:html]
Despite that in my controller I have:
respond_to :html, :json
def index
@alarm_events=[...]
respond_with @alarm_events do |format|
format.json{
render :json=>@alarm_events.map{|e| e.to_portal_representation}.to_json,
:content_type=>'application/json'
}
end
end
How the hell should I code the intended request on the TestCase?
When I request alarm_events.json in the browser it works fine.
Thanks
I had to specify the format in the params for action controller testing:
get :index, {format: :json}
@request.accept = 'application/json'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With