2013-11-12 06:47:28 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe BroadcastMessage do
|
2016-11-18 17:22:02 -05:00
|
|
|
subject { build(:broadcast_message) }
|
2013-11-12 06:47:28 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_valid }
|
2013-11-12 08:08:20 -05:00
|
|
|
|
2015-12-01 18:53:44 -05:00
|
|
|
describe 'validations' do
|
|
|
|
let(:triplet) { '#000' }
|
|
|
|
let(:hex) { '#AABBCC' }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value(nil).for(:color) }
|
|
|
|
it { is_expected.to allow_value(triplet).for(:color) }
|
|
|
|
it { is_expected.to allow_value(hex).for(:color) }
|
|
|
|
it { is_expected.not_to allow_value('000').for(:color) }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value(nil).for(:font) }
|
|
|
|
it { is_expected.to allow_value(triplet).for(:font) }
|
|
|
|
it { is_expected.to allow_value(hex).for(:font) }
|
|
|
|
it { is_expected.not_to allow_value('000').for(:font) }
|
|
|
|
end
|
|
|
|
|
2015-12-31 17:07:11 -05:00
|
|
|
describe '.current' do
|
2017-06-15 09:47:33 -04:00
|
|
|
it 'returns message if time match' do
|
2015-12-31 17:07:11 -05:00
|
|
|
message = create(:broadcast_message)
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.current).to include(message)
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
|
2017-06-15 09:47:33 -04:00
|
|
|
it 'returns multiple messages if time match' do
|
|
|
|
message1 = create(:broadcast_message)
|
|
|
|
message2 = create(:broadcast_message)
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.current).to contain_exactly(message1, message2)
|
2017-06-15 09:47:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty list if time not come' do
|
2015-12-31 17:07:11 -05:00
|
|
|
create(:broadcast_message, :future)
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.current).to be_empty
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
|
2017-06-15 09:47:33 -04:00
|
|
|
it 'returns empty list if time has passed' do
|
2015-12-31 17:07:11 -05:00
|
|
|
create(:broadcast_message, :expired)
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.current).to be_empty
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
end
|
2015-12-31 17:07:11 -05:00
|
|
|
|
|
|
|
describe '#active?' do
|
|
|
|
it 'is truthy when started and not ended' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
expect(message).to be_active
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is falsey when ended' do
|
|
|
|
message = build(:broadcast_message, :expired)
|
|
|
|
|
|
|
|
expect(message).not_to be_active
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is falsey when not started' do
|
|
|
|
message = build(:broadcast_message, :future)
|
|
|
|
|
|
|
|
expect(message).not_to be_active
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#started?' do
|
|
|
|
it 'is truthy when starts_at has passed' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
travel_to(3.days.from_now) do
|
|
|
|
expect(message).to be_started
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is falsey when starts_at is in the future' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
travel_to(3.days.ago) do
|
|
|
|
expect(message).not_to be_started
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#ended?' do
|
|
|
|
it 'is truthy when ends_at has passed' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
travel_to(3.days.from_now) do
|
|
|
|
expect(message).to be_ended
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is falsey when ends_at is in the future' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
travel_to(3.days.ago) do
|
|
|
|
expect(message).not_to be_ended
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-12 06:47:28 -05:00
|
|
|
end
|