Sha256: 32f69c562ea5edca71f7f1a0b58bf3a1a40be651ce686e5778f77a42ae05ee76

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

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

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

  before do
    resource_builder.append
    10.times { Document.create }
  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)   { Document.create }

      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

5 entries across 5 versions & 1 rubygems

Version Path
azeroth-0.2.0 spec/lib/azeroth/resource_builder_spec.rb
azeroth-0.1.0 spec/lib/azeroth/resource_builder_spec.rb
azeroth-0.0.7 spec/lib/azeroth/resource_builder_spec.rb
azeroth-0.0.6 spec/lib/azeroth/resource_builder_spec.rb
azeroth-0.0.5 spec/lib/azeroth/resource_builder_spec.rb