diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-12-31 17:07:11 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-01-13 11:34:58 -0500 |
commit | df496fcaf08b085816a45d31d02f1ea230454b63 (patch) | |
tree | 9d7c23c6c33cc96f4e216db234a8ac63bb8e3581 /spec/models | |
parent | 5a1706791e46fd69a67fcdebfc384a702b00a7ff (diff) | |
download | gitlab-ce-df496fcaf08b085816a45d31d02f1ea230454b63.tar.gz |
Update BroadcastMessage model
- Adds default values for `color` and `font` attributes
- Adds `active?`, `started?`, `ended?`, and 'status' methods
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/broadcast_message_spec.rb | 91 |
1 files changed, 86 insertions, 5 deletions
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 001b2facaab..57550725ae3 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -15,6 +15,8 @@ require 'spec_helper' describe BroadcastMessage, models: true do + include ActiveSupport::Testing::TimeHelpers + subject { create(:broadcast_message) } it { is_expected.to be_valid } @@ -34,20 +36,99 @@ describe BroadcastMessage, models: true do it { is_expected.not_to allow_value('000').for(:font) } end - describe :current do + describe '.current' do it "should return last message if time match" do - broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow) - expect(BroadcastMessage.current).to eq(broadcast_message) + message = create(:broadcast_message) + + expect(BroadcastMessage.current).to eq message end it "should return nil if time not come" do - create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) + create(:broadcast_message, :future) + expect(BroadcastMessage.current).to be_nil end it "should return nil if time has passed" do - create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) + create(:broadcast_message, :expired) + expect(BroadcastMessage.current).to be_nil end end + + 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 + + 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 |