broadcast_message_spec.rb 812 Bytes
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe BroadcastMessage do
  subject { create(:broadcast_message) }

  it { should be_valid }
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

  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)
      BroadcastMessage.current.should == broadcast_message
    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)
      BroadcastMessage.current.should be_nil
    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)
      BroadcastMessage.current.should be_nil
    end
  end
24
end