# encoding: utf-8 require 'test_helper' class BasicControllerTest < ActionDispatch::IntegrationTest test 'json requests' do @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' } # 404 get '/not_existing_url', {}, @headers assert_response(404) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'No route matches [GET] /not_existing_url') # 401 get '/api/v1/organizations', {}, @headers assert_response(401) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'authentication failed') # 422 get '/tests/unprocessable_entity', {}, @headers assert_response(422) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'some error message') # 401 get '/tests/not_authorized', {}, @headers assert_response(401) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'some error message') # 401 get '/tests/ar_not_found', {}, @headers assert_response(404) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'some error message') # 500 get '/tests/standard_error', {}, @headers assert_response(500) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'some error message') # 422 get '/tests/argument_error', {}, @headers assert_response(422) result = JSON.parse(@response.body) assert_equal(result.class, Hash) assert(result['error'], 'some error message') end test 'html requests' do # 404 get '/not_existing_url', {}, @headers assert_response(404) assert_match(/404: Not Found}, @response.body) assert_match(%r{