I am running into an interesting challenge this weekend. I want to test the following 4 rescue statements. What do you feel is the best approach? I have been testing anonymous controllers, gets, and more but I am coming up blank. Is this even possible?
Rspec
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ApplicationController, type: :controller do
it 'rescue record not found with 404' do
end
it 'rescue parameter missing with 400' do
end
it 'rescue routing error with 400' do
end
it 'rescue invalid authenticity token with 400' do
end
end
Application Controller
# frozen_string_literal: true
class ApplicationController < ActionController::Base
force_ssl if: :ssl_configured?
rescue_from ActiveRecord::RecordNotFound, with: :render_404
rescue_from ActionController::ParameterMissing, with: :render_400
rescue_from ActionController::RoutingError, with: :render_404
rescue_from ActionController::InvalidAuthenticityToken, with: :render_400
include StatusCodes
include JsonTester
private
def ssl_configured?
AppUnsecure.settings[:ssl_configured]
end
end