Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions elasticsearch-dsl/spec/filters/and_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Filters::And do

let(:search) do
described_class.new
end

describe '#to_hash' do

it 'can be converted to a hash' do
expect(search.to_hash).to eq(and: {})
end
end

context 'when enumerable methods are called' do

before do
search << { term: { foo: 'bar' } }
search << { term: { moo: 'mam' } }
end

it 'behaves like an enumerable' do
expect(search.size).to eq(2)
expect(search[0][:term][:foo]).to eq('bar')
expect(search.any? { |d| d[:term] == { foo: 'bar' } }).to be(true)
end
end

describe '#initialize' do

context 'when a hash is provided' do

let(:search) do
described_class.new(filters: [ { term: { foo: 'bar' } } ])
end

it 'applies the hash' do
expect(search.to_hash).to eq(and: { filters: [ { term: { foo: 'bar' } } ] })
end
end

context 'when a block is provided' do

let(:search) do
described_class.new do
term foo: 'bar'
term moo: 'mam'
end
end

it 'executes the block' do
expect(search.to_hash).to eq(and: [ { term: { foo: 'bar' } }, { term: { moo: 'mam' } } ])
end
end
end
end
132 changes: 132 additions & 0 deletions elasticsearch-dsl/spec/filters/bool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Filters::Bool do

let(:search) do
described_class.new
end

describe '#to_hash' do

it 'can be converted to a hash' do
expect(search.to_hash).to eq(bool: {})
end
end

describe '#initialize' do

context 'when a hash is provided' do

let(:search) do
described_class.new(must: [ {term: { foo: 'bar' } } ])
end

it 'applies the hash' do
expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' } } ] })
end
end

context 'when a block is provided' do

let(:search) do
described_class.new do
must { term foo: 'bar' }
end
end

it 'executes the block' do
expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' }} ] })
end

context 'when the block calls multiple methods' do

let(:search) do
described_class.new do
must { term foo: 'bar' }
must_not { term moo: 'bam' }
should { term xoo: 'bax' }
end
end

it 'executes the block' do
expect(search.to_hash).to eq(bool:
{ must: [ {term: { foo: 'bar' }} ],
must_not: [ {term: { moo: 'bam' }} ],
should: [ {term: { xoo: 'bax' }} ]
})
end
end

context 'when the block calls multiple conditions' do

let(:search) do
described_class.new do
must { term foo: 'bar' }
must { term moo: 'bam' }

should { term xoo: 'bax' }
should { term zoo: 'baz' }
end
end

it 'executes the block' do
expect(search.to_hash).to eq(bool:
{ must: [ {term: { foo: 'bar' }}, {term: { moo: 'bam' }} ],
should: [ {term: { xoo: 'bax' }}, {term: { zoo: 'baz' }} ]
})
end
end
end
end

describe '#must' do

before do
search.must { term foo: 'bar' }
end

it 'applies the condition' do
expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' }} ] })
end

context 'when the method is called more than once' do

before do
search.must { term foo: 'bar' }
search.must { term moo: 'bam' }
end

it 'applies the conditions' do
expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' } }, { term: { moo: 'bam' } } ] })
end
end
end

describe '#should' do

before do
search.should { term xoo: 'bax' }
end

it 'applies the condition' do
expect(search.to_hash).to eq(bool: { should: [ {term: { xoo: 'bax' }} ] })
end
end

context 'when methods are chained' do

before do
search.must { term foo: 'bar' }
search.must { term foo: 'baz' }.must { term moo: 'bam' }
search.must_not { term foo: 'biz' }
search.should { term foo: 'bor' }
end

it 'applies all the conditions' do
expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }, { term: { foo: 'baz' } },
{ term: { moo: 'bam' } }],
must_not: [{ term: { foo: 'biz' } }],
should: [{ term: { foo: 'bor' } }] })
end
end
end
49 changes: 49 additions & 0 deletions elasticsearch-dsl/spec/filters/exists_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Filters::Exists do

let(:search) do
described_class.new
end

describe '#to_hash' do

it 'can be converted to a hash' do
expect(search.to_hash).to eq(exists: {})
end
end

context 'when options methods are called' do

let(:search) do
described_class.new(:foo)
end

describe '#field' do

before do
search.field('bar')
end

it 'applies the option' do
expect(search.to_hash[:exists][:foo][:field]).to eq('bar')
end
end
end

describe '#initialize' do

context 'when a block is provided' do

let(:search) do
described_class.new do
field 'bar'
end
end

it 'executes the block' do
expect(search.to_hash).to eq(exists: { field: 'bar' })
end
end
end
end
127 changes: 127 additions & 0 deletions elasticsearch-dsl/spec/filters/geo_bounding_box_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Filters::GeoBoundingBox do

describe '#to_hash' do

let(:search) do
described_class.new
end

it 'can be converted to a hash' do
expect(search.to_hash).to eq(geo_bounding_box: {})
end
end

context 'when options methods are called' do

let(:search) do
described_class.new
end

describe '#top_left' do

before do
search.top_left('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:top_left]).to eq('bar')
end
end

describe '#bottom_right' do

before do
search.bottom_right('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:bottom_right]).to eq('bar')
end
end

describe '#top_right' do

before do
search.top_right('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:top_right]).to eq('bar')
end
end

describe '#bottom_left' do

before do
search.bottom_left('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:bottom_left]).to eq('bar')
end
end

describe '#top' do

before do
search.top('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:top]).to eq('bar')
end
end

describe '#left' do

before do
search.left('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:left]).to eq('bar')
end
end

describe '#bottom' do

before do
search.bottom('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:bottom]).to eq('bar')
end
end

describe '#right' do

before do
search.right('bar')
end

it 'applies the option' do
expect(search.to_hash[:geo_bounding_box][:right]).to eq('bar')
end
end
end

describe '#initialize' do

context 'when a block is provided' do

let(:search) do
described_class.new do
top_left [0,1]
bottom_right [3,2]
end
end

it 'executes the block' do
expect(search.to_hash).to eq(geo_bounding_box: { top_left: [0,1], bottom_right: [3,2] })
end
end
end
end
Loading