Sha256: e055c3b3f8d2d1a2e5b9a278f5f707025e75f8cd66fd1cea865f05b46246a100

Contents?: true

Size: 1.99 KB

Versions: 41

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

RSpec.describe ActiveFedora::SchemaIndexingStrategy do
  subject(:index_strategy) { described_class.new(property_indexer_factory) }

  describe "#apply" do
    let(:property) do
      p = object_double(ActiveTriples::Property.new(name: nil))
      allow(p).to receive(:to_h).and_return(options)
      allow(p).to receive(:name).and_return(name)
      p
    end
    let(:name) { "Name" }
    let(:options) do
      {
        class_name: "Test"
      }
    end
    let(:object) do
      o = object_double(ActiveFedora::Base)
      allow(o).to receive(:property).and_yield(index_configuration)
      o
    end
    let(:index_configuration) do
      d = double("index configuration")
      allow(d).to receive(:as)
      d
    end
    let(:property_indexer) do
      p = double("property_indexer")
      allow(p).to receive(:index).with(anything) do |index|
        index.as(*Array.wrap(index_types))
      end
      p
    end
    let(:property_indexer_factory) do
      p = double("property indexer factory")
      allow(p).to receive(:new).with(anything).and_return(property_indexer)
      p
    end
    let(:index_types) {}
    context "with no index types" do
      subject(:index_strategy) { described_class.new }
      it "does not try to index it" do
        index_strategy.apply(object, property)

        expect(object).to have_received(:property).with(property.name, property.to_h)
        expect(index_configuration).not_to have_received(:as)
      end
    end
    context "with one index type" do
      let(:index_types) { :symbol }
      it "applies that one" do
        index_strategy.apply(object, property)

        expect(index_configuration).to have_received(:as).with(:symbol)
      end
    end
    context "with multiple index types" do
      let(:index_types) { [:symbol, :stored_searchable] }
      it "applies all of them" do
        index_strategy.apply(object, property)

        expect(index_configuration).to have_received(:as).with(:symbol, :stored_searchable)
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.2.3 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.5.6 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.2.2 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.2.1 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.2.1 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.0.3 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.5.5 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-13.1.2 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-13.1.1 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-13.1.0 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-13.0.0 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.1.1 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.1.0 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.5.4 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.5.3 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.0.2 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.0.1 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-11.5.2 spec/unit/schema_indexing_strategy_spec.rb
active-fedora-12.0.0 spec/unit/schema_indexing_strategy_spec.rb