<commit_before>require 'rails_helper'
include Devise::TestHelpers

describe Admin::PendingOrphanListsController, type: :controller do
  let(:pending_orphan_list) { instance_double PendingOrphanList, spreadsheet: 'sheet', destroy!: true }
  let(:partner) { instance_double Partner }
  let(:orphan_lists) { double }
  let(:orphan_list) { double }
  let(:pending_orphans) { double }

  before(:each) do
    sign_in instance_double(AdminUser)

    allow(Partner).to receive(:find).with('1').and_return partner
    allow(PendingOrphanList).to receive(:new).and_return pending_orphan_list
    allow(PendingOrphanList).to receive(:find).with('1').and_return pending_orphan_list

    allow(partner).to receive(:orphan_lists).and_return orphan_lists
    allow(orphan_lists).to receive(:create!).and_return orphan_list
    allow(orphan_lists).to receive(:build).and_return orphan_list
  end

  describe 'upload' do
    context 'when partner is inactive' do
      it 'redirects to partner if partner not active' do
        expect(partner).to receive(:active?).and_return false
        get :upload, partner_id: 1
        expect(response).to redirect_to admin_partner_path(1)
      end
    end

    context 'when partner is active' do
      before(:each) do
        expect(partner).to receive(:active?).and_return true
        get :upload, partner_id: 1
      end

      it 'sets instance variables' do
        expect(assigns :partner).to eq partner
      end

      it 'renders :upload' do
        expect(response).to render_template :upload
      end
    end
  end

  describe 'validate' do
    context 'when partner is inactive' do
      it 'redirects to partner if partner not active' do
        expect(partner).to receive(:active?).and_return false
        post :validate, partner_id: 1
        expect(response).to redirect_to admin_partner_path(1)
      end
    end

    context 'when partner is active' do
      let(:orphan_list_params) { { spreadsheet: fixture_file_upload('one_orphan_xls.xls') } }

      before do
        allow(partner).to receive(:active?).and_return true
        allow(pending_orphan_list).to receive :save!
        allow(pending_orphan_list).to receive :pending_orphans=
        post :validate, partner_id: 1, pending_orphan_list: orphan_list_params
      end

      it 'sets instance variables' do
        expect(assigns :partner).to eq partner
        expect(assigns :pending_orphan_list).to eq pending_orphan_list
      end

      it 'saves pending_orphan_list' do
        expect(pending_orphan_list).to have_received :save!
      end

      it 'renders :validate' do
        expect(response).to render_template :validate
      end
    end
  end
<commit_msg>Fixed failing spec<commit_after>require 'rails_helper'
include Devise::TestHelpers

describe Admin::PendingOrphanListsController, type: :controller do
  let(:pending_orphan_list) { instance_double PendingOrphanList, spreadsheet: 'sheet', destroy!: true }
  let(:partner) { instance_double Partner }
  let(:orphan_lists) { double }
  let(:orphan_list) { double }
  let(:pending_orphans) { double }

  before(:each) do
    sign_in instance_double(AdminUser)

    allow(Partner).to receive(:find).with('1').and_return partner
    allow(PendingOrphanList).to receive(:new).and_return pending_orphan_list
    allow(PendingOrphanList).to receive(:find).with('1').and_return pending_orphan_list

    allow(partner).to receive(:orphan_lists).and_return orphan_lists
    allow(orphan_lists).to receive(:create!).and_return orphan_list
    allow(orphan_lists).to receive(:build).and_return orphan_list
  end

  describe 'upload' do
    context 'when partner is inactive' do
      it 'redirects to partner if partner not active' do
        expect(partner).to receive(:active?).and_return false
        get :upload, partner_id: 1
        expect(response).to redirect_to admin_partner_path(1)
      end
    end

    context 'when partner is active' do
      before(:each) do
        expect(partner).to receive(:active?).and_return true
        get :upload, partner_id: 1
      end

      it 'sets instance variables' do
        expect(assigns :partner).to eq partner
      end

      it 'renders :upload' do
        expect(response).to render_template :upload
      end
    end
  end

  describe 'validate' do
    context 'when partner is inactive' do
      it 'redirects to partner if partner not active' do
        expect(partner).to receive(:active?).and_return false
        post :validate, partner_id: 1
        expect(response).to redirect_to admin_partner_path(1)
      end
    end

    context 'when partner is active' do
      let(:orphan_list_params) { { spreadsheet: fixture_file_upload('one_orphan_xls.xls') } }

      before do
        allow(partner).to receive(:active?).and_return true
        allow(pending_orphan_list).to receive :save!
        allow(pending_orphan_list).to receive :pending_orphans=
        post :validate, partner_id: 1, pending_orphan_list: orphan_list_params
      end

      it 'sets instance variables' do
        expect(assigns :partner).to eq partner
        expect(assigns :pending_orphan_list).to eq pending_orphan_list
      end

      it 'saves pending_orphan_list' do
        expect(pending_orphan_list).to have_received :save!
      end

      it 'renders :validate' do
        expect(response).to render_template :valid_list
      end
    end
  end

{'fraction_non_alphanumeric': 0.08838336751818013, 'fraction_numerical': 0.0029834048107402573, 'mean_word_length': 3.429397192402973, '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': '2559811', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1570, 'n_words': 408}