Sha256: dd5371d17e4d9f8b5b4215b8bc43767a081b73badd497718b72528074bb28833

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

require "elasticity/search"

RSpec.describe Elasticity::Document do
  mappings = {
    properties: {
      name: { type: "string" },

      items: {
        type: "nested",
        properties: {
          name: { type: "string" },
        },
      }
    }
  }

  let :klass do
    Class.new(described_class) do
      def self.name
        "SomeClass"
      end

      configure do |c|
        c.index_base_name = "class_names"
        c.document_type   = "class_name"
        c.mapping         = mappings
      end

      attr_accessor :name, :items

      def to_document
        { name: name, items: items }
      end
    end
  end

  let :strategy do
    double(:strategy)
  end

  before :each do
    allow(Elasticity::Strategies::SingleIndex).to receive(:new).and_return(strategy)
  end

  it "requires subclasses to define to_document method" do
    expect { Class.new(described_class).new.to_document }.to raise_error(NotImplementedError)
  end

  context "instance" do
    subject { klass.new _id: 1, name: "Foo", items: [{ name: "Item1" }] }

    it "stores the document in the strategy" do
      expect(strategy).to receive(:index_document).with("class_name", 1, { name: "Foo", items: [{ name: "Item1" }] }).and_return("_id" => "1", "created" => true)
      subject.update
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
es-elasticity-0.7.1 spec/units/document_spec.rb
es-elasticity-0.7.0 spec/units/document_spec.rb
es-elasticity-0.6.5 spec/units/document_spec.rb
es-elasticity-0.6.4 spec/units/document_spec.rb
es-elasticity-0.6.3 spec/units/document_spec.rb
es-elasticity-0.6.2 spec/units/document_spec.rb
es-elasticity-0.6.1 spec/units/document_spec.rb
es-elasticity-0.6.0 spec/units/document_spec.rb