Sha256: 2e4150c9a5d81325d18a0e05684cfddb7d01938620c9b9462a385e57daa3a309

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

RSpec.describe Aldous::Controller::Action::Wrapper do
  let(:wrapper) { described_class.new controller_action }

  let(:controller_action) { double 'controller action',
                            default_view_data: default_view_data,
                            preconditions: preconditions,
                            default_error_respondable: default_error_respondable,
                            perform: nil,
                            build_view: nil }

  let(:default_view_data) { {default_view_data: true} }
  let(:preconditions) { double 'preconditions' }
  let(:default_error_respondable) {double 'default_error_respondable'}

  before do
    allow(Aldous::LoggingWrapper).to receive(:log)
  end

  describe '#perform' do
    subject(:perform) { wrapper.perform }

    it "calls perform on the controller action" do
      expect(controller_action).to receive(:perform)
      perform
    end

    context 'when controller service throws an exception' do
      let(:e) { StandardError.new 'message' }

      before do
        allow(controller_action).to receive(:perform).and_raise(e)
      end

      it "builds a default error view with errors" do
        expect(controller_action).to receive(:build_view).with(default_error_respondable, errors: [e])
        perform
      end

      it 'reports the error' do
        expect(Aldous::LoggingWrapper).to receive(:log).with(e)
        perform
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aldous-1.0.0 spec/aldous/controller/action/wrapper_spec.rb