Sha256: 6f6bf6e1d58c740275ca4a5fb4d1e8ee7e76c70e03b109bbc87df2372aae0225

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

# encoding: UTF-8
require 'spec_helper'

feature 'Error json response', if: !ENV["CUSTOM_EXCEPTIONS_APP"], type: :request do
  def json_response
    JSON.parse(response.body)
  end

  def get(path)
    without_layouts do
      super(path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")
    end
  end

  def without_layouts
    `mv spec/fake_app/app/views/layouts/application.html.erb .`
    `mv spec/fake_app/app/views/layouts/error.html.erb .`

    yield
  ensure
    `mv application.html.erb spec/fake_app/app/views/layouts/`
    `mv error.html.erb spec/fake_app/app/views/layouts/`
  end

  scenario 'returns 422 json due to ActionController:InvalidAuthenticityToken but without its template' do
    get '/users/new'

    expect(response.status).to eq(422)
    expect(json_response['message']).to eq("Something went wrong")
  end

  scenario 'returns 500 json due to RuntimeError' do
    get '/users/1.json'

    expect(response.status).to eq(500)
    expect(json_response['message']).to eq("Something went wrong")
  end

  scenario 'returns 404 json due to CustomException' do
    get '/users.json'

    expect(response.status).to eq(404)
    expect(json_response['message']).to eq("Page not found")
  end

  scenario 'returns 404 json due to ActinoController::RoutingError' do
    get '/doesnt_exist.json'

    expect(response.status).to eq(404)
    expect(json_response['message']).to eq("Page not found")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rambulance-0.3.1 spec/requests/error_json_spec.rb