<commit_before>shared_examples 'description_controller_spec' do
  describe 'GET #show' do
    before do
      dossier.update_column :autorisation_donnees, true
    end
    context 'user is not connected' do
      before do
        sign_out dossier.user
      end

      it 'redirects to users/sign_in' do
        get :show, params: {dossier_id: dossier_id}
        expect(response).to redirect_to('/users/sign_in')
      end
    end

    context 'when all is ok' do
      before do
        dossier.entreprise = create :entreprise
        get :show, params: {dossier_id: dossier_id}
      end

      it 'returns http success' do
        expect(response).to have_http_status(:success)
      end

      context 'procedure is archived' do
        render_views
        let(:archived_at) { Time.now }

        it { expect(response).to have_http_status(:success) }
        it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }

        context 'dossier is a brouillon' do
          let(:state) { 'brouillon' }

          it { expect(response).to have_http_status(:success) }
          it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) }
        end
      end
    end

    it 'redirection vers start si mauvais dossier ID' do
      get :show, params: {dossier_id: bad_dossier_id}

      expect(flash[:alert]).to be_present
      expect(response).to redirect_to(root_path)
    end

    it_behaves_like "not owner of dossier", :show

    describe 'before_action authorized_routes?' do
      context 'when dossier does not have a valid state' do
        before do
          dossier.state = 'en_instruction'
          dossier.save

          get :show, params: {dossier_id: dossier.id}
        end

        it { is_expected.to redirect_to root_path }
      end
    end

    describe 'before action check_autorisation_donnees' do
      subject { get :show, params: {dossier_id: dossier_id} }

      context 'when dossier does not have a valid autorisations_donness (nil)' do
        before do
          dossier.update_column :autorisation_donnees, nil
        end

        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end

      context 'when dossier does not have a valid autorisations_donness (false)' do
        before do
          dossier.update_column :autorisation_donnees, false
        end

        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end
    end

    describe 'before action check_starter_dossier_informations' do
      subject { get :show, params: {dossier_id: dossier_id} }

      context 'when dossier does not have an enterprise datas' do
        before do
        end

        it { expect(dossier.entreprise).to be_nil }
        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end

      context 'when dossier does not have an individual datas' do
        before do
          procedure.update_column :for_individual, true
        end

        it { expect(dossier.individual).to be_nil }
        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end
    end
  end

  describe 'POST #update' do
    let(:timestamp) { Time.now }
    let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut  la ligne.' }

    context 'Tous les attributs sont bons' do
      describe 'Premier enregistrement des données' do
        subject { post :update, params: {dossier_id: dossier_id, submit: submit} }

        before do
          dossier.brouillon!
          subject
          dossier.reload
        end

        context "when the user submits the dossier" do
          let(:submit) { {nouveaux: 'nouveaux'} }

          it "redirection vers la page recapitulative" do
            expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
          end
<commit_msg>[#1209] remove unused test code<commit_after>shared_examples 'description_controller_spec' do
  describe 'GET #show' do
    before do
      dossier.update_column :autorisation_donnees, true
    end
    context 'user is not connected' do
      before do
        sign_out dossier.user
      end

      it 'redirects to users/sign_in' do
        get :show, params: {dossier_id: dossier_id}
        expect(response).to redirect_to('/users/sign_in')
      end
    end

    context 'when all is ok' do
      before do
        dossier.entreprise = create :entreprise
        get :show, params: {dossier_id: dossier_id}
      end

      it 'returns http success' do
        expect(response).to have_http_status(:success)
      end

      context 'procedure is archived' do
        render_views
        let(:archived_at) { Time.now }

        it { expect(response).to have_http_status(:success) }
        it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }

        context 'dossier is a brouillon' do
          let(:state) { 'brouillon' }

          it { expect(response).to have_http_status(:success) }
          it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) }
        end
      end
    end

    it 'redirection vers start si mauvais dossier ID' do
      get :show, params: {dossier_id: bad_dossier_id}

      expect(flash[:alert]).to be_present
      expect(response).to redirect_to(root_path)
    end

    it_behaves_like "not owner of dossier", :show

    describe 'before_action authorized_routes?' do
      context 'when dossier does not have a valid state' do
        before do
          dossier.state = 'en_instruction'
          dossier.save

          get :show, params: {dossier_id: dossier.id}
        end

        it { is_expected.to redirect_to root_path }
      end
    end

    describe 'before action check_autorisation_donnees' do
      subject { get :show, params: {dossier_id: dossier_id} }

      context 'when dossier does not have a valid autorisations_donness (nil)' do
        before do
          dossier.update_column :autorisation_donnees, nil
        end

        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end

      context 'when dossier does not have a valid autorisations_donness (false)' do
        before do
          dossier.update_column :autorisation_donnees, false
        end

        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end
    end

    describe 'before action check_starter_dossier_informations' do
      subject { get :show, params: {dossier_id: dossier_id} }

      context 'when dossier does not have an enterprise datas' do
        it { expect(dossier.entreprise).to be_nil }
        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end

      context 'when dossier does not have an individual datas' do
        before do
          procedure.update_column :for_individual, true
        end

        it { expect(dossier.individual).to be_nil }
        it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
      end
    end
  end

  describe 'POST #update' do
    context 'Tous les attributs sont bons' do
      describe 'Premier enregistrement des données' do
        subject { post :update, params: {dossier_id: dossier_id, submit: submit} }

        before do
          dossier.brouillon!
          subject
          dossier.reload
        end

        context "when the user submits the dossier" do
          let(:submit) { {nouveaux: 'nouveaux'} }

          it "redirection vers la page recapitulative" do
            expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
          end

{'fraction_non_alphanumeric': 0.08418034923117018, 'fraction_numerical': 0.001563721657544957, 'mean_word_length': 2.4603246167718664, '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': '14868', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2270, 'n_words': 654}