diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-14 06:37:00 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-14 06:37:00 +0000 |
commit | 6f81fc44a909f7ae95d322e729eb95e9e066e85a (patch) | |
tree | c3584e0f9573cb2d0413d7db21f8b29eb3a2d3af | |
parent | dbcc0e03ac82d6b90fc93b1fefac8ce80c741178 (diff) | |
parent | e6cd2353a4123af3183188b200233a32ea7adbdd (diff) | |
download | gitlab-ce-6f81fc44a909f7ae95d322e729eb95e9e066e85a.tar.gz |
Merge branch 'sh-fix-nil-broadcast-message' into 'master'
Handle case when BroadcastMessage.current is nil
Closes #35094
See merge request !12860
-rw-r--r-- | app/views/layouts/_broadcast.html.haml | 2 | ||||
-rw-r--r-- | lib/api/internal.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/internal_spec.rb | 11 |
3 files changed, 13 insertions, 2 deletions
diff --git a/app/views/layouts/_broadcast.html.haml b/app/views/layouts/_broadcast.html.haml index bcd2f03e83c..e2dbdcbb939 100644 --- a/app/views/layouts/_broadcast.html.haml +++ b/app/views/layouts/_broadcast.html.haml @@ -1,2 +1,2 @@ -- BroadcastMessage.current.each do |message| +- BroadcastMessage.current&.each do |message| = broadcast_message(message) diff --git a/lib/api/internal.rb b/lib/api/internal.rb index ef2c08e902c..465363da582 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -101,7 +101,7 @@ module API end get "/broadcast_message" do - if message = BroadcastMessage.current.last + if message = BroadcastMessage.current&.last present message, with: Entities::BroadcastMessage else {} diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 453eb4683a0..beaaf346283 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -35,6 +35,17 @@ describe API::Internal do expect(json_response).to be_empty end end + + context 'nil broadcast message' do + it 'returns nothing' do + allow(BroadcastMessage).to receive(:current).and_return(nil) + + get api('/internal/broadcast_message'), secret_token: secret_token + + expect(response).to have_http_status(200) + expect(json_response).to be_empty + end + end end describe 'GET /internal/broadcast_messages' do |