summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-07-14 06:37:00 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-07-14 15:01:19 +0100
commit3e48796de12848df4401245383c99e3a026ba09c (patch)
tree09d84bed9712b5f1501e38bcc8c5a39f5eb85303
parentaf4acd0443985b68f62596aab5d42376d3312994 (diff)
downloadgitlab-ce-3e48796de12848df4401245383c99e3a026ba09c.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.haml2
-rw-r--r--lib/api/internal.rb2
-rw-r--r--spec/requests/api/internal_spec.rb11
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 cde4fa888a0..159bf77a0c0 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