Commit 84366282 authored by Robert Speicher's avatar Robert Speicher

Move `BroadcastMessage#status` to a helper since it's presentational

parent c13b5acb
...@@ -21,4 +21,14 @@ module BroadcastMessagesHelper ...@@ -21,4 +21,14 @@ module BroadcastMessagesHelper
style style
end end
def broadcast_message_status(broadcast_message)
if broadcast_message.active?
'Active'
elsif broadcast_message.ended?
'Expired'
else
'Pending'
end
end
end end
...@@ -40,14 +40,4 @@ class BroadcastMessage < ActiveRecord::Base ...@@ -40,14 +40,4 @@ class BroadcastMessage < ActiveRecord::Base
def ended? def ended?
ends_at < Time.zone.now ends_at < Time.zone.now
end end
def status
if active?
'Active'
elsif ended?
'Expired'
else
'Pending'
end
end
end end
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
- @broadcast_messages.each do |message| - @broadcast_messages.each do |message|
%tr %tr
%td %td
= message.status = broadcast_message_status(message)
%td %td
= broadcast_message(message) = broadcast_message(message)
%td %td
......
...@@ -37,4 +37,24 @@ describe BroadcastMessagesHelper do ...@@ -37,4 +37,24 @@ describe BroadcastMessagesHelper do
to match('background-color: #f2dede; color: #b94a48') to match('background-color: #f2dede; color: #b94a48')
end end
end end
describe 'broadcast_message_status' do
it 'returns Active' do
message = build(:broadcast_message)
expect(helper.broadcast_message_status(message)).to eq 'Active'
end
it 'returns Expired' do
message = build(:broadcast_message, :expired)
expect(helper.broadcast_message_status(message)).to eq 'Expired'
end
it 'returns Pending' do
message = build(:broadcast_message, :future)
expect(helper.broadcast_message_status(message)).to eq 'Pending'
end
end
end end
...@@ -111,24 +111,4 @@ describe BroadcastMessage, models: true do ...@@ -111,24 +111,4 @@ describe BroadcastMessage, models: true do
end end
end end
end end
describe '#status' do
it 'returns Active' do
message = build(:broadcast_message)
expect(message.status).to eq 'Active'
end
it 'returns Expired' do
message = build(:broadcast_message, :expired)
expect(message.status).to eq 'Expired'
end
it 'returns Pending' do
message = build(:broadcast_message, :future)
expect(message.status).to eq 'Pending'
end
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