<commit_before>require "active_record_spec_helper"

describe Timeline do
  let(:course) { create :course }
  subject { described_class.new(course) }

  describe "#initialize" do
    it "is initialized with a course" do
      expect(subject.course).to eq course
    end
  end

  describe "#events" do
    it "includes assignments that have due dates or open dates" do
      assignment = create(:assignment, course: course, due_at: Date.today)
      assignment_no_date = create(:assignment, course: course, due_at: nil)
      expect(subject.events).to eq [assignment]
    end

    it "includes events that have due dates or open dates" do
      event = create(:event, course: course, due_at: Date.today)
      event_no_date = create(:event, course: course, due_at: nil)
      expect(subject.events).to eq [event]
    end

    it "includes challenge that have due dates or open dates if the course allows it" do
      course.update_attributes team_challenges: true
      challenge = create(:challenge, course: course, due_at: Date.today)
      challenge_no_date = create(:challenge, course: course, due_at: nil)
      expect(subject.events).to eq [challenge]
    end

    it "does not include challenge that have due dates or open dates if the course does not allows it" do
      challenge = create(:challenge, course: course, due_at: Date.today)
      challenge_no_date = create(:challenge, course: course, due_at: nil)
      expect(subject.events).to eq []
    end
  end
end<commit_msg>Refactored the spec to utilize context for better code organization<commit_after>require "active_record_spec_helper"

describe Timeline do
  let(:course) { create :course }
  subject { described_class.new(course) }

  describe "#initialize" do
    it "is initialized with a course" do
      expect(subject.course).to eq course
    end
  end

  describe "#events" do
    context "with assignments for the course" do
      let!(:assignment) { create :assignment, course: course, due_at: Date.today }
      let!(:assignment_not_due) { create :assignment, course: course, due_at: nil }

      it "includes the assignments" do
        expect(subject.events).to eq [assignment]
      end
    end

    context "with events for the course" do
      let!(:event) { create :event, course: course, due_at: Date.today }
      let!(:event_not_due) { create :event, course: course, due_at: nil }

      it "includes the events" do
        expect(subject.events).to eq [event]
      end
    end

    context "with challenges for the course" do
      let!(:challenge) { create :challenge, course: course, due_at: Date.today }
      let!(:challenge_not_due) { create :challenge, course: course, due_at: nil }

      context "that accepts team challenges" do
        before { course.update_attributes team_challenges: true }

        it "includes the challenges" do
          expect(subject.events).to eq [challenge]
        end
      end

      context "that does not accept team challenges" do
        it "does not include the challenges" do
          expect(subject.events).to eq []
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08829236739974126, 'fraction_numerical': 0.0, 'mean_word_length': 3.1797297297297296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3802196', 'n_tokens_mistral': 910, 'n_tokens_neox': 864, 'n_words': 315}