diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-06-07 08:11:30 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-06-07 08:11:30 +0000 |
commit | 5ebc461829403a6e0fbf596255bbf6e505c42648 (patch) | |
tree | 51fac2e7b055f934665d7a6626cbc031b87019b0 /spec | |
parent | 10fd34ba0323bc90af3665ad6fcf5011a112d062 (diff) | |
parent | 5d3abdf9a7c0260c708a46e2fd232b0490940f80 (diff) | |
download | gitlab-ce-5ebc461829403a6e0fbf596255bbf6e505c42648.tar.gz |
Merge branch 'sh-log-422-responses' into 'master'2018-06-07-RC-cut
Log response body to production_json.log when a controller responds with a 422 status
See merge request gitlab-org/gitlab-ce!19473
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/application_controller_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 683c57c96f8..773bf25ed44 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require 'spec_helper' describe ApplicationController do @@ -478,6 +479,63 @@ describe ApplicationController do end end + describe '#append_info_to_payload' do + controller(described_class) do + attr_reader :last_payload + + def index + render text: 'authenticated' + end + + def append_info_to_payload(payload) + super + + @last_payload = payload + end + end + + it 'does not log errors with a 200 response' do + get :index + + expect(controller.last_payload.has_key?(:response)).to be_falsey + end + + context '422 errors' do + it 'logs a response with a string' do + response = spy(ActionDispatch::Response, status: 422, body: 'Hello world', content_type: 'application/json') + allow(controller).to receive(:response).and_return(response) + get :index + + expect(controller.last_payload[:response]).to eq('Hello world') + end + + it 'logs a response with an array' do + body = ['I want', 'my hat back'] + response = spy(ActionDispatch::Response, status: 422, body: body, content_type: 'application/json') + allow(controller).to receive(:response).and_return(response) + get :index + + expect(controller.last_payload[:response]).to eq(body) + end + + it 'does not log a string with an empty body' do + response = spy(ActionDispatch::Response, status: 422, body: nil, content_type: 'application/json') + allow(controller).to receive(:response).and_return(response) + get :index + + expect(controller.last_payload.has_key?(:response)).to be_falsey + end + + it 'does not log an HTML body' do + response = spy(ActionDispatch::Response, status: 422, body: 'This is a test', content_type: 'application/html') + allow(controller).to receive(:response).and_return(response) + get :index + + expect(controller.last_payload.has_key?(:response)).to be_falsey + end + end + end + describe '#access_denied' do controller(described_class) do def index |