Add Announcement tests

This commit is contained in:
Karina Kwiatek 2020-04-19 22:38:01 +01:00
parent 4889071f95
commit 864d5844dc
3 changed files with 49 additions and 4 deletions

View File

@ -104,4 +104,5 @@ group :development, :test do
gem 'letter_opener' # Use this just in local test environments
gem 'brakeman'
gem 'guard-brakeman'
gem 'timecop'
end

View File

@ -456,6 +456,7 @@ GEM
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.10)
timecop (0.9.1)
tiny-color-rails (0.0.2)
railties (>= 3.0)
turbolinks (2.5.4)
@ -566,6 +567,7 @@ DEPENDENCIES
simplecov-rcov
spring (~> 2.0)
sweetalert-rails
timecop
tiny-color-rails
tumblr_client!
turbolinks (~> 2.5.3)

View File

@ -1,5 +1,47 @@
require 'rails_helper'
# frozen_string_literal: true
RSpec.describe Announcement, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
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