BigW Consortium Gitlab

Commit 84366282 by Robert Speicher

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

parent c13b5acb
......@@ -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
......@@ -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
......@@ -23,7 +23,7 @@
- @broadcast_messages.each do |message|
%tr
%td
= message.status
= broadcast_message_status(message)
%td
= broadcast_message(message)
%td
......
......@@ -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
......@@ -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
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