demarches-normaliennes/spec/controllers/application_controller/error_handling_spec.rb
Pierre de La Morinerie 37c62ac0a3 app: display standard error page when no cookies are present
This occurs mostly when Safari attempts to perform a POST request
again (without sending any of the cookies).

In that case, our custom `422.html` page is more helpful to the user
(because it has a link to the previous page) than a "No cookies" blank
text.
2021-07-06 16:29:22 +02:00

43 lines
1.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

RSpec.describe ApplicationController::ErrorHandling, type: :controller do
controller(ActionController::Base) do
include ApplicationController::ErrorHandling
def invalid_authenticity_token
raise ActionController::InvalidAuthenticityToken
end
end
before do
routes.draw { post 'invalid_authenticity_token' => 'anonymous#invalid_authenticity_token' }
end
describe 'handling ActionController::InvalidAuthenticityToken' do
let(:request_cookies) do
{ 'some_cookie': true }
end
before { cookies.update(request_cookies) }
it 'logs the error' do
allow(Sentry).to receive(:capture_message)
post :invalid_authenticity_token rescue nil
expect(Sentry).to have_received(:capture_message)
end
it 'forwards the error upwards' do
expect { post :invalid_authenticity_token }.to raise_error(ActionController::InvalidAuthenticityToken)
end
context 'when Safari retries a POST request without cookies' do
let(:request_cookies) do
{}
end
it 'doesnt log the error' do
allow(Sentry).to receive(:capture_message)
post :invalid_authenticity_token rescue nil
expect(Sentry).not_to have_received(:capture_message)
end
end
end
end