spec/units/search_spec.rb in es-elasticity-0.2.4 vs spec/units/search_spec.rb in es-elasticity-0.2.5
- old
+ new
@@ -5,33 +5,33 @@
let(:document_type) { "document" }
let(:body) { {} }
let :full_response do
{ "hits" => { "total" => 2, "hits" => [
- {"_source" => { "id" => 1, "name" => "foo" }},
- {"_source" => { "id" => 2, "name" => "bar" }},
+ { "_id" => 1, "_source" => { "name" => "foo" } },
+ { "_id" => 2, "_source" => { "name" => "bar" } },
]}}
end
let :ids_response do
{ "hits" => { "total" => 2, "hits" => [
- {"_source" => { "id" => 1, "name" => "foo" }},
- {"_source" => { "id" => 2, "name" => "bar" }},
+ { "_id" => 1 },
+ { "_id" => 2 },
]}}
end
let :empty_response do
{ "hits" => { "total" => 0, "hits" => [] }}
end
let :klass do
Class.new do
include ActiveModel::Model
- attr_accessor :id, :name
+ attr_accessor :_id, :name
def ==(other)
- self.id == other.id && self.name == other.name
+ self._id == other._id && self.name == other.name
end
end
end
describe Elasticity::Search do
@@ -41,11 +41,11 @@
it "searches the index and return document models" do
expect(index).to receive(:search).with(document_type, body).and_return(full_response)
docs = subject.documents(klass)
- expected = [klass.new(id: 1, name: "foo"), klass.new(id: 2, name: "bar")]
+ expected = [klass.new(_id: 1, name: "foo"), klass.new(_id: 2, name: "bar")]
expect(docs.total).to eq 2
expect(docs.size).to eq expected.size
expect(docs).to_not be_empty
@@ -57,11 +57,11 @@
expect(docs.each.first).to eq expected[0]
expect(Array(docs)).to eq expected
end
it "searches the index and return active record models" do
- expect(index).to receive(:search).with(document_type, body.merge(_source: [])).and_return(ids_response)
+ expect(index).to receive(:search).with(document_type, body.merge(_source: false)).and_return(ids_response)
relation = double(:relation,
connection: double(:connection),
table_name: "table_name",
klass: double(:klass, primary_key: "id"),
@@ -73,11 +73,11 @@
expect(subject.active_records(relation).mapping).to be relation
end
it "return relation.none from activerecord relation with no matches" do
- expect(index).to receive(:search).with(document_type, body.merge(_source: [])).and_return(empty_response)
+ expect(index).to receive(:search).with(document_type, body.merge(_source: false)).and_return(empty_response)
relation = double(:relation)
expect(relation).to receive(:none).and_return(relation)
expect(subject.active_records(relation).mapping).to be relation
@@ -93,10 +93,10 @@
described_class.new(search, klass)
end
it "automatically maps the documents into the provided Document class" do
expect(index).to receive(:search).with(document_type, body).and_return(full_response)
- expect(Array(subject)).to eq [klass.new(id: 1, name: "foo"), klass.new(id: 2, name: "bar")]
+ expect(Array(subject)).to eq [klass.new(_id: 1, name: "foo"), klass.new(_id: 2, name: "bar")]
end
it "delegates active_records for the underlying search" do
records = double(:records)
rel = double(:relation)