2013-11-13 07:10:03 -05:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: broadcast_messages
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2014-04-09 08:05:03 -04:00
|
|
|
# message :text not null
|
2013-11-13 07:10:03 -05:00
|
|
|
# starts_at :datetime
|
|
|
|
# ends_at :datetime
|
|
|
|
# alert_type :integer
|
2014-04-09 08:05:03 -04:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2013-12-09 00:34:51 -05:00
|
|
|
# color :string(255)
|
|
|
|
# font :string(255)
|
2013-11-13 07:10:03 -05:00
|
|
|
#
|
|
|
|
|
2013-11-12 06:47:28 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BroadcastMessage do
|
|
|
|
subject { create(:broadcast_message) }
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_valid }
|
2013-11-12 08:08:20 -05:00
|
|
|
|
|
|
|
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-02-12 13:17:35 -05:00
|
|
|
expect(BroadcastMessage.current).to eq(broadcast_message)
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if time not come" do
|
2015-10-03 02:48:54 -04:00
|
|
|
create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(BroadcastMessage.current).to be_nil
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if time has passed" do
|
2015-10-03 02:48:54 -04:00
|
|
|
create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(BroadcastMessage.current).to be_nil
|
2013-11-12 08:08:20 -05:00
|
|
|
end
|
|
|
|
end
|
2013-11-12 06:47:28 -05:00
|
|
|
end
|