Sha256: 7b91288e044bf6edbf2b83085f413cb3d4b317f5fc0006db68f6ce8f5be69cd2

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Azeroth::RequestHandler do
  describe '#process' do
    subject(:handler) { handler_class.new(controller, model) }

    let(:controller) { controller_class.new }
    let(:params)     { ActionController::Parameters.new(parameters) }
    let(:model)      { Azeroth::Model.new(:document) }

    let(:decorator)       { Document::Decorator.new(Document.all) }
    let(:expected_json)   { decorator.as_json }
    let(:documents_count) { 3 }

    let(:controller_class) { RequestHandlerController }

    let(:parameters) do
      { format: format }
    end

    let(:handler_class) do
      Class.new(described_class) do
        private

        def resource
          Document.all
        end
      end
    end

    before do
      documents_count.times { create(:document) }

      allow(controller).to receive(:params)
        .and_return(params)

      allow(controller).to receive(:render)
        .with(json: expected_json)
        .and_return(expected_json)
    end

    context 'with format json' do
      let(:format) { 'json' }

      it 'returns json for resource' do
        expect(handler.process).to eq(expected_json)
      end

      it 'renders the json' do
        handler.process

        expect(controller).to have_received(:render)
      end
    end

    context 'with format html' do
      let(:format) { 'html' }

      it do
        handler.process

        expect(controller).not_to have_received(:render)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
azeroth-0.2.0 spec/lib/azeroth/request_handler_spec.rb
azeroth-0.1.0 spec/lib/azeroth/request_handler_spec.rb