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

This commit is contained in:
Robert Speicher 2016-01-13 11:46:32 -05:00
parent c13b5acb16
commit 843662821d
5 changed files with 31 additions and 31 deletions

View File

@ -21,4 +21,14 @@ module BroadcastMessagesHelper
style
end
def broadcast_message_status(broadcast_message)
if broadcast_message.active?
'Active'
elsif broadcast_message.ended?
'Expired'
else
'Pending'
end
end
end

View File

@ -40,14 +40,4 @@ class BroadcastMessage < ActiveRecord::Base
def ended?
ends_at < Time.zone.now
end
def status
if active?
'Active'
elsif ended?
'Expired'
else
'Pending'
end
end
end

View File

@ -23,7 +23,7 @@
- @broadcast_messages.each do |message|
%tr
%td
= message.status
= broadcast_message_status(message)
%td
= broadcast_message(message)
%td

View File

@ -37,4 +37,24 @@ describe BroadcastMessagesHelper do
to match('background-color: #f2dede; color: #b94a48')
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

View File

@ -111,24 +111,4 @@ describe BroadcastMessage, models: true do
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