Update broadcast_message helper
Now it returns the fully-formatted message so we can be consistent about how it's shown.
This commit is contained in:
parent
8086b2bd2e
commit
5a1706791e
4 changed files with 46 additions and 27 deletions
|
@ -181,10 +181,6 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def broadcast_message
|
|
||||||
BroadcastMessage.current
|
|
||||||
end
|
|
||||||
|
|
||||||
# Render a `time` element with Javascript-based relative date and tooltip
|
# Render a `time` element with Javascript-based relative date and tooltip
|
||||||
#
|
#
|
||||||
# time - Time object
|
# time - Time object
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
module BroadcastMessagesHelper
|
module BroadcastMessagesHelper
|
||||||
def broadcast_styling(broadcast_message)
|
def broadcast_message(message = BroadcastMessage.current)
|
||||||
styling = ''
|
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?
|
if broadcast_message.color.present?
|
||||||
styling << "background-color: #{broadcast_message.color}"
|
style << "background-color: #{broadcast_message.color}"
|
||||||
styling << '; ' if broadcast_message.font.present?
|
style << '; ' if broadcast_message.font.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
if broadcast_message.font.present?
|
if broadcast_message.font.present?
|
||||||
styling << "color: #{broadcast_message.font}"
|
style << "color: #{broadcast_message.font}"
|
||||||
end
|
end
|
||||||
|
|
||||||
styling
|
style
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1 @@
|
||||||
- if broadcast_message.present?
|
= broadcast_message
|
||||||
.broadcast-message{ style: broadcast_styling(broadcast_message) }
|
|
||||||
= icon('bullhorn')
|
|
||||||
= broadcast_message.message
|
|
||||||
|
|
|
@ -1,22 +1,40 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe BroadcastMessagesHelper do
|
describe BroadcastMessagesHelper do
|
||||||
describe 'broadcast_styling' do
|
describe 'broadcast_message' do
|
||||||
let(:broadcast_message) { double(color: '', font: '') }
|
it 'returns nil when no current message' do
|
||||||
|
expect(helper.broadcast_message(nil)).to be_nil
|
||||||
context "default style" do
|
|
||||||
it "should have no style" do
|
|
||||||
expect(broadcast_styling(broadcast_message)).to eq ''
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "customized style" do
|
it 'includes the current message' do
|
||||||
let(:broadcast_message) { double(color: "#f2dede", font: '#b94a48') }
|
current = double(message: 'Current Message')
|
||||||
|
|
||||||
it "should have a customized style" do
|
allow(helper).to receive(:broadcast_message_style).and_return(nil)
|
||||||
expect(broadcast_styling(broadcast_message)).
|
|
||||||
to match('background-color: #f2dede; color: #b94a48')
|
expect(helper.broadcast_message(current)).to include 'Current Message'
|
||||||
end
|
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
|
||||||
|
|
||||||
|
describe 'broadcast_message_style' do
|
||||||
|
it 'defaults to no style' do
|
||||||
|
broadcast_message = spy
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue