|
26 | 26 |
|
27 | 27 | RSpec.describe Session, type: :model do
|
28 | 28 | let(:session) { build_stubbed(:session) }
|
| 29 | + let(:live_session) { create(:session, :live) } |
| 30 | + let(:starting_soon_session) { create(:session, :starting_soon) } |
| 31 | + let(:past_session) { create(:session, :past) } |
| 32 | + |
| 33 | + before do |
| 34 | + Timecop.freeze(Time.current.change(hour: 12)) |
| 35 | + end |
29 | 36 |
|
30 | 37 | it "has a valid factory" do
|
31 | 38 | expect(session).to be_valid
|
|
39 | 46 | expect(session).not_to be_valid
|
40 | 47 | end
|
41 | 48 | end
|
| 49 | + |
| 50 | + describe "#live?" do |
| 51 | + it { expect(live_session).to be_live } |
| 52 | + |
| 53 | + context "when session has not started" do |
| 54 | + it "returns false" do |
| 55 | + allow(live_session).to receive_messages(starts_at: 1.hour.from_now, ends_at: 2.hours.from_now) |
| 56 | + expect(live_session).not_to be_live |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + context "when session has already ended" do |
| 61 | + it "returns false" do |
| 62 | + allow(live_session).to receive_messages(starts_at: 2.hours.ago, ends_at: 1.hour.ago) |
| 63 | + expect(live_session).not_to be_live |
| 64 | + end |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + describe "#starting_soon?" do |
| 69 | + it { expect(starting_soon_session).to be_starting_soon } |
| 70 | + |
| 71 | + context "when session has already started" do |
| 72 | + it "returns false" do |
| 73 | + allow(starting_soon_session).to receive(:starts_at).and_return(2.hours.ago) |
| 74 | + expect(starting_soon_session).not_to be_starting_soon |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + context "when session starts in more than an hour" do |
| 79 | + it "returns false" do |
| 80 | + allow(starting_soon_session).to receive(:starts_at).and_return(2.hours.from_now) |
| 81 | + expect(starting_soon_session).not_to be_starting_soon |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + describe "#past?" do |
| 87 | + it { expect(past_session).to be_past } |
| 88 | + |
| 89 | + context "when session hasn't ended" do |
| 90 | + it "returns false" do |
| 91 | + allow(past_session).to receive(:ends_at).and_return(2.hours.from_now) |
| 92 | + expect(past_session).not_to be_past |
| 93 | + end |
| 94 | + end |
| 95 | + end |
42 | 96 | end
|
0 commit comments