|
| 1 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +# license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright |
| 4 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +# the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +require 'spec_helper' |
| 19 | + |
| 20 | +describe Elasticsearch::DSL::Search::Aggregations::Composite do |
| 21 | + |
| 22 | + let(:search) do |
| 23 | + described_class.new |
| 24 | + end |
| 25 | + |
| 26 | + describe '#to_hash' do |
| 27 | + |
| 28 | + it 'can be converted to a hash' do |
| 29 | + expect(search.to_hash).to eq(composite: {}) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'when options methods are called' do |
| 34 | + |
| 35 | + let(:search) do |
| 36 | + described_class.new(:foo) |
| 37 | + end |
| 38 | + |
| 39 | + describe '#size' do |
| 40 | + |
| 41 | + before do |
| 42 | + search.size(2_000) |
| 43 | + end |
| 44 | + |
| 45 | + it 'applies the option' do |
| 46 | + expect(search.to_hash[:composite][:foo][:size]).to eq(2_000) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + describe '#sources' do |
| 51 | + |
| 52 | + before do |
| 53 | + search.sources('bar') |
| 54 | + end |
| 55 | + |
| 56 | + it 'applies the option' do |
| 57 | + expect(search.to_hash[:composite][:foo][:sources]).to eq('bar') |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + describe '#after' do |
| 62 | + context 'when after is not given' do |
| 63 | + before do |
| 64 | + search.size(2_000) |
| 65 | + end |
| 66 | + |
| 67 | + it 'applies the option' do |
| 68 | + expect(search.to_hash[:composite][:foo].keys).not_to include(:after) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'when after is given' do |
| 73 | + before do |
| 74 | + search.after('fake_after_key') |
| 75 | + end |
| 76 | + |
| 77 | + it 'applies the option' do |
| 78 | + expect(search.to_hash[:composite][:foo][:after]).to eq('fake_after_key') |
| 79 | + end |
| 80 | + end |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + describe '#initialize' do |
| 85 | + |
| 86 | + context 'when a block is provided' do |
| 87 | + |
| 88 | + let(:search) do |
| 89 | + described_class.new(:foo) do |
| 90 | + size 2_000 |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + it 'executes the block' do |
| 95 | + expect(search.to_hash).to eq({ composite: { foo: { size: 2_000 } } }) |
| 96 | + end |
| 97 | + end |
| 98 | + end |
| 99 | +end |
0 commit comments