<commit_before>require 'rails_helper'

describe AnamnesesController do
  describe '#new' do
    let(:patient) { double(:patient) }
    let(:anamnesis) { double(:anamnesis) }

    before do
      allow(Patient).to receive(:find).with('1') { patient }
      allow(Anamnesis).to receive(:new) { anamnesis }
      get :new, patient_id: '1'
    end

    it 'assings @patient' do
      expect(assigns(:patient)).to eq(patient)
    end

    it 'assings @anamnesis' do
      expect(assigns(:anamnesis)).to eq(anamnesis)
    end

    it { is_expected.to render_template :new }
    it { is_expected.to respond_with :ok }
  end

  describe '#create' do
    let(:patient) { create(:patient) }
    let(:attributes_for_anamnesis) do
      {
        personal_history: 'personal history',
        surgical_history: 'surgical history',
        allergies: 'allergies',
        observations: 'observations',
        habits: 'habits',
        family_history: 'family history'
      }
    end

    before do |example|
      unless example.metadata[:skip_on_before]
        post :create, anamnesis: attributes_for_anamnesis,
                      patient_id: patient.id.to_s
      end
    end

    it 'creates a new anamnesis', :skip_on_before do
      expect do
        post :create, anamnesis: attributes_for_anamnesis,
                      patient_id: patient.id.to_s
      end.to change { Anamnesis.count }.by(1)
    end

    it { is_expected.to redirect_to patients_path }
    it { is_expected.to respond_with :redirect }<commit_msg>Use `attributes_for` instead of an explicit hash of attributes<commit_after>require 'rails_helper'

describe AnamnesesController do
  describe '#new' do
    let(:patient) { double(:patient) }
    let(:anamnesis) { double(:anamnesis) }

    before do
      allow(Patient).to receive(:find).with('1') { patient }
      allow(Anamnesis).to receive(:new) { anamnesis }
      get :new, patient_id: '1'
    end

    it 'assings @patient' do
      expect(assigns(:patient)).to eq(patient)
    end

    it 'assings @anamnesis' do
      expect(assigns(:anamnesis)).to eq(anamnesis)
    end

    it { is_expected.to render_template :new }
    it { is_expected.to respond_with :ok }
  end

  describe '#create' do
    let(:patient)                  { create(:patient) }
    let(:attributes_for_anamnesis) { attributes_for(:anamnesis) }

    before do |example|
      unless example.metadata[:skip_on_before]
        post :create, anamnesis: attributes_for_anamnesis,
                      patient_id: patient.id.to_s
      end
    end

    it 'creates a new anamnesis', :skip_on_before do
      expect do
        post :create, anamnesis: attributes_for_anamnesis,
                      patient_id: patient.id.to_s
      end.to change { Anamnesis.count }.by(1)
    end

    it { is_expected.to redirect_to patients_path }
    it { is_expected.to respond_with :redirect }
{'fraction_non_alphanumeric': 0.10295652173913043, 'fraction_numerical': 0.0020869565217391303, 'mean_word_length': 2.7157622739018086, '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': '3824172', 'n_tokens_mistral': 951, 'n_tokens_neox': 923, 'n_words': 216}