<commit_before>require "rails_helper"

module Renalware
  module Transplants
    describe DonorStage do
      it { is_expected.to belong_to(:patient).touch(true) }
      it { is_expected.to validate_presence_of(:patient) }
      it { is_expected.to belong_to(:stage_position) }
      it { is_expected.to belong_to(:stage_status) }
      it { is_expected.to validate_presence_of(:stage_position) }
      it { is_expected.to respond_to(:created_by) }
      it { is_expected.to respond_to(:updated_by) }
      it { is_expected.to respond_to(:started_on) }
      it { is_expected.to respond_to(:terminated_on) }
      it { is_expected.to validate_presence_of(:stage_status) }
      it { is_expected.to validate_presence_of(:started_on) }
      it { is_expected.not_to validate_presence_of(:terminated_on) }

      describe "class methods" do
        subject { DonorStage }

        it { is_expected.to respond_to(:for_patient) }
      end

      describe "scopes" do
        describe "#current" do
          it "returns the one and only current status ie the only one (for this patient) "\
             "without a termination date" do
            patient = Transplants.cast_patient(create(:patient))
            terminated_status = create(:donor_stage,
                                       patient: patient,
                                       started_on: 1.week.ago,
                                       terminated_on: 1.day.ago)
            current_status = create(:donor_stage,
                                    patient: patient,
                                    started_on: terminated_status.terminated_on,
                                    terminated_on: nil)

            current = DonorStage.for_patient(patient).current
            expect(current.length).to eq(1)
            expect(current.first.id).to eq(current_status.id)
          end
        end
      end
    end
  end
end<commit_msg>Fix intermittently failing spec<commit_after>require "rails_helper"

module Renalware
  module Transplants
    describe DonorStage do
      it { is_expected.to belong_to(:patient).touch(true) }
      it { is_expected.to validate_presence_of(:patient) }
      it { is_expected.to belong_to(:stage_position) }
      it { is_expected.to belong_to(:stage_status) }
      it { is_expected.to validate_presence_of(:stage_position) }
      it { is_expected.to respond_to(:created_by) }
      it { is_expected.to respond_to(:updated_by) }
      it { is_expected.to respond_to(:started_on) }
      it { is_expected.to respond_to(:terminated_on) }
      it { is_expected.to validate_presence_of(:stage_status) }
      it { is_expected.to validate_presence_of(:started_on) }
      it { is_expected.not_to validate_presence_of(:terminated_on) }

      describe "class methods" do
        subject { DonorStage }

        it { is_expected.to respond_to(:for_patient) }
      end

      describe "scopes" do
        describe "#current" do
          it "returns the one and only current status ie the only one (for this patient) "\
             "without a termination date" do
            patient = Transplants.cast_patient(create(:patient, family_name: "Ng"))
            terminated_status = create(:donor_stage,
                                       patient: patient,
                                       started_on: 1.week.ago,
                                       terminated_on: 1.day.ago)
            current_status = create(:donor_stage,
                                    patient: patient,
                                    started_on: terminated_status.terminated_on,
                                    terminated_on: nil)

            current = DonorStage.for_patient(patient).current
            expect(current.length).to eq(1)
            expect(current.first.id).to eq(current_status.id)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08041504539559015, 'fraction_numerical': 0.0015564202334630351, 'mean_word_length': 1.9661538461538461, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819048', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1056, 'n_words': 226}