Sha256: e937b60b06e7f7bef18ee7c8fba332602b4d515d634d2bdea5d6ba459f2db71d

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe Alephant::Broker::ResponseFactory do
  describe "#response_from(request)" do
    let (:request) { double("Alephant::Broker::Request") }
    let (:post_request) { double("Alephant::Broker::PostRequest") }

    it "should return asset response" do
      instance = Alephant::Broker::ResponseFactory.new({})
      allow(request).to receive(:type).and_return(:asset)

      Alephant::Broker::AssetResponse
        .any_instance
        .stub(:initialize)
        .with(request, {})

      expect(instance.response_from(request))
        .to be_a Alephant::Broker::AssetResponse
    end

    it "should return batched response" do
      instance = Alephant::Broker::ResponseFactory.new({})
      allow(post_request).to receive(:type).and_return(:batch)
      allow(post_request).to receive(:content_type).and_return('application/json')
      allow(post_request).to receive(:set_component)
      allow(post_request).to receive(:components).and_return({
        :batch_id   => 'baz',
        :components => [
          { 'component' => 'foo1', 'variant'   => 'bar1' },
          { 'component' => 'foo2', 'variant'   => 'bar2' }
        ]
      })

      Alephant::Broker::AssetResponse
        .any_instance
        .stub(:initialize)
        .with(post_request, {})

      expect(instance.response_from(post_request))
        .to be_a Alephant::Broker::BatchResponse
    end

    it "should return status response" do
      allow(request).to receive(:type).and_return(:status)
      response = subject.response_from(request)
      expect(response.status).to eq(200)
    end

    it "should return 404 response" do
      allow(request).to receive(:type).and_return(:notfound)
      response = subject.response_from(request)
      expect(response.status).to eq(404)
    end

    it "should return 500 response" do
      allow(request).to receive(:type).and_return(:error)
      response = subject.response_from(request)
      expect(response.status).to eq(500)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alephant-broker-0.1.5 spec/response_factory_spec.rb
alephant-broker-0.1.4 spec/response_factory_spec.rb
alephant-broker-0.1.3 spec/response_factory_spec.rb
alephant-broker-0.1.2 spec/response_factory_spec.rb
alephant-broker-0.1.1 spec/response_factory_spec.rb
alephant-broker-0.1.0 spec/response_factory_spec.rb