spec/units/search_spec.rb in es-elasticity-0.3.4 vs spec/units/search_spec.rb in es-elasticity-0.3.5

- old
+ new

@@ -11,10 +11,34 @@ { "_id" => 1, "_source" => { "name" => "foo" } }, { "_id" => 2, "_source" => { "name" => "bar" } }, ]}} end + let :aggregations do + { + "logins_count" => { "value" => 1495 }, + "gender" => { + "buckets" => [ + { + "doc_count" => 100, + "key" => "M" + }, + { + "doc_count" => 100, + "key" => "F" + } + ], + "doc_count_error_upper_bound" => 0, + "sum_other_doc_count" => 0 + } + } + end + + let :full_response_with_aggregations do + full_response.merge("aggregations" => aggregations) + end + let :ids_response do { "hits" => { "total" => 2, "hits" => [ { "_id" => 1 }, { "_id" => 2 }, ]}} @@ -70,9 +94,16 @@ expect(docs[0].name).to eq expected[0].name expect(docs[1].name).to eq expected[1].name expect(docs.each.first).to eq expected[0] expect(Array(docs)).to eq expected + end + + it "searches and the index returns aggregations" do + expect(client).to receive(:search).with(index: index_name, type: document_type, body: body).and_return(full_response_with_aggregations) + + docs = subject.documents(klass) + expect(docs.aggregations).to eq aggregations end it "searches using scan&scroll" do expect(client).to receive(:search).with(index: index_name, type: document_type, body: body, search_type: "scan", size: 100, scroll: "1m").and_return(scan_response) expect(client).to receive(:scroll).with(scroll_id: "abc123", scroll: "1m").and_return(scroll_response)