Sha256: df58a0b511e2faf924413e8513f0b2414ce043b02b5326b5166f07ee1e803bb6

Contents?: true

Size: 1.03 KB

Versions: 74

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

RSpec.describe 'Blacklight::Document::ActiveModelShim', api: true do
  class MockDocument
    include Blacklight::Document
    include Blacklight::Document::ActiveModelShim
  end

  class MockResponse
    attr_reader :response, :params

    def initialize(response, params)
      @response = response
      @params = params
    end

    def documents
      response.collect { |doc| MockDocument.new(doc, self) }
    end
  end

  before do
    allow(MockDocument).to receive(:repository).and_return(double(find: MockResponse.new([{ id: 1 }], {})))
  end

  describe "#find" do
    it "returns a document from the repository" do
      expect(MockDocument.find(1)).to be_a MockDocument
      expect(MockDocument.find(1).id).to be 1
    end
  end

  describe "#==" do
    it 'is equal for the same id' do
      expect(MockDocument.new(id: 1) == MockDocument.new(id: 1)).to eq true
    end

    it 'is not equal if the ids differ' do
      expect(MockDocument.new(id: 1) == MockDocument.new(id: 2)).to eq false
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
blacklight-7.40.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.39.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.38.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.37.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.36.2 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.36.1 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.36.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.35.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.34.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.33.1 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.33.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.32.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.31.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.30.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.29.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.28.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.27.1 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.27.0 spec/models/blacklight/document/active_model_shim_spec.rb
blacklight-7.26.1 spec/models/blacklight/document/active_model_shim_spec.rb