<commit_before>require "rails_helper"

module Renalware
  module Medications
    RSpec.describe Prescription, type: :model do
      describe "validations" do
        it { should validate_presence_of :patient }
        it { should validate_presence_of :treatable }
        it { should validate_presence_of(:drug) }
        it { should validate_presence_of(:dose_amount) }
        it { should validate_presence_of(:dose_unit) }
        it { should validate_presence_of(:medication_route) }
        it { should validate_presence_of(:frequency) }
        it { should validate_presence_of(:prescribed_on) }
        it { should validate_presence_of(:provider) }

        describe "#valid?" do
          context "route description" do
            context "given a route" do
              before { subject.medication_route = build(:medication_route) }

              it { is_expected.not_to validate_presence_of(:route_description) }
            end

            context "given a `other` route" do
              before { subject.medication_route = build(:medication_route, :other) }

              it { is_expected.to validate_presence_of(:route_description) }
            end

            context "given a route and a route description" do
              before do
                subject.medication_route = build(:medication_route)
                subject.route_description = "::route description::"
              end

              it "adds an error" do
                subject.valid?

                expect(subject.errors[:route_description]).to be_present
              end
            end
          end
        end
      end

      describe "scopes" do
        describe ".current" do
          it "returns prescriptions that terminate today or later, or not specified" do
            create(:prescription, notes: ":expires_today:", terminated_on: "2010-01-02")
            create(:prescription, notes: ":expired_yesteday:", terminated_on: "2010-01-01")
            create(:prescription, notes: ":not_specified:")
            create(:prescription, notes: ":expires_tomorrow:", terminated_on: "2010-01-03")

            prescriptions = Prescription.current("2010-01-02")

            expect(prescriptions.map(&:notes)).to \
              include(":expires_today:", ":expires_tomorrow:", ":not_specified:")
            expect(prescriptions.map(&:notes)).not_to include(":expires_yesterday:")
          end
        end
      end

      describe "state predicates" do
        let(:date_today) { Date.parse("2010-01-02")}<commit_msg>fix spec for prescription scopes<commit_after>require "rails_helper"

module Renalware
  module Medications
    RSpec.describe Prescription, type: :model do
      describe "validations" do
        it { should validate_presence_of :patient }
        it { should validate_presence_of :treatable }
        it { should validate_presence_of(:drug) }
        it { should validate_presence_of(:dose_amount) }
        it { should validate_presence_of(:dose_unit) }
        it { should validate_presence_of(:medication_route) }
        it { should validate_presence_of(:frequency) }
        it { should validate_presence_of(:prescribed_on) }
        it { should validate_presence_of(:provider) }

        describe "#valid?" do
          context "route description" do
            context "given a route" do
              before { subject.medication_route = build(:medication_route) }

              it { is_expected.not_to validate_presence_of(:route_description) }
            end

            context "given a `other` route" do
              before { subject.medication_route = build(:medication_route, :other) }

              it { is_expected.to validate_presence_of(:route_description) }
            end

            context "given a route and a route description" do
              before do
                subject.medication_route = build(:medication_route)
                subject.route_description = "::route description::"
              end

              it "adds an error" do
                subject.valid?

                expect(subject.errors[:route_description]).to be_present
              end
            end
          end
        end
      end

      describe "scopes" do
        before do
          create(:prescription, notes: ":expires_today:", terminated_on: "2010-01-02")
          create(:prescription, notes: ":expired_yesteday:", terminated_on: "2010-01-01")
          create(:prescription, notes: ":not_specified:")
          create(:prescription, notes: ":expires_tomorrow:", terminated_on: "2010-01-03")
        end

        describe ".current" do
          subject(:prescriptions) { Prescription.current("2010-01-02") }

          it "returns prescriptions that terminate today or later, or not specified" do
            expect(prescriptions.map(&:notes)).to \
              include(":expires_tomorrow:", ":not_specified:")
            expect(prescriptions.map(&:notes)).not_to \
              include(":expires_today:", ":expires_yesterday:")
          end
        end

        describe ".terminated" do
          subject(:prescriptions) { Prescription.terminated("2010-01-02") }

          it "returns prescriptions that terminate today or later, or not specified" do
            expect(prescriptions.map(&:notes)).to \
              include(":expires_today:", ":expired_yesteday:")
            expect(prescriptions.map(&:notes)).not_to \
              include(":expires_tomorrow:", ":not_specified:")
          end
        end
      end

      describe "state predicates" do
        let(:date_today) { Date.parse("2010-01-02")}
{'fraction_non_alphanumeric': 0.09772279003048234, 'fraction_numerical': 0.015779092702169626, 'mean_word_length': 2.2811764705882354, 'pattern_counts': {'":': 22, '<': 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': '5896605', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1448, 'n_words': 349}