BigW Consortium Gitlab

broadcast_message_spec.rb 1.14 KB
Newer Older
Dmitriy Zaporozhets committed
1 2 3 4 5
# == Schema Information
#
# Table name: broadcast_messages
#
#  id         :integer          not null, primary key
Dmitriy Zaporozhets committed
6
#  message    :text             not null
Dmitriy Zaporozhets committed
7 8 9
#  starts_at  :datetime
#  ends_at    :datetime
#  alert_type :integer
Dmitriy Zaporozhets committed
10 11
#  created_at :datetime
#  updated_at :datetime
12 13
#  color      :string(255)
#  font       :string(255)
Dmitriy Zaporozhets committed
14 15
#

16 17 18 19 20
require 'spec_helper'

describe BroadcastMessage do
  subject { create(:broadcast_message) }

21
  it { is_expected.to be_valid }
22 23 24 25

  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)
26
      expect(BroadcastMessage.current).to eq(broadcast_message)
27 28 29 30
    end

    it "should return nil if time not come" do
      broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
31
      expect(BroadcastMessage.current).to be_nil
32 33 34 35
    end

    it "should return nil if time has passed" do
      broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
36
      expect(BroadcastMessage.current).to be_nil
37 38
    end
  end
39
end