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

15 16
require 'spec_helper'

Douwe Maan's avatar
Douwe Maan committed
17
describe BroadcastMessage, models: true do
18 19
  subject { create(:broadcast_message) }

20
  it { is_expected.to be_valid }
21

Robert Speicher's avatar
Robert Speicher committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  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

37 38 39
  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)
40
      expect(BroadcastMessage.current).to eq(broadcast_message)
41 42 43
    end

    it "should return nil if time not come" do
44
      create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
45
      expect(BroadcastMessage.current).to be_nil
46 47 48
    end

    it "should return nil if time has passed" do
49
      create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
50
      expect(BroadcastMessage.current).to be_nil
51 52
    end
  end
53
end