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
22 changes: 11 additions & 11 deletions elasticsearch-dsl/spec/filters/bool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
context 'when a hash is provided' do

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

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

Expand All @@ -35,7 +35,7 @@
end

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

context 'when the block calls multiple methods' do
Expand All @@ -50,9 +50,9 @@

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' }} ]
{ must: [ { term: { foo: 'bar' } } ],
must_not: [ { term: { moo: 'bam' } } ],
should: [ { term: { xoo: 'bax' } } ]
})
end
end
Expand All @@ -71,8 +71,8 @@

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' }} ]
{ must: [ { term: { foo: 'bar' } }, { term: { moo: 'bam' } } ],
should: [ { term: { xoo: 'bax' } }, { term: { zoo: 'baz' } } ]
})
end
end
Expand All @@ -86,7 +86,7 @@
end

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

context 'when the method is called more than once' do
Expand All @@ -97,7 +97,7 @@
end

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

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

Expand Down
142 changes: 142 additions & 0 deletions elasticsearch-dsl/spec/queries/bool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Queries::Bool 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(bool: {})
end
end

describe '#initialize' do

context 'when a block is provided' do

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

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

context 'when multiple option methods are called' do

let(:search) do
described_class.new do
should { term tag: 'wow' }
should { term tag: 'elasticsearch' }

minimum_should_match 1
boost 1.0
end
end

it 'defines all the options' do
expect(search.to_hash).to eq(bool: {
minimum_should_match: 1,
boost: 1.0,
should: [ {term: { tag: 'wow' }}, {term: { tag: 'elasticsearch' }} ]})
end
end

context 'when multiple conditions are provided' do

let(:search) do
described_class.new do
must do
match foo: 'bar'
end

must do
match moo: 'bam'
end

should do
match xoo: 'bax'
end

should do
match zoo: 'baz'
end
end
end

it 'applies each condition' do
expect(search.to_hash).to eq(bool:
{ must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ],
should: [ {match: { xoo: 'bax' }}, {match: { zoo: 'baz' }} ]
})
end

context 'when #to_hash is called more than once' do

it 'does not alter the hash' do
expect(search.to_hash).to eq(search.to_hash)
end
end
end
end
end

context 'when options methods are called' do

let(:search) do
described_class.new
end

before do
search.must { match foo: 'bar' }
search.must { match moo: 'bam' }
search.should { match xoo: 'bax' }
end

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

context 'when the filter method is called multiple times' do

let(:search) do
described_class.new
end

before do
search.filter { term foo: 'bar' }
search.filter { term zoo: 'baz' }
end

it 'combines the filer clauses' do
expect(search.to_hash).to eq(bool:
{ filter: [
{ term: { foo: "bar"}},
{ term: { zoo: "baz"}}
] })
end
end

context 'when methods are chained' do

let(:search) do
described_class.new
end

before do
search.must { match foo: 'bar' }.must { match moo: 'bam' }.should { match xoo: 'bax' }
end

it 'applies the option' do
expect(search.to_hash).to eq(bool: { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ],
should: [ {match: { xoo: 'bax' }} ] })
end
end
end
73 changes: 73 additions & 0 deletions elasticsearch-dsl/spec/queries/boosting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'spec_helper'

describe Elasticsearch::DSL::Search::Queries::Boosting 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(boosting: {})
end
end

context 'when options methods are called' do

let(:search) do
described_class.new
end

describe '#positive' do

before do
search.positive('bar')
end

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

describe '#negative' do

before do
search.negative('bar')
end

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

describe '#negative_boost' do

before do
search.negative_boost('bar')
end

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

describe '#initialize' do

context 'when a block is provided' do

let(:search) do
described_class.new do
positive foo: 'bar'
negative moo: 'xoo'
end
end

it 'executes the block' do
expect(search.to_hash[:boosting][:positive][:foo]).to eq('bar')
expect(search.to_hash[:boosting][:negative][:moo]).to eq('xoo')
end
end
end
end
Loading