Sha256: a0592c0799d9968c421d8c8e1f544b97fc07d01e4fc72dcc128d41c6b12f5701

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Azeroth::ResourceBuilder do
  subject(:resource_builder) do
    described_class.new(model: model, builder: builder)
  end

  let(:model)   { Azeroth::Model.new(:document, options) }
  let(:options) { Azeroth::Options.new }
  let(:builder) { Sinclair.new(klass) }
  let(:klass)   { Class.new(ResourceBuilderController) }

  before do
    resource_builder.append
    create_list(:document, 10)
  end

  describe '#append' do
    it 'adds the listing method' do
      expect { builder.build }
        .to change { klass.new.respond_to?(:documents) }
        .to(true)
    end

    it 'adds the fetching method' do
      expect { builder.build }
        .to change { klass.new.respond_to?(:document) }
        .to(true)
    end

    describe 'after the build' do
      let(:controller) { klass.new(document_id: document.id) }
      let(:document)   { create(:document) }

      before { builder.build }

      context 'when requesting the list of documents' do
        it 'returns the list of documents' do
          expect(controller.documents).to eq(Document.all)
        end
      end

      context 'when requesting one document' do
        it 'returns the requested document' do
          expect(controller.document).to eq(document)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
azeroth-1.0.0 spec/lib/azeroth/resource_builder_spec.rb