Sha256: 10d9cda8b3a4df51eb84af87f3002d9ddb3edf3bd7e237c84a725f652a3c898a

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

RSpec.describe Aldous::Controller::PreconditionsExecutionService do
  let(:preconditions_execution_service) {described_class.new(action_wrapper, controller)}

  let(:controller) {double "controller"}
  let(:action_wrapper) {double 'action wrapper', preconditions: preconditions, controller_action: action}
  let(:action) {double 'action'}

  let(:preconditions) { [] }

  describe "#perform" do
    subject(:perform) {preconditions_execution_service.perform}

    context "when no preconditions defined" do
      it "returns an array of nils" do
        expect(perform).to eq [nil, nil]
      end
    end

    context "when preconditions defined" do
      let(:preconditions) { [precondition_class] }
      let(:precondition_class) {double 'precondition_class', build: precondition}
      let(:precondition) {double "precondition", perform: nil}

      it "builds the precondition with the controller_aciont" do
        expect(precondition_class).to receive(:build).with(action)
        perform
      end

      context "but they don't short-circuit execution" do
        it "returns an array of nils" do
          expect(perform).to eq [nil, nil]
        end
      end

      context "and they short-circuit execution" do
        let(:precondition) {double "precondition", perform: precondition_result}
        let(:precondition_result) {Aldous::Respondable::Renderable.new(nil, nil, nil)}

        it "returns an array of precondition and precondition result" do
          expect(perform).to eq [precondition, precondition_result]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aldous-1.0.1 spec/aldous/controller/preconditions_execution_service_spec.rb
aldous-1.0.0 spec/aldous/controller/preconditions_execution_service_spec.rb