Sha256: 65ec49133a3fd062a02b14cf244ec8e43327f37c49b37dd16822aea0738527d1

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

shared_examples 'a request handler' do |status: :ok|
  subject(:handler) do
    described_class.new(controller, model, options)
  end

  let(:controller)      { controller_class.new }
  let(:params)          { ActionController::Parameters.new(parameters) }
  let(:model)           { Azeroth::Model.new(:document, options) }
  let(:options)         { Azeroth::Options.new(options_hash) }
  let(:options_hash)    { {} }
  let(:extra_params)    { {} }

  let(:decorator)       { Document::Decorator.new(expected_resource) }
  let(:expected_json)   { decorator.as_json }
  let(:documents_count) { 0 }

  let(:controller_class) { RequestHandlerController }

  let(:format) { 'json' }

  let(:parameters) do
    { format: format }.merge(extra_params)
  end

  let(:controller_headers) { {} }

  before do
    create_list(:document, documents_count)

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

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

    allow(controller).to receive(:headers)
      .and_return(controller_headers)
  end

  it 'returns all documents json' do
    expect(handler.process).to eq(expected_json)
  end

  it 'renders the json' do
    handler.process

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

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

    it do
      handler.process

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
azeroth-1.0.0 spec/support/shared_examples/request_handler.rb
azeroth-0.10.1 spec/support/shared_examples/request_handler.rb
azeroth-0.10.0 spec/support/shared_examples/request_handler.rb
azeroth-0.9.0 spec/support/shared_examples/request_handler.rb
azeroth-0.8.2 spec/support/shared_examples/request_handler.rb
azeroth-0.8.1 spec/support/shared_examples/request_handler.rb