Add Announcement tests
This commit is contained in:
parent
4889071f95
commit
864d5844dc
1
Gemfile
1
Gemfile
|
@ -104,4 +104,5 @@ group :development, :test do
|
||||||
gem 'letter_opener' # Use this just in local test environments
|
gem 'letter_opener' # Use this just in local test environments
|
||||||
gem 'brakeman'
|
gem 'brakeman'
|
||||||
gem 'guard-brakeman'
|
gem 'guard-brakeman'
|
||||||
|
gem 'timecop'
|
||||||
end
|
end
|
||||||
|
|
|
@ -456,6 +456,7 @@ GEM
|
||||||
thor (1.0.1)
|
thor (1.0.1)
|
||||||
thread_safe (0.3.6)
|
thread_safe (0.3.6)
|
||||||
tilt (2.0.10)
|
tilt (2.0.10)
|
||||||
|
timecop (0.9.1)
|
||||||
tiny-color-rails (0.0.2)
|
tiny-color-rails (0.0.2)
|
||||||
railties (>= 3.0)
|
railties (>= 3.0)
|
||||||
turbolinks (2.5.4)
|
turbolinks (2.5.4)
|
||||||
|
@ -566,6 +567,7 @@ DEPENDENCIES
|
||||||
simplecov-rcov
|
simplecov-rcov
|
||||||
spring (~> 2.0)
|
spring (~> 2.0)
|
||||||
sweetalert-rails
|
sweetalert-rails
|
||||||
|
timecop
|
||||||
tiny-color-rails
|
tiny-color-rails
|
||||||
tumblr_client!
|
tumblr_client!
|
||||||
turbolinks (~> 2.5.3)
|
turbolinks (~> 2.5.3)
|
||||||
|
|
|
@ -1,5 +1,47 @@
|
||||||
require 'rails_helper'
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe Announcement, type: :model do
|
require "rails_helper"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
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
|
Loading…
Reference in New Issue