Skip to content
Permalink
Browse files

test with render as well

  • Loading branch information...
pushcx committed Oct 23, 2019
1 parent a7fee75 commit 6c804eeea641d11fbbd9992435cbaee2197d9c32
@@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
# (lobster_trap) which is sent even to logged-out visitors
CACHE_PAGE = proc { false && @user.blank? && cookies[TAG_FILTER_COOKIE].blank? }

rescue_from ActionController::UnknownFormat do
rescue_from ActionController::UnknownFormat, ActionView::MissingTemplate do
render plain: '404 Not Found', status: :not_found, content_type: 'text/plain'
end

@@ -1,33 +1,49 @@
require 'rails_helper'

describe ApplicationController do
describe 'rescuing for unkown format errors' do
describe 'rescuing format errors' do
controller do
def index
def with_respond_to
respond_to do |format|
format.html { render plain: 'hello world', status: :ok }
end
end

def with_render
render plain: 'hello world', status: :ok
end
end

# https://github.com/rspec/rspec-rails/issues/636
before do
get :index, format: request_format
routes.draw do
get 'with_respond_to' => 'anonymous#with_respond_to'
get 'with_render' => 'anonymous#with_render'
end
end

context 'requesting with handeled format' do
let(:request_format) { :html }
it 'requesting valid format from respond_to works' do
get :with_respond_to, format: :html
expect(response).to have_http_status(:ok)
get :with_respond_to
expect(response).to have_http_status(:ok)
end

it 'responses with the expected http status code' do
expect(response).to have_http_status(:ok)
end
it 'requesting valid format from render call worksworks' do
get :with_render, format: :html
expect(response).to have_http_status(:ok)
get :with_render
expect(response).to have_http_status(:ok)
end

context 'requesting with unhandeled format' do
let(:request_format) { :flv }
it 'requesting unhandled format from respond_to fails' do
get :with_respond_to, format: :rss
expect(response).to have_http_status(:not_found)
end

it 'responses with a error inicating http status code' do
expect(response).to have_http_status(:not_found)
end
xit 'requesting unhandled format from render fails' do
get :with_render, format: :rss
expect(response).to have_http_status(:not_found)
end
end
end
@@ -5,7 +5,7 @@
it 'displays the username' do
user = create(:user)

get "/u/#{user.username}"
get "/top/1y.rss"

expect(response.body).to include("User #{user.username}")
end

0 comments on commit 6c804ee

Please sign in to comment.
You can’t perform that action at this time.