summaryrefslogtreecommitdiff
path: root/spec/models/broadcast_message_spec.rb
blob: 2b325f44f64abff8cbef7ba91bc1270855a6298b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# == Schema Information
#
# Table name: broadcast_messages
#
#  id         :integer          not null, primary key
#  message    :text             not null
#  starts_at  :datetime
#  ends_at    :datetime
#  alert_type :integer
#  created_at :datetime
#  updated_at :datetime
#  color      :string(255)
#  font       :string(255)
#

require 'spec_helper'

describe BroadcastMessage do
  subject { create(:broadcast_message) }

  it { is_expected.to be_valid }

  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

  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)
    end

    it "should return nil if time not come" do
      create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
      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)
      expect(BroadcastMessage.current).to be_nil
    end
  end
end