debian-mirror-gitlab/spec/models/broadcast_message_spec.rb

55 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
# == 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'
2015-12-23 02:04:40 +05:30
describe BroadcastMessage, models: true do
2014-09-02 18:07:02 +05:30
subject { create(:broadcast_message) }
2015-04-26 12:48:37 +05:30
it { is_expected.to be_valid }
2014-09-02 18:07:02 +05:30
2015-12-23 02:04:40 +05:30
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
2014-09-02 18:07:02 +05:30
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)
2015-04-26 12:48:37 +05:30
expect(BroadcastMessage.current).to eq(broadcast_message)
2014-09-02 18:07:02 +05:30
end
it "should return nil if time not come" do
2015-10-24 18:46:33 +05:30
create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
2015-04-26 12:48:37 +05:30
expect(BroadcastMessage.current).to be_nil
2014-09-02 18:07:02 +05:30
end
it "should return nil if time has passed" do
2015-10-24 18:46:33 +05:30
create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
2015-04-26 12:48:37 +05:30
expect(BroadcastMessage.current).to be_nil
2014-09-02 18:07:02 +05:30
end
end
end