2020-04-19 14:38:01 -07:00
|
|
|
# frozen_string_literal: true
|
2020-04-19 12:12:22 -07:00
|
|
|
|
2020-04-19 14:38:01 -07:00
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
RSpec.describe(Announcement, type: :model) do
|
|
|
|
let!(:user) { FactoryBot.create :user }
|
|
|
|
let!(:me) do
|
|
|
|
Announcement.new(
|
|
|
|
content: "Raccoon",
|
|
|
|
starts_at: Time.current,
|
|
|
|
ends_at: Time.current + 1.day,
|
|
|
|
user: user
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#active?" do
|
|
|
|
it "returns true when the current time is between starts_at and ends_at" do
|
|
|
|
expect(me.active?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when the current time is before starts_at" do
|
|
|
|
Timecop.freeze(me.starts_at - 1.second)
|
|
|
|
expect(me.active?).to be(false)
|
|
|
|
Timecop.return
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when the current time is after ends_at" do
|
|
|
|
Timecop.freeze(me.ends_at)
|
|
|
|
expect(me.active?).to be(false)
|
|
|
|
Timecop.return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#link_present?" do
|
|
|
|
it "returns true if a link is present" do
|
|
|
|
me.link_text = "Very good dogs"
|
|
|
|
me.link_href = "https://www.reddit.com/r/rarepuppers/"
|
|
|
|
expect(me.link_present?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if a link is not present" do
|
|
|
|
me.link_text = nil
|
|
|
|
me.link_href = nil
|
|
|
|
expect(me.link_present?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|