Commit 5a170679 authored by Robert Speicher's avatar Robert Speicher

Update broadcast_message helper

Now it returns the fully-formatted message so we can be consistent about
how it's shown.
parent 8086b2bd
......@@ -181,10 +181,6 @@ module ApplicationHelper
end
end
def broadcast_message
BroadcastMessage.current
end
# Render a `time` element with Javascript-based relative date and tooltip
#
# time - Time object
......
module BroadcastMessagesHelper
def broadcast_styling(broadcast_message)
styling = ''
def broadcast_message(message = BroadcastMessage.current)
return unless message.present?
content_tag :div, class: 'broadcast-message', style: broadcast_message_style(message) do
icon('bullhorn') << ' ' << message.message
end
end
def broadcast_message_style(broadcast_message)
style = ''
if broadcast_message.color.present?
styling << "background-color: #{broadcast_message.color}"
styling << '; ' if broadcast_message.font.present?
style << "background-color: #{broadcast_message.color}"
style << '; ' if broadcast_message.font.present?
end
if broadcast_message.font.present?
styling << "color: #{broadcast_message.font}"
style << "color: #{broadcast_message.font}"
end
styling
style
end
end
- if broadcast_message.present?
.broadcast-message{ style: broadcast_styling(broadcast_message) }
= icon('bullhorn')
= broadcast_message.message
= broadcast_message
require 'spec_helper'
describe BroadcastMessagesHelper do
describe 'broadcast_styling' do
let(:broadcast_message) { double(color: '', font: '') }
describe 'broadcast_message' do
it 'returns nil when no current message' do
expect(helper.broadcast_message(nil)).to be_nil
end
it 'includes the current message' do
current = double(message: 'Current Message')
allow(helper).to receive(:broadcast_message_style).and_return(nil)
context "default style" do
it "should have no style" do
expect(broadcast_styling(broadcast_message)).to eq ''
expect(helper.broadcast_message(current)).to include 'Current Message'
end
it 'includes custom style' do
current = double(message: 'Current Message')
allow(helper).to receive(:broadcast_message_style).and_return('foo')
expect(helper.broadcast_message(current)).to include 'style="foo"'
end
end
context "customized style" do
let(:broadcast_message) { double(color: "#f2dede", font: '#b94a48') }
describe 'broadcast_message_style' do
it 'defaults to no style' do
broadcast_message = spy
it "should have a customized style" do
expect(broadcast_styling(broadcast_message)).
to match('background-color: #f2dede; color: #b94a48')
expect(helper.broadcast_message_style(broadcast_message)).to eq ''
end
it 'allows custom style' do
broadcast_message = double(color: '#f2dede', font: '#b94a48')
expect(helper.broadcast_message_style(broadcast_message)).
to match('background-color: #f2dede; color: #b94a48')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment