Sha256: cf3a13f1ef79e62bfc53826093ec8e4237398f3f0974a1a6bd8e96e063b3a369

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"

require 'roqua/responders/active_interaction_aware_responder'
class AIAResponder < ActionController::Responder
  include Roqua::Responders::ActiveInteractionAwareResponder
end

require 'active_interaction'
class TestInteraction < ActiveInteraction::Base
  string :some_string
  def execute
    {foo: some_string}
  end
end

class ApplicationController < ActionController::Base
  respond_to :json
end

describe Roqua::Responders::ActiveInteractionAwareResponder, type: :controller do
  context 'with a valid interaction' do
    controller(ApplicationController) do
      self.responder  = AIAResponder
      def index
        use_case = TestInteraction.run some_string: 'bla'
        respond_with use_case
      end
    end

    subject { get :index, format: :json }

    it 'returns the result if valid' do
      subject
      expect(response.body).to eq '{"foo":"bla"}'
    end

  end

  context 'with an invalid interaction' do
    controller(ApplicationController) do
      self.responder  = AIAResponder
      def index
        use_case = TestInteraction.run
        respond_with use_case
      end
    end
    subject { post :index, format: :json }

    it 'returns the interaction' do
      subject
      expect(response.body).to eq '{"errors":{"some_string":["is required"]}}'
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
roqua-support-0.4.4 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.4.3 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.4.2 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.4.1 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.4.0 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.5 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.4 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.3 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.2 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.1 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.3.0 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.34 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.33 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.32 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.31 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.30 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.29 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.28 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.27 spec/roqua/responders/active_interaction_aware_responder_spec.rb
roqua-support-0.1.26 spec/roqua/responders/active_interaction_aware_responder_spec.rb