summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 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