Sha256: 185bfe66b1e4a9e653d455b62a684fa9afb046517b8cb7460288f569de24e852
Contents?: true
Size: 1.88 KB
Versions: 14
Compression:
Stored size: 1.88 KB
Contents
RSpec.describe "Segmented indexes", elasticsearch: true do subject do Class.new(Elasticity::SegmentedDocument) do def self.name "SomeClass" end configure do |c| c.index_base_name = "people" c.document_type = "person" c.mapping = { properties: { name: { type: "string" }, }, } end attr_accessor :name def self.by_name(name) search(query: { match: { name: name } }) end def to_document { name: name } end end end def ensure_index(*segments) @indexed ||= [] segments.each(&:recreate_index) @indexed += segments end after do Array(@indexed).each { |i| i.delete_index } end it "allows all operations on a segment" do seg = subject.segment("A") ensure_index(seg) rodrigo = seg.new(name: "rodrigo") id, success = rodrigo.update expect(id).to be_kind_of(String) expect(success).to be true seg.flush_index results = seg.by_name("rodrigo").to_a.first expect(results.class).to eq rodrigo.class expect(results.name).to eq rodrigo.name rodrigo.delete seg.flush_index results = seg.by_name("rodrigo").to_a expect(results).to be_empty end it "isolates segments from one another" do seg_a = subject.segment("A") seg_b = subject.segment("B") ensure_index(seg_a, seg_b) doc_a = seg_a.new(name: "doc a") _, success = doc_a.update expect(success).to be true doc_b = seg_b.new(name: "doc b") _, success = doc_b.update expect(success).to be true seg_a.flush_index seg_b.flush_index res_a = seg_a.by_name("doc").to_a.first expect(res_a.class).to eq doc_a.class expect(res_a.name).to eq doc_a.name res_b = seg_b.by_name("doc").to_a.first expect(res_b.class).to eq doc_b.class expect(res_b.name).to eq doc_b.name end end
Version data entries
14 entries across 14 versions & 1 rubygems