Sha256: a13c52d4563ffdc26c4b9ea24bfa942779dcd4341d32d66d55db01d47e54fed2

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'rails_helper'

module RocketJobMissionControl
  RSpec.describe Jobs::FailuresController do
    routes { Engine.routes }

    describe "GET #index" do
      describe "with a failed job" do
        let(:job) { spy(failed?: true, id: 42) }
        let(:slice_errors) do
          [
            {
              '_id' =>
              {
                'error_class' => 'BoomError',
              },
              'message' => ['boom'],
              'count'   => '1337',
            },
          ]
        end
        let(:selected_exception) { spy(count: 1337, first: current_failure) }
        let(:current_failure) { {'exception' => 'Doh! Something blew up!'} }

        before do
          allow(RocketJob::Job).to receive(:find).and_return(job)
          allow(job).to receive_message_chain('input.collection.aggregate') { slice_errors }
          allow(job).to receive_message_chain('input.collection.find.limit') { selected_exception }
          get :index, job_id: job.id
        end

        it 'succeeds' do
          expect(response).to be_success
        end
        it 'returns the job' do
          expect(assigns(:job)).to eq(job)
        end
        it 'returns the errors' do
          expect(assigns(:slice_errors)).to eq(slice_errors)
        end
        it 'returns the first exception' do
          expect(assigns(:failure_exception)).to eq(current_failure['exception'])
        end
      end

      describe "with a job that is not failed" do
        let(:job) { spy(failed?: false, id: 42) }

        before do
          allow(RocketJob::Job).to receive(:find).and_return(job)
          get :index, job_id: job.id
        end

        it "redirects to the job" do
          expect(response).to redirect_to(job_path(job.id))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rocketjob_mission_control-1.2.0 spec/controllers/jobs/failures_controller_spec.rb