diff --git a/elasticsearch-dsl/spec/filters/bool_spec.rb b/elasticsearch-dsl/spec/filters/bool_spec.rb index d2504af10a..fb7f0691d0 100644 --- a/elasticsearch-dsl/spec/filters/bool_spec.rb +++ b/elasticsearch-dsl/spec/filters/bool_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/elasticsearch-dsl/spec/queries/bool_spec.rb b/elasticsearch-dsl/spec/queries/bool_spec.rb new file mode 100644 index 0000000000..cfcb6b8df0 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/bool_spec.rb @@ -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 diff --git a/elasticsearch-dsl/spec/queries/boosting_spec.rb b/elasticsearch-dsl/spec/queries/boosting_spec.rb new file mode 100644 index 0000000000..6ab5edff88 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/boosting_spec.rb @@ -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 diff --git a/elasticsearch-dsl/spec/queries/common_spec.rb b/elasticsearch-dsl/spec/queries/common_spec.rb new file mode 100644 index 0000000000..d4a0ce6ee1 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/common_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Common 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(common: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:query]).to eq('bar') + end + end + + describe '#cutoff_frequency' do + + before do + search.cutoff_frequency('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:cutoff_frequency]).to eq('bar') + end + end + + describe '#low_freq_operator' do + + before do + search.low_freq_operator('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:low_freq_operator]).to eq('bar') + end + end + + describe '#minimum_should_match' do + + before do + search.minimum_should_match('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:minimum_should_match]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:boost]).to eq('bar') + end + end + + describe '#analyzer' do + + before do + search.analyzer('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:analyzer]).to eq('bar') + end + end + + describe '#disable_coord' do + + before do + search.disable_coord('bar') + end + + it 'applies the option' do + expect(search.to_hash[:common][:disable_coord]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:common][:query]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/constant_score_spec.rb b/elasticsearch-dsl/spec/queries/constant_score_spec.rb new file mode 100644 index 0000000000..e3e386458b --- /dev/null +++ b/elasticsearch-dsl/spec/queries/constant_score_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::ConstantScore 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(constant_score: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:constant_score][:query]).to eq('bar') + end + end + + describe '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:constant_score][:filter]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:constant_score][:boost]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query do + term foo: 'bar' + end + end + end + + it 'executes the block' do + expect(search.to_hash[:constant_score][:query][:term][:foo]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/dis_max_spec.rb b/elasticsearch-dsl/spec/queries/dis_max_spec.rb new file mode 100644 index 0000000000..837bf33e46 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/dis_max_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::DisMax 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(dis_max: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#tie_breaker' do + + before do + search.tie_breaker('bar') + end + + it 'applies the option' do + expect(search.to_hash[:dis_max][:tie_breaker]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:dis_max][:boost]).to eq('bar') + end + end + + describe '#queries' do + + before do + search.queries('bar') + end + + it 'applies the option' do + expect(search.to_hash[:dis_max][:queries]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + tie_breaker 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:dis_max][:tie_breaker]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/exists_spec.rb b/elasticsearch-dsl/spec/queries/exists_spec.rb new file mode 100644 index 0000000000..e86c715e4a --- /dev/null +++ b/elasticsearch-dsl/spec/queries/exists_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Exists 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(exists: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#field' do + + before do + search.field('bar') + end + + it 'applies the option' do + expect(search.to_hash[:exists][: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[:exists][:field]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/filtered_spec.rb b/elasticsearch-dsl/spec/queries/filtered_spec.rb new file mode 100644 index 0000000000..431059f668 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/filtered_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Filtered 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(filtered: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:filtered][:query]).to eq('bar') + end + end + + describe '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:filtered][:filter]).to eq('bar') + end + end + + describe '#strategy' do + + before do + search.strategy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:filtered][:strategy]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query do + match foo: 'BLAM' + end + filter do + term bar: 'slam' + end + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(filtered: { query: { match: { foo: 'BLAM' } }, filter: { term: { bar: 'slam' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/function_score_spec.rb b/elasticsearch-dsl/spec/queries/function_score_spec.rb new file mode 100644 index 0000000000..2ea7408b8f --- /dev/null +++ b/elasticsearch-dsl/spec/queries/function_score_spec.rb @@ -0,0 +1,147 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::FunctionScore 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(function_score: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:query]).to eq('bar') + end + end + + describe '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:filter]).to eq('bar') + end + end + + describe '#functions' do + + before do + search.functions('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:functions]).to eq('bar') + end + + context 'when the option is called as a setter' do + + before do + search.functions = [ {foo: { abc: '123' }} ] + end + + it 'applies the option' do + expect(search.to_hash).to eq(function_score: { functions: [ {foo: { abc: '123' }} ] }) + end + end + end + + describe '#script_score' do + + before do + search.script_score('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:script_score]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:boost]).to eq('bar') + end + end + + describe '#max_boost' do + + before do + search.max_boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:max_boost]).to eq('bar') + end + end + + describe '#score_mode' do + + before do + search.score_mode('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:score_mode]).to eq('bar') + end + end + + describe '#boost_mode' do + + before do + search.boost_mode('bar') + end + + it 'applies the option' do + expect(search.to_hash[:function_score][:boost_mode]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query do + match foo: 'BLAM' + end + filter do + term bar: 'slam' + end + functions << { foo: { abc: '123' } } + functions << { foo: { xyz: '456' } } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(function_score: { + query: { match: { foo: 'BLAM' } }, + filter: { term: { bar: 'slam' } }, + functions: [ { foo: { abc: '123' } }, { foo: { xyz: '456' } } ] }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/fuzzy_like_this_field_spec.rb b/elasticsearch-dsl/spec/queries/fuzzy_like_this_field_spec.rb new file mode 100644 index 0000000000..77fa475c64 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/fuzzy_like_this_field_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::FuzzyLikeThisField 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(fuzzy_like_this_field: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#like_text' do + + before do + search.like_text('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:like_text]).to eq('bar') + end + end + + describe '#fuzziness' do + + before do + search.fuzziness('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:fuzziness]).to eq('bar') + end + end + + describe '#analyzer' do + + before do + search.analyzer('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:analyzer]).to eq('bar') + end + end + + describe '#max_query_terms' do + + before do + search.max_query_terms('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:max_query_terms]).to eq('bar') + end + end + + describe '#prefix_length' do + + before do + search.prefix_length('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:prefix_length]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:boost]).to eq('bar') + end + end + + describe '#ignore_tf' do + + before do + search.ignore_tf('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this_field][:ignore_tf]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + like_text 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:fuzzy_like_this_field][:like_text]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/fuzzy_like_this_spec.rb b/elasticsearch-dsl/spec/queries/fuzzy_like_this_spec.rb new file mode 100644 index 0000000000..9f8bea9ce9 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/fuzzy_like_this_spec.rb @@ -0,0 +1,117 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::FuzzyLikeThis 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(fuzzy_like_this: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#fields' do + + before do + search.fields('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:fields]).to eq('bar') + end + end + + describe '#like_text' do + + before do + search.like_text('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:like_text]).to eq('bar') + end + end + + describe '#fuzziness' do + + before do + search.fuzziness('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:fuzziness]).to eq('bar') + end + end + + describe '#analyzer' do + + before do + search.analyzer('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:analyzer]).to eq('bar') + end + end + + describe '#max_query_terms' do + + before do + search.max_query_terms('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:max_query_terms]).to eq('bar') + end + end + + describe '#prefix_length' do + + before do + search.prefix_length('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:prefix_length]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy_like_this][:boost]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + fields ['foo'] + like_text 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:fuzzy_like_this][:like_text]).to eq('bar') + expect(search.to_hash[:fuzzy_like_this][:fields]).to eq(['foo']) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/fuzzy_spec.rb b/elasticsearch-dsl/spec/queries/fuzzy_spec.rb new file mode 100644 index 0000000000..b66fefbac8 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/fuzzy_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Fuzzy 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(fuzzy: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#value' do + + before do + search.value('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy][:value]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy][:boost]).to eq('bar') + end + end + + describe '#fuzziness' do + + before do + search.fuzziness('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy][:fuzziness]).to eq('bar') + end + end + + describe '#prefix_length' do + + before do + search.prefix_length('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy][:prefix_length]).to eq('bar') + end + end + + describe '#max_expansions' do + + before do + search.max_expansions('bar') + end + + it 'applies the option' do + expect(search.to_hash[:fuzzy][:max_expansions]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + value 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:fuzzy][:value]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/geo_shape_spec.rb b/elasticsearch-dsl/spec/queries/geo_shape_spec.rb new file mode 100644 index 0000000000..001bc2b4bf --- /dev/null +++ b/elasticsearch-dsl/spec/queries/geo_shape_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::GeoShape 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_shape: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#shape' do + + before do + search.shape('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_shape][:shape]).to eq('bar') + end + end + + describe '#indexed_shape' do + + before do + search.indexed_shape('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_shape][:indexed_shape]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + shape 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:geo_shape][:foo][:shape]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/has_child_spec.rb b/elasticsearch-dsl/spec/queries/has_child_spec.rb new file mode 100644 index 0000000000..87447fc024 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/has_child_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::HasChild 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(has_child: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#type' do + + before do + search.type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:type]).to eq('bar') + end + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:query]).to eq('bar') + end + end + + describe '#score_mode' do + + before do + search.score_mode('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:score_mode]).to eq('bar') + end + end + + describe '#min_children' do + + before do + search.min_children('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:min_children]).to eq('bar') + end + end + + describe '#max_children' do + + before do + search.max_children('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:max_children]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + type 'bar' + query do + match :foo do + query 'bar' + end + end + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(has_child: { type: 'bar', query: { match: { foo: { query: 'bar'} } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/has_parent_spec.rb b/elasticsearch-dsl/spec/queries/has_parent_spec.rb new file mode 100644 index 0000000000..becc735fb3 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/has_parent_spec.rb @@ -0,0 +1,72 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::HasParent 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(has_parent: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#parent_type' do + + before do + search.parent_type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_parent][:parent_type]).to eq('bar') + end + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_parent][:query]).to eq('bar') + end + end + + describe '#score_mode' do + + before do + search.score_mode('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_parent][:score_mode]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + parent_type 'bar' + query match: { foo: 'bar' } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(has_parent: { parent_type: 'bar', query: { match: { foo: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/ids_spec.rb b/elasticsearch-dsl/spec/queries/ids_spec.rb new file mode 100644 index 0000000000..26a6ef170c --- /dev/null +++ b/elasticsearch-dsl/spec/queries/ids_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Ids 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(ids: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#type' do + + before do + search.type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:ids][:type]).to eq('bar') + end + end + + describe '#values' do + + before do + search.values('bar') + end + + it 'applies the option' do + expect(search.to_hash[:ids][:values]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + type 'bar' + values [1, 2, 3] + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(ids: { type: 'bar', values: [1, 2, 3] }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/indices_spec.rb b/elasticsearch-dsl/spec/queries/indices_spec.rb new file mode 100644 index 0000000000..58c8df00b4 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/indices_spec.rb @@ -0,0 +1,72 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Indices 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(indices: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#indices' do + + before do + search.indices('bar') + end + + it 'applies the option' do + expect(search.to_hash[:indices][:indices]).to eq('bar') + end + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:indices][:query]).to eq('bar') + end + end + + describe '#no_match_query' do + + before do + search.no_match_query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:indices][:no_match_query]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + indices 'bar' + query term: { foo: 'bar' } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(indices: { indices: 'bar', query: { term: { foo: 'bar' } } } ) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/mach_spec.rb b/elasticsearch-dsl/spec/queries/mach_spec.rb new file mode 100644 index 0000000000..a6c43c66f8 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/mach_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Match 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(match: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:match][:query]).to eq('bar') + end + end + + describe '#operator' do + + before do + search.operator('standard') + end + + it 'applies the option' do + expect(search.to_hash[:match][:operator]).to eq('standard') + end + end + + describe '#type' do + + before do + search.type(10) + end + + it 'applies the option' do + expect(search.to_hash[:match][:type]).to eq(10) + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(message: { query: 'test' }) + end + + it 'sets the value' do + expect(search.to_hash).to eq(match: { message: { query: 'test' } }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'test' + operator 'and' + type 'phrase_prefix' + boost 2 + fuzziness 'AUTO' + end + end + + it 'executes the block' do + expect(search.to_hash[:match][:query]).to eq('test') + expect(search.to_hash[:match][:operator]).to eq('and') + expect(search.to_hash[:match][:type]).to eq('phrase_prefix') + expect(search.to_hash[:match][:boost]).to eq(2) + expect(search.to_hash[:match][:fuzziness]).to eq('AUTO') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/match_all_spec.rb b/elasticsearch-dsl/spec/queries/match_all_spec.rb new file mode 100644 index 0000000000..5329345f4f --- /dev/null +++ b/elasticsearch-dsl/spec/queries/match_all_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::MatchAll 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(match_all: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#boost' do + + before do + search.boost('bar') + end + + it 'applies the option' do + expect(search.to_hash[:match_all][:boost]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + boost 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(match_all: { boost: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/match_phrase_prefix_spec.rb b/elasticsearch-dsl/spec/queries/match_phrase_prefix_spec.rb new file mode 100644 index 0000000000..47078b6359 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/match_phrase_prefix_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::MatchPhrasePrefix 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(match_phrase_prefix: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase_prefix][:query]).to eq('bar') + end + end + + describe '#boost' do + + before do + search.boost(10) + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase_prefix][:boost]).to eq(10) + end + end + + describe '#max_expansions' do + + before do + search.max_expansions(2) + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase_prefix][:max_expansions]).to eq(2) + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(message: 'test') + end + + it 'sets the value' do + expect(search.to_hash).to eq(match_phrase_prefix: { message: 'test' }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'test' + boost 2 + max_expansions 1 + end + end + + it 'executes the block' do + expect(search.to_hash[:match_phrase_prefix][:query]).to eq('test') + expect(search.to_hash[:match_phrase_prefix][:boost]).to eq(2) + expect(search.to_hash[:match_phrase_prefix][:max_expansions]).to eq(1) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/match_phrase_spec.rb b/elasticsearch-dsl/spec/queries/match_phrase_spec.rb new file mode 100644 index 0000000000..655e752cab --- /dev/null +++ b/elasticsearch-dsl/spec/queries/match_phrase_spec.rb @@ -0,0 +1,97 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::MatchPhrase 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(match_phrase: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase][:query]).to eq('bar') + end + end + + describe '#analyzer' do + + before do + search.analyzer('standard') + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase][:analyzer]).to eq('standard') + end + end + + describe '#boost' do + + before do + search.boost(10) + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase][:boost]).to eq(10) + end + end + + describe '#slop' do + + before do + search.slop(1) + end + + it 'applies the option' do + expect(search.to_hash[:match_phrase][:slop]).to eq(1) + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(message: { query: 'test' }) + end + + it 'sets the value' do + expect(search.to_hash).to eq(match_phrase: { message: { query: 'test' } }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'test' + slop 1 + boost 2 + end + end + + it 'executes the block' do + expect(search.to_hash[:match_phrase][:query]).to eq('test') + expect(search.to_hash[:match_phrase][:boost]).to eq(2) + expect(search.to_hash[:match_phrase][:slop]).to eq(1) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/more_like_this_spec.rb b/elasticsearch-dsl/spec/queries/more_like_this_spec.rb new file mode 100644 index 0000000000..5dd627f585 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/more_like_this_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::MoreLikeThis 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(more_like_this: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'fields', + 'like_text', + 'min_term_freq', + 'max_query_terms', + 'docs', + 'ids', + 'include', + 'exclude', + 'percent_terms_to_match', + 'stop_words', + 'min_doc_freq', + 'max_doc_freq', + 'min_word_length', + 'max_word_length', + 'boost_terms', + 'boost', + 'analyzer' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:more_like_this][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + fields ['foo', 'bar'] + like_text 'abc' + end + end + + it 'executes the block' do + expect(search.to_hash[:more_like_this][:fields]).to eq(['foo', 'bar']) + expect(search.to_hash[:more_like_this][:like_text]).to eq('abc') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/multi_match_spec.rb b/elasticsearch-dsl/spec/queries/multi_match_spec.rb new file mode 100644 index 0000000000..44ea9c9917 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/multi_match_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::MultiMatch 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(multi_match: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'query', + 'fields', + 'type', + 'use_dis_max' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:multi_match][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'bar' + fields ['a', 'b'] + end + end + + it 'executes the block' do + expect(search.to_hash[:multi_match][:fields]).to eq(['a', 'b']) + expect(search.to_hash[:multi_match][:query]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/nested_spec.rb b/elasticsearch-dsl/spec/queries/nested_spec.rb new file mode 100644 index 0000000000..e6ec4a695b --- /dev/null +++ b/elasticsearch-dsl/spec/queries/nested_spec.rb @@ -0,0 +1,81 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Nested 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(nested: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'path', + 'score_mode', + 'score_mode', + 'query' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:nested][option.to_sym]).to eq('bar') + end + end + + describe '#inner_hits' do + + before do + search.inner_hits(size: 1) + end + + it 'applies the option' do + expect(search.to_hash[:nested][:inner_hits]).to eq(size: 1) + end + end + + describe '#query' do + + before do + search.query(match: { foo: 'bar' }) + end + + it 'applies the option' do + expect(search.to_hash[:nested][:query]).to eq(match: { foo: 'bar' }) + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + path 'bar' + query do + match foo: 'bar' + end + end + end + + it 'executes the block' do + expect(search.to_hash[:nested][:path]).to eq('bar') + expect(search.to_hash[:nested][:query]).to eq(match: { foo: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/prefix_spec.rb b/elasticsearch-dsl/spec/queries/prefix_spec.rb new file mode 100644 index 0000000000..48cbdb3317 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/prefix_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Prefix 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(prefix: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'value', + 'boost'].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:prefix][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + value 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:prefix][:value]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/query_string_spec.rb b/elasticsearch-dsl/spec/queries/query_string_spec.rb new file mode 100644 index 0000000000..0d7dd89306 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/query_string_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::QueryString 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(query_string: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'query', + 'fields', + 'default_field', + 'default_operator', + 'allow_leading_wildcard', + 'lowercase_expanded_terms', + 'enable_position_increments', + 'fuzzy_max_expansions', + 'fuzziness', + 'fuzzy_prefix_length', + 'phrase_slop', + 'boost', + 'analyze_wildcard', + 'auto_generate_phrase_queries', + 'minimum_should_match', + 'lenient', + 'locale', + 'use_dis_max', + 'tie_breaker', + 'time_zone'].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:query_string][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'foo AND bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:query_string][:query]).to eq('foo AND bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/range_spec.rb b/elasticsearch-dsl/spec/queries/range_spec.rb new file mode 100644 index 0000000000..b3001f3574 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/range_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Range 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(range: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'gte', + 'lte', + 'boost', + 'format'].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:range][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + gte 10 + lte 20 + boost 2 + format 'mm/dd/yyyy' + end + end + + it 'executes the block' do + expect(search.to_hash[:range][:gte]).to eq(10) + expect(search.to_hash[:range][:lte]).to eq(20) + expect(search.to_hash[:range][:boost]).to eq(2) + expect(search.to_hash[:range][:format]).to eq('mm/dd/yyyy') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/regexp_spec.rb b/elasticsearch-dsl/spec/queries/regexp_spec.rb new file mode 100644 index 0000000000..4e313a661e --- /dev/null +++ b/elasticsearch-dsl/spec/queries/regexp_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Regexp 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(regexp: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'value', + 'boost', + 'flags'].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:regexp][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: 'b.*r') + end + + it 'sets the value' do + expect(search.to_hash[:regexp][:foo]).to eq('b.*r') + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + value 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:regexp][:foo][:value]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/simple_query_string_spec.rb b/elasticsearch-dsl/spec/queries/simple_query_string_spec.rb new file mode 100644 index 0000000000..e3be89503b --- /dev/null +++ b/elasticsearch-dsl/spec/queries/simple_query_string_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SimpleQueryString 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(simple_query_string: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'query', + 'fields', + 'default_operator', + 'analyzer', + 'flags', + 'lenient'].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:simple_query_string][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + query 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:simple_query_string][:foo][:query]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_first_spec.rb b/elasticsearch-dsl/spec/queries/span_first_spec.rb new file mode 100644 index 0000000000..0fecabdd9c --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_first_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanFirst 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(span_first: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'match' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:span_first][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + match 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:span_first][:match]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_multi_spec.rb b/elasticsearch-dsl/spec/queries/span_multi_spec.rb new file mode 100644 index 0000000000..0df318ee30 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_multi_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanMulti 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(span_multi: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'match' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:span_multi][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + match 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:span_multi][:match]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_near_spec.rb b/elasticsearch-dsl/spec/queries/span_near_spec.rb new file mode 100644 index 0000000000..805ab19bea --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_near_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanNear 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(span_near: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'span_near', + 'slop', + 'in_order', + 'collect_payloads' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:span_near][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + span_near 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:span_near][:span_near]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_not_spec.rb b/elasticsearch-dsl/spec/queries/span_not_spec.rb new file mode 100644 index 0000000000..1e7d1ef8aa --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_not_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanNot 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(span_not: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'include', + 'exclude', + 'pre', + 'post', + 'dist' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:span_not][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + include 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:span_not][:include]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_or_spec.rb b/elasticsearch-dsl/spec/queries/span_or_spec.rb new file mode 100644 index 0000000000..14feeab3cd --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_or_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanOr 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(span_or: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'clauses' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:span_or][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + clauses 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:span_or][:clauses]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/span_term_spec.rb b/elasticsearch-dsl/spec/queries/span_term_spec.rb new file mode 100644 index 0000000000..fd4f2251dc --- /dev/null +++ b/elasticsearch-dsl/spec/queries/span_term_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::SpanTerm 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(span_term: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: 'bar') + end + + it 'sets the value' do + expect(search.to_hash[:span_term][:foo]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/template_spec.rb b/elasticsearch-dsl/spec/queries/template_spec.rb new file mode 100644 index 0000000000..e7dae7990b --- /dev/null +++ b/elasticsearch-dsl/spec/queries/template_spec.rb @@ -0,0 +1,67 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Template 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(template: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'query', + 'params' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:template][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(query: 'bar', params: { foo: 'abc' }) + end + + it 'sets the value' do + expect(search.to_hash[:template][:query]).to eq('bar') + expect(search.to_hash[:template][:params][:foo]).to eq('abc') + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + query 'bar' + params foo: 'abc' + end + end + + it 'executes the block' do + expect(search.to_hash[:template][:query]).to eq('bar') + expect(search.to_hash[:template][:params][:foo]).to eq('abc') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/term_spec.rb b/elasticsearch-dsl/spec/queries/term_spec.rb new file mode 100644 index 0000000000..e56707759f --- /dev/null +++ b/elasticsearch-dsl/spec/queries/term_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Term 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(term: {}) + end + end + + describe '#initialize' do + + context 'when a String is provided' do + + let(:search) do + described_class.new(message: 'test') + end + + it 'executes the block' do + expect(search.to_hash[:term][:message]).to eq('test') + end + end + + context 'when a hash is provided' do + + let(:search) do + described_class.new(message: { query: 'test', boost: 2 }) + end + + it 'sets the value' do + expect(search.to_hash[:term][:message]).to eq(query: 'test', boost: 2) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/terms_spec.rb b/elasticsearch-dsl/spec/queries/terms_spec.rb new file mode 100644 index 0000000000..09a5544adf --- /dev/null +++ b/elasticsearch-dsl/spec/queries/terms_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Terms 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(terms: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: ['abc', 'xyz']) + end + + it 'sets the value' do + expect(search.to_hash[:terms]).to eq(foo: ['abc', 'xyz']) + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/top_children_spec.rb b/elasticsearch-dsl/spec/queries/top_children_spec.rb new file mode 100644 index 0000000000..a65b00d0e5 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/top_children_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::TopChildren 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(top_children: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'type', + 'query', + 'score', + 'factor', + 'incremental_factor', + '_scope' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:top_children][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + type 'bar' + query 'foo' + end + end + + it 'executes the block' do + expect(search.to_hash[:top_children][:type]).to eq('bar') + expect(search.to_hash[:top_children][:query]).to eq('foo') + end + end + + context 'when nested blocks are provided' do + + let(:search) do + described_class.new do + type 'bar' + query do + match foo: 'BLAM' + end + end + end + + it 'executes the block' do + expect(search.to_hash[:top_children][:type]).to eq('bar') + expect(search.to_hash[:top_children][:query][:match][:foo]).to eq('BLAM') + end + end + end +end diff --git a/elasticsearch-dsl/spec/queries/wildcard_spec.rb b/elasticsearch-dsl/spec/queries/wildcard_spec.rb new file mode 100644 index 0000000000..6be4057040 --- /dev/null +++ b/elasticsearch-dsl/spec/queries/wildcard_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Queries::Wildcard 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(wildcard: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + [ 'value', + 'boost' ].each do |option| + + describe "##{option}" do + + before do + search.send(option, 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:wildcard][option.to_sym]).to eq('bar') + end + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: 'bar') + end + + it 'sets the value' do + expect(search.to_hash[:wildcard][:foo]).to eq('bar') + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + value 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash[:wildcard][:value]).to eq('bar') + end + end + end +end diff --git a/elasticsearch-dsl/test/unit/queries/bool_test.rb b/elasticsearch-dsl/test/unit/queries/bool_test.rb deleted file mode 100644 index 9ffe055702..0000000000 --- a/elasticsearch-dsl/test/unit/queries/bool_test.rb +++ /dev/null @@ -1,147 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class BoolTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Bool Query" do - subject { Bool.new } - - should "be converted to a Hash" do - assert_equal({ bool: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Bool.new must: [ {match: { foo: 'bar' }} ] - - assert_equal( { bool: { must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash ) - end - - should "take a block" do - subject = Bool.new do - must { match foo: 'bar' } - end - - assert_equal( { bool: {must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash ) - end - - should "have option methods" do - subject = Bool.new do - should { term tag: 'wow' } - should { term tag: 'elasticsearch' } - - minimum_should_match 1 - boost 1.0 - end - - assert_equal( { bool: - { - minimum_should_match: 1, - boost: 1.0, - should: [ {term: { tag: 'wow' }}, {term: { tag: 'elasticsearch' }} ] - } - }, - subject.to_hash ) - end - - should "take a block with multiple methods" do - subject = Bool.new do - must { match foo: 'bar' } - must_not { match moo: 'bam' } - should { match xoo: 'bax' } - filter { term zoo: 'baz'} - end - - assert_equal( { bool: - { must: [ {match: { foo: 'bar' }} ], - must_not: [ {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }} ], - filter: [ {term: { zoo: 'baz' }}] - } - }, - subject.to_hash ) - end - - should "take a block with multiple conditions" do - subject = Bool.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 - - # Make sure we're not additive - subject.to_hash - subject.to_hash - - assert_equal( { bool: - { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }}, {match: { zoo: 'baz' }} ] - } - }, - subject.to_hash ) - end - - should "take method calls" do - subject = Bool.new - - subject.must { match foo: 'bar' } - assert_equal( { bool: { must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash ) - - subject.must { match moo: 'bam' } - assert_equal( { bool: { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ]} }, - subject.to_hash ) - - subject.should { match xoo: 'bax' } - assert_equal( { bool: - { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }} ] } - }, - subject.to_hash ) - end - - should "combine chained filters" do - subject = Bool.new - subject. - filter { - term foo: "bar" - } - subject.filter { - term zoo: "baz" - } - - assert_equal( { bool: - { filter: [ - { term: { foo: "bar"}}, - { term: { zoo: "baz"}} - ] } - }, - subject.to_hash) - end - - should "be chainable" do - subject = Bool.new - - assert_instance_of Bool, subject.must { match foo: 'bar' } - assert_instance_of Bool, subject.must { match foo: 'bar' }.must { match moo: 'bam' } - assert_instance_of Bool, subject.must_not { match foo: 'bar' } - assert_instance_of Bool, subject.should { match foo: 'bar' } - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/boosting_test.rb b/elasticsearch-dsl/test/unit/queries/boosting_test.rb deleted file mode 100644 index c47f70b1e4..0000000000 --- a/elasticsearch-dsl/test/unit/queries/boosting_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class BoostingTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Boosting query" do - subject { Boosting.new } - - should "be converted to a Hash" do - assert_equal({ boosting: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Boosting.new - - subject.positive 'bar' - subject.negative 'bar' - subject.negative_boost 'bar' - - assert_equal %w[ negative negative_boost positive ], - subject.to_hash[:boosting].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:boosting][:positive] - end - - should "take a block" do - subject = Boosting.new do - positive foo: 'bar' - negative moo: 'xoo' - end - - assert_equal 'bar', subject.to_hash[:boosting][:positive][:foo] - assert_equal 'xoo', subject.to_hash[:boosting][:negative][:moo] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/common_test.rb b/elasticsearch-dsl/test/unit/queries/common_test.rb deleted file mode 100644 index c79ba46293..0000000000 --- a/elasticsearch-dsl/test/unit/queries/common_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class CommonTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Common query" do - subject { Common.new } - - should "be converted to a Hash" do - assert_equal({ common: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Common.new :foo - - subject.query 'bar' - subject.cutoff_frequency 'bar' - subject.low_freq_operator 'bar' - subject.minimum_should_match 'bar' - subject.boost 'bar' - subject.analyzer 'bar' - subject.disable_coord 'bar' - - assert_equal %w[ analyzer boost cutoff_frequency disable_coord low_freq_operator minimum_should_match query ], - subject.to_hash[:common][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:common][:foo][:query] - end - - should "take a block" do - subject = Common.new :foo do - query 'bar' - end - assert_equal 'bar', subject.to_hash[:common][:foo][:query] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/constant_score_test.rb b/elasticsearch-dsl/test/unit/queries/constant_score_test.rb deleted file mode 100644 index d828c71a6c..0000000000 --- a/elasticsearch-dsl/test/unit/queries/constant_score_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class ConstantScoreTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "ConstantScore query" do - subject { ConstantScore.new } - - should "be converted to a Hash" do - assert_equal({ constant_score: {} }, subject.to_hash) - end - - should "have option methods" do - subject = ConstantScore.new - - subject.query 'bar' - subject.filter 'bar' - subject.boost 'bar' - - assert_equal %w[ boost filter query ], - subject.to_hash[:constant_score].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:constant_score][:query] - end - - should "take a block" do - subject = ConstantScore.new do - query term: { foo: 'bar' } - end - assert_equal 'bar', subject.to_hash[:constant_score][:query][:term][:foo] - end - - should "evaluate a block passed to the option method" do - subject = ConstantScore.new do - query do - term foo: 'bar' - end - end - assert_equal 'bar', subject.to_hash[:constant_score][:query][:term][:foo] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/dis_max_test.rb b/elasticsearch-dsl/test/unit/queries/dis_max_test.rb deleted file mode 100644 index 8d14c2e3b5..0000000000 --- a/elasticsearch-dsl/test/unit/queries/dis_max_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class DisMaxTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "DisMax query" do - subject { DisMax.new } - - should "be converted to a Hash" do - assert_equal({ dis_max: {} }, subject.to_hash) - end - - should "have option methods" do - subject = DisMax.new - - subject.tie_breaker 'bar' - subject.boost 'bar' - subject.queries 'bar' - - assert_equal %w[ boost queries tie_breaker ], - subject.to_hash[:dis_max].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:dis_max][:tie_breaker] - end - - should "take a block" do - subject = DisMax.new do - tie_breaker 'bar' - end - assert_equal 'bar', subject.to_hash[:dis_max][:tie_breaker] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/exists_test.rb b/elasticsearch-dsl/test/unit/queries/exists_test.rb deleted file mode 100644 index 2b1df2def3..0000000000 --- a/elasticsearch-dsl/test/unit/queries/exists_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class ExistsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Exists query" do - subject { Exists.new } - - should "be converted to a Hash" do - assert_equal({ exists: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Exists.new - - subject.field 'bar' - - assert_equal %w[ field ], - subject.to_hash[:exists].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:exists][:field] - end - - should "take a block" do - subject = Exists.new do - field 'bar' - end - assert_equal({ exists: { field: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/filtered_test.rb b/elasticsearch-dsl/test/unit/queries/filtered_test.rb deleted file mode 100644 index e6d8ecbf6b..0000000000 --- a/elasticsearch-dsl/test/unit/queries/filtered_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class FilteredTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Filtered query" do - subject { Filtered.new } - - should "be converted to a Hash" do - assert_equal({ filtered: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Filtered.new - - subject.query 'bar' - subject.filter 'bar' - subject.strategy 'bar' - - assert_equal %w[ filter query strategy ], - subject.to_hash[:filtered].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:filtered][:query] - end - - should "take a block" do - subject = Filtered.new do - query 'bar' - end - assert_equal 'bar', subject.to_hash[:filtered][:query] - end - - should "evaluate a block passed to the option method" do - subject = Filtered.new do - query do - match foo: 'BLAM' - end - filter do - term bar: 'slam' - end - end - - assert_equal({filtered: { query: { match: { foo: 'BLAM' } }, filter: { term: { bar: 'slam' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/function_score_test.rb b/elasticsearch-dsl/test/unit/queries/function_score_test.rb deleted file mode 100644 index b1e1485137..0000000000 --- a/elasticsearch-dsl/test/unit/queries/function_score_test.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class FunctionScoreTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "FunctionScore query" do - subject { FunctionScore.new } - - should "be converted to a Hash" do - assert_equal({ function_score: {} }, subject.to_hash) - end - - should "have option methods" do - subject = FunctionScore.new - - subject.query 'bar' - subject.filter 'bar' - subject.functions ['bar'] - subject.script_score 'bar' - subject.boost 'bar' - subject.max_boost 'bar' - subject.score_mode 'bar' - subject.boost_mode 'bar' - - assert_equal %w[ boost boost_mode filter functions max_boost query score_mode script_score ], - subject.to_hash[:function_score].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:function_score][:query] - end - - should "take a block" do - subject = FunctionScore.new do - query 'bar' - end - assert_equal 'bar', subject.to_hash[:function_score][:query] - end - - should "evaluate a block passed to the option method" do - subject = FunctionScore.new do - query do - match foo: 'BLAM' - end - filter do - term bar: 'slam' - end - functions << { foo: { abc: '123' } } - functions << { foo: { xyz: '456' } } - end - - assert_equal({ - function_score: { - query: { match: { foo: 'BLAM' } }, - filter: { term: { bar: 'slam' } }, - functions: [ { foo: { abc: '123' } }, { foo: { xyz: '456' } } ] } }, - subject.to_hash) - end - - should "set the functions directly" do - subject = FunctionScore.new - subject.functions = [ {foo: { abc: '123' }} ] - - assert_equal({function_score: { functions: [ {foo: { abc: '123' }} ] }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_field_test.rb b/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_field_test.rb deleted file mode 100644 index 145b5ef1e6..0000000000 --- a/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_field_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class FuzzyLikeThisFieldTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "FuzzyLikeThisField query" do - subject { FuzzyLikeThisField.new } - - should "be converted to a Hash" do - assert_equal({ fuzzy_like_this_field: {} }, subject.to_hash) - end - - should "have option methods" do - subject = FuzzyLikeThisField.new :foo - - subject.like_text 'bar' - subject.fuzziness 'bar' - subject.analyzer 'bar' - subject.max_query_terms 'bar' - subject.prefix_length 'bar' - subject.boost 'bar' - subject.ignore_tf 'bar' - - assert_equal %w[ analyzer boost fuzziness ignore_tf like_text max_query_terms prefix_length ], - subject.to_hash[:fuzzy_like_this_field][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:fuzzy_like_this_field][:foo][:like_text] - end - - should "take a block" do - subject = FuzzyLikeThisField.new :foo do - like_text 'bar' - end - assert_equal 'bar', subject.to_hash[:fuzzy_like_this_field][:foo][:like_text] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_test.rb b/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_test.rb deleted file mode 100644 index a2cf4c27e3..0000000000 --- a/elasticsearch-dsl/test/unit/queries/fuzzy_like_this_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class FuzzyLikeThisTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "FuzzyLikeThis query" do - subject { FuzzyLikeThis.new } - - should "be converted to a Hash" do - assert_equal({ fuzzy_like_this: {} }, subject.to_hash) - end - - should "have option methods" do - subject = FuzzyLikeThis.new - - subject.fields 'bar' - subject.like_text 'bar' - subject.fuzziness 'bar' - subject.analyzer 'bar' - subject.max_query_terms 'bar' - subject.prefix_length 'bar' - subject.boost 'bar' - - assert_equal %w[ analyzer boost fields fuzziness like_text max_query_terms prefix_length ], - subject.to_hash[:fuzzy_like_this].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:fuzzy_like_this][:fields] - end - - should "take a block" do - subject = FuzzyLikeThis.new do - fields ['foo'] - like_text 'bar' - end - - assert_equal({ fuzzy_like_this: { fields: ['foo'], like_text: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/fuzzy_test.rb b/elasticsearch-dsl/test/unit/queries/fuzzy_test.rb deleted file mode 100644 index ebfe2839d9..0000000000 --- a/elasticsearch-dsl/test/unit/queries/fuzzy_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class FuzzyTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Fuzzy query" do - subject { Fuzzy.new } - - should "be converted to a Hash" do - assert_equal({ fuzzy: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Fuzzy.new :foo - - subject.value 'bar' - subject.boost 'bar' - subject.fuzziness 'bar' - subject.prefix_length 'bar' - subject.max_expansions 'bar' - - assert_equal %w[ boost fuzziness max_expansions prefix_length value ], - subject.to_hash[:fuzzy][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:fuzzy][:foo][:value] - end - - should "take a block" do - subject = Fuzzy.new :foo do - value 'bar' - end - assert_equal({fuzzy: { foo: { value: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/geo_shape_test.rb b/elasticsearch-dsl/test/unit/queries/geo_shape_test.rb deleted file mode 100644 index 4e6bab8380..0000000000 --- a/elasticsearch-dsl/test/unit/queries/geo_shape_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class GeoShapeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "GeoShape query" do - subject { GeoShape.new } - - should "be converted to a Hash" do - assert_equal({ geo_shape: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeoShape.new :foo - - subject.shape 'bar' - subject.indexed_shape 'bar' - - assert_equal %w[ indexed_shape shape ], - subject.to_hash[:geo_shape][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:geo_shape][:foo][:shape] - end - - should "take a block" do - subject = GeoShape.new :foo do - shape 'bar' - end - assert_equal({geo_shape: { foo: { shape: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/has_child_test.rb b/elasticsearch-dsl/test/unit/queries/has_child_test.rb deleted file mode 100644 index 5af18a7205..0000000000 --- a/elasticsearch-dsl/test/unit/queries/has_child_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class HasChildTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "HasChild query" do - subject { HasChild.new } - - should "be converted to a Hash" do - assert_equal({ has_child: {} }, subject.to_hash) - end - - should "have option methods" do - subject = HasChild.new - - subject.type 'bar' - subject.query 'bar' - subject.score_mode 'bar' - subject.min_children 'bar' - subject.max_children 'bar' - - assert_equal %w[ max_children min_children query score_mode type ], - subject.to_hash[:has_child].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:has_child][:type] - end - - should "take a block" do - subject = HasChild.new do - type 'bar' - query match: { foo: 'bar' } - end - assert_equal({ has_child: { type: 'bar', query: { match: { foo: 'bar' } } } }, subject.to_hash) - end - - should "take a block for option method" do - subject = HasChild.new do - type 'bar' - query do - match :foo do - query 'bar' - end - end - end - assert_equal({ has_child: { type: 'bar', query: { match: { foo: { query: 'bar'} } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/has_parent_test.rb b/elasticsearch-dsl/test/unit/queries/has_parent_test.rb deleted file mode 100644 index ac47f0d609..0000000000 --- a/elasticsearch-dsl/test/unit/queries/has_parent_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class HasParentTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "HasParent query" do - subject { HasParent.new } - - should "be converted to a Hash" do - assert_equal({ has_parent: {} }, subject.to_hash) - end - - should "have option methods" do - subject = HasParent.new - - subject.parent_type 'bar' - subject.query 'bar' - subject.score_mode 'bar' - - assert_equal %w[ parent_type query score_mode ], - subject.to_hash[:has_parent].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:has_parent][:parent_type] - end - - should "take a block" do - subject = HasParent.new do - parent_type 'bar' - query match: { foo: 'bar' } - end - assert_equal({ has_parent: { parent_type: 'bar', query: { match: { foo: 'bar' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/ids_test.rb b/elasticsearch-dsl/test/unit/queries/ids_test.rb deleted file mode 100644 index 0c15a0b503..0000000000 --- a/elasticsearch-dsl/test/unit/queries/ids_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class IdsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Ids query" do - subject { Ids.new } - - should "be converted to a Hash" do - assert_equal({ ids: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Ids.new - - subject.type 'bar' - subject.values 'bar' - - assert_equal %w[ type values ], - subject.to_hash[:ids].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:ids][:type] - end - - should "take a block" do - subject = Ids.new do - type 'bar' - values [1, 2, 3] - end - assert_equal({ids: { type: 'bar', values: [1, 2, 3] } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/indices_test.rb b/elasticsearch-dsl/test/unit/queries/indices_test.rb deleted file mode 100644 index 5e71773e3f..0000000000 --- a/elasticsearch-dsl/test/unit/queries/indices_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class IndicesTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Indices query" do - subject { Indices.new } - - should "be converted to a Hash" do - assert_equal({ indices: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Indices.new - - subject.indices 'bar' - subject.query 'bar' - subject.no_match_query 'bar' - - assert_equal %w[ indices no_match_query query ], - subject.to_hash[:indices].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:indices][:indices] - end - - should "take a block" do - subject = Indices.new do - indices 'bar' - query term: { foo: 'bar' } - end - assert_equal({indices: { indices: 'bar', query: { term: { foo: 'bar' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/match_all_test.rb b/elasticsearch-dsl/test/unit/queries/match_all_test.rb deleted file mode 100644 index 9e06e4c3b6..0000000000 --- a/elasticsearch-dsl/test/unit/queries/match_all_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MatchAllTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "MatchAll query" do - subject { MatchAll.new } - - should "be converted to a Hash" do - assert_equal({ match_all: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MatchAll.new - - subject.boost 'bar' - - assert_equal %w[ boost ], - subject.to_hash[:match_all].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:match_all][:boost] - end - - should "take a block" do - subject = MatchAll.new do - boost 'bar' - end - assert_equal({match_all: { boost: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb b/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb deleted file mode 100644 index 4d23802e1a..0000000000 --- a/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MatchPhrasePrefixTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Match Phrase Prefix Query" do - subject { MatchPhrasePrefix.new } - - should "be converted to a Hash" do - assert_equal({ match_phrase_prefix: {} }, subject.to_hash) - end - - should "take a concrete value" do - subject = MatchPhrasePrefix.new message: 'test' - - assert_equal({match_phrase_prefix: {message: "test"}}, subject.to_hash) - end - - should "have option methods" do - subject = MatchPhrasePrefix.new - - subject.query 'bar' - subject.boost 10 - subject.max_expansions 1 - - assert_equal %w[ boost max_expansions query ], - subject.to_hash[:match_phrase_prefix].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:match_phrase_prefix][:query] - end - - should "take a Hash" do - subject = MatchPhrasePrefix.new message: { query: 'test' } - - assert_equal({match_phrase_prefix: {message: {query: "test" }}}, subject.to_hash) - end - - should "take a block" do - subject = MatchPhrasePrefix.new :message do - query 'test' - boost 2 - max_expansions 1 - end - - assert_equal({match_phrase_prefix: {message: {query: "test", max_expansions: 1, boost: 2 }}}, - subject.to_hash) - end - - should "take a method call" do - subject = MatchPhrasePrefix.new :message - subject.query 'test' - - assert_equal({match_phrase_prefix: {message: {query: "test" }}}, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb b/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb deleted file mode 100644 index 971814c7b8..0000000000 --- a/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MatchPhraseTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Match Phrase Query" do - subject { MatchPhrase.new } - - should "be converted to a Hash" do - assert_equal({ match_phrase: {} }, subject.to_hash) - end - - should "take a concrete value" do - subject = MatchPhrase.new message: 'test' - - assert_equal({match_phrase: {message: "test"}}, subject.to_hash) - end - - should "have option methods" do - subject = MatchPhrase.new - - subject.query 'bar' - subject.analyzer 'standard' - subject.boost 10 - subject.slop 1 - - assert_equal %w[ analyzer boost query slop ], - subject.to_hash[:match_phrase].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:match_phrase][:query] - end - - should "take a Hash" do - subject = MatchPhrase.new message: { query: 'test' } - - assert_equal({match_phrase: {message: {query: "test" }}}, subject.to_hash) - end - - should "take a block" do - subject = MatchPhrase.new :message do - query 'test' - slop 1 - boost 2 - end - - assert_equal({match_phrase: {message: {query: "test", slop: 1, boost: 2 }}}, - subject.to_hash) - end - - should "take a method call" do - subject = MatchPhrase.new :message - subject.query 'test' - - assert_equal({match_phrase: {message: {query: "test" }}}, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/match_test.rb b/elasticsearch-dsl/test/unit/queries/match_test.rb deleted file mode 100644 index d987e81573..0000000000 --- a/elasticsearch-dsl/test/unit/queries/match_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MatchTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Match Query" do - subject { Match.new } - - should "be converted to a Hash" do - assert_equal({ match: {} }, subject.to_hash) - end - - should "take a concrete value" do - subject = Match.new message: 'test' - - assert_equal({match: {message: "test"}}, subject.to_hash) - end - - should "have option methods" do - subject = Match.new - - subject.query 'bar' - subject.operator 'bar' - subject.type 'bar' - - assert_equal %w[ operator query type ], - subject.to_hash[:match].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:match][:query] - end - - should "take a Hash" do - subject = Match.new message: { query: 'test', operator: 'and' } - - assert_equal({match: {message: {query: "test", operator: "and"}}}, subject.to_hash) - end - - should "take a block" do - subject = Match.new :message do - query 'test' - operator 'and' - type 'phrase_prefix' - boost 2 - fuzziness 'AUTO' - end - - assert_equal({match: {message: {query: "test", operator: "and", type: 'phrase_prefix', boost: 2, fuzziness: 'AUTO'}}}, - subject.to_hash) - end - - should "take a method call" do - subject = Match.new :message - subject.query 'test' - subject.operator 'and' - - assert_equal({match: {message: {query: "test", operator: "and"}}}, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/more_like_this_test.rb b/elasticsearch-dsl/test/unit/queries/more_like_this_test.rb deleted file mode 100644 index 4075bcd5b2..0000000000 --- a/elasticsearch-dsl/test/unit/queries/more_like_this_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MoreLikeThisTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "MoreLikeThis query" do - subject { MoreLikeThis.new } - - should "be converted to a Hash" do - assert_equal({ more_like_this: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MoreLikeThis.new - - subject.fields 'bar' - subject.like_text 'bar' - subject.min_term_freq 'bar' - subject.max_query_terms 'bar' - subject.docs 'bar' - subject.ids 'bar' - subject.include 'bar' - subject.exclude 'bar' - subject.percent_terms_to_match 'bar' - subject.stop_words 'bar' - subject.min_doc_freq 'bar' - subject.max_doc_freq 'bar' - subject.min_word_length 'bar' - subject.max_word_length 'bar' - subject.boost_terms 'bar' - subject.boost 'bar' - subject.analyzer 'bar' - - assert_equal %w[ analyzer boost boost_terms docs exclude fields ids include like_text max_doc_freq max_query_terms max_word_length min_doc_freq min_term_freq min_word_length percent_terms_to_match stop_words ], - subject.to_hash[:more_like_this].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:more_like_this][:fields] - end - - should "take a block" do - subject = MoreLikeThis.new do - fields ['foo', 'bar'] - like_text 'abc' - end - assert_equal({more_like_this: { fields: ['foo','bar'], like_text: 'abc' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/multi_match_test.rb b/elasticsearch-dsl/test/unit/queries/multi_match_test.rb deleted file mode 100644 index 7b3175dc09..0000000000 --- a/elasticsearch-dsl/test/unit/queries/multi_match_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class MultiMatchTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "MultiMatch query" do - subject { MultiMatch.new } - - should "be converted to a Hash" do - assert_equal({ multi_match: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MultiMatch.new - - subject.query 'bar' - subject.fields 'bar' - subject.type 'bar' - subject.use_dis_max 'bar' - - assert_equal %w[ fields query type use_dis_max ], - subject.to_hash[:multi_match].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:multi_match][:query] - end - - should "take a block" do - subject = MultiMatch.new do - query 'bar' - fields ['a', 'b'] - end - - assert_equal 'bar', subject.to_hash[:multi_match][:query] - assert_equal ['a', 'b'], subject.to_hash[:multi_match][:fields] - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/nested_test.rb b/elasticsearch-dsl/test/unit/queries/nested_test.rb deleted file mode 100644 index 99a4a245e2..0000000000 --- a/elasticsearch-dsl/test/unit/queries/nested_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class NestedTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Nested query" do - subject { Nested.new } - - should "be converted to a Hash" do - assert_equal({ nested: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Nested.new - - subject.path 'bar' - subject.score_mode 'bar' - subject.query 'bar' - subject.inner_hits({ size: 1 }) - - assert_equal %w[ inner_hits path query score_mode ], - subject.to_hash[:nested].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:nested][:path] - assert_equal({ size: 1 }, subject.to_hash[:nested][:inner_hits]) - end - - should "take the query as a Hash" do - subject = Nested.new - subject.path 'bar' - subject.query match: { foo: 'bar' } - - assert_equal({nested: { path: 'bar', query: { match: { foo: 'bar' } } } }, subject.to_hash) - end - - should "take a block" do - subject = Nested.new do - path 'bar' - query do - match foo: 'bar' - end - end - - assert_equal({nested: { path: 'bar', query: { match: { foo: 'bar' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/prefix_test.rb b/elasticsearch-dsl/test/unit/queries/prefix_test.rb deleted file mode 100644 index 755d6f3ee2..0000000000 --- a/elasticsearch-dsl/test/unit/queries/prefix_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class PrefixTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Prefix query" do - subject { Prefix.new } - - should "be converted to a Hash" do - assert_equal({ prefix: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Prefix.new :foo - - subject.value 'bar' - subject.boost 'bar' - - assert_equal %w[ boost value ], - subject.to_hash[:prefix][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:prefix][:foo][:value] - end - - should "take a block" do - subject = Prefix.new :foo do - value 'bar' - end - assert_equal({prefix: { foo: { value: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/query_string_test.rb b/elasticsearch-dsl/test/unit/queries/query_string_test.rb deleted file mode 100644 index 93a9f41b60..0000000000 --- a/elasticsearch-dsl/test/unit/queries/query_string_test.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class QueryStringTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "QueryString query" do - subject { QueryString.new } - - should "be converted to a Hash" do - assert_equal({ query_string: {} }, subject.to_hash) - end - - should "have option methods" do - subject = QueryString.new :foo - - subject.query 'bar' - subject.fields 'bar' - subject.default_field 'bar' - subject.default_operator 'bar' - subject.analyzer 'bar' - subject.allow_leading_wildcard 'bar' - subject.lowercase_expanded_terms 'bar' - subject.enable_position_increments 'bar' - subject.fuzzy_max_expansions 'bar' - subject.fuzziness 'bar' - subject.fuzzy_prefix_length 'bar' - subject.phrase_slop 'bar' - subject.boost 'bar' - subject.analyze_wildcard 'bar' - subject.auto_generate_phrase_queries 'bar' - subject.minimum_should_match 'bar' - subject.lenient 'bar' - subject.locale 'bar' - subject.use_dis_max 'bar' - subject.tie_breaker 'bar' - subject.time_zone 'bar' - - assert_equal %w[ allow_leading_wildcard analyze_wildcard analyzer auto_generate_phrase_queries boost default_field default_operator enable_position_increments fields fuzziness fuzzy_max_expansions fuzzy_prefix_length lenient locale lowercase_expanded_terms minimum_should_match phrase_slop query tie_breaker time_zone use_dis_max ], - subject.to_hash[:query_string][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:query_string][:foo][:query] - end - - should "take a block" do - subject = QueryString.new :foo do - query 'foo AND bar' - end - assert_equal({ query_string: { foo: { query: 'foo AND bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/range_test.rb b/elasticsearch-dsl/test/unit/queries/range_test.rb deleted file mode 100644 index 8b0eeda6fd..0000000000 --- a/elasticsearch-dsl/test/unit/queries/range_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class RangeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Range Query" do - - should "take a Hash" do - @subject = Range.new age: { gte: 10, lte: 20 } - - assert_equal({:range=>{:age=>{:gte=>10, :lte=>20}}}, @subject.to_hash) - end - - should "take a block" do - @subject = Range.new :age do - gte 10 - lte 20 - boost 2 - format 'mm/dd/yyyy' - end - - assert_equal({:range=>{:age=>{:gte=>10, :lte=>20, :boost=>2, :format=>'mm/dd/yyyy'}}}, @subject.to_hash) - end - - should "take a method call" do - @subject = Range.new :age - @subject.gte 10 - @subject.lte 20 - @subject.format 'mm/dd/yyyy' - - assert_equal({:range=>{:age=>{:gte=>10, :lte=>20, :format=>'mm/dd/yyyy'}}}, @subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/regexp_test.rb b/elasticsearch-dsl/test/unit/queries/regexp_test.rb deleted file mode 100644 index 145ef9432d..0000000000 --- a/elasticsearch-dsl/test/unit/queries/regexp_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class RegexpTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Regexp query" do - subject { Regexp.new } - - should "be converted to a Hash" do - assert_equal({ regexp: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Regexp.new :foo - - subject.value 'bar' - subject.boost 'bar' - subject.flags 'bar' - - assert_equal %w[ boost flags value ], - subject.to_hash[:regexp][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:regexp][:foo][:value] - end - - should "take a Hash" do - subject = Regexp.new foo: 'b.*r' - assert_equal({regexp: { foo: 'b.*r' }}, subject.to_hash) - end - - should "take a block" do - subject = Regexp.new :foo do - value 'bar' - end - assert_equal({regexp: { foo: { value: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/simple_query_string_test.rb b/elasticsearch-dsl/test/unit/queries/simple_query_string_test.rb deleted file mode 100644 index 740e004c0d..0000000000 --- a/elasticsearch-dsl/test/unit/queries/simple_query_string_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SimpleQueryStringTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SimpleQueryString query" do - subject { SimpleQueryString.new } - - should "be converted to a Hash" do - assert_equal({ simple_query_string: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SimpleQueryString.new :foo - - subject.query 'bar' - subject.fields 'bar' - subject.default_operator 'bar' - subject.analyzer 'bar' - subject.flags 'bar' - subject.lenient 'bar' - - assert_equal %w[ analyzer default_operator fields flags lenient query ], - subject.to_hash[:simple_query_string][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:simple_query_string][:foo][:query] - end - - should "take a block" do - subject = SimpleQueryString.new :foo do - query 'bar' - end - assert_equal({simple_query_string: { foo: { query: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_first_test.rb b/elasticsearch-dsl/test/unit/queries/span_first_test.rb deleted file mode 100644 index bbdbf61e8d..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_first_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanFirstTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanFirst query" do - subject { SpanFirst.new } - - should "be converted to a Hash" do - assert_equal({ span_first: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SpanFirst.new - - subject.match 'bar' - - assert_equal %w[ match ], - subject.to_hash[:span_first].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:span_first][:match] - end - - should "take a block" do - subject = SpanFirst.new do - match 'bar' - end - assert_equal({ span_first: { match: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_multi_test.rb b/elasticsearch-dsl/test/unit/queries/span_multi_test.rb deleted file mode 100644 index 05136f6264..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_multi_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanMultiTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanMulti query" do - subject { SpanMulti.new } - - should "be converted to a Hash" do - assert_equal({ span_multi: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SpanMulti.new - - subject.match 'bar' - - assert_equal %w[ match ], - subject.to_hash[:span_multi].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:span_multi][:match] - end - - should "take a block" do - subject = SpanMulti.new do - match 'bar' - end - assert_equal({span_multi: { match: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_near_test.rb b/elasticsearch-dsl/test/unit/queries/span_near_test.rb deleted file mode 100644 index 1468a406f8..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_near_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanNearTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanNear query" do - subject { SpanNear.new } - - should "be converted to a Hash" do - assert_equal({ span_near: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SpanNear.new - - subject.span_near 'bar' - subject.slop 'bar' - subject.in_order 'bar' - subject.collect_payloads 'bar' - - assert_equal %w[ collect_payloads in_order slop span_near ], - subject.to_hash[:span_near].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:span_near][:span_near] - end - - should "take a block" do - subject = SpanNear.new do - span_near 'bar' - end - assert_equal({ span_near: { span_near: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_not_test.rb b/elasticsearch-dsl/test/unit/queries/span_not_test.rb deleted file mode 100644 index 6d5aa7511b..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_not_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanNotTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanNot query" do - subject { SpanNot.new } - - should "be converted to a Hash" do - assert_equal({ span_not: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SpanNot.new - - subject.include 'bar' - subject.exclude 'bar' - subject.pre 'bar' - subject.post 'bar' - subject.dist 'bar' - - assert_equal %w[ dist exclude include post pre ], - subject.to_hash[:span_not].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:span_not][:include] - end - - should "take a block" do - subject = SpanNot.new do - include 'bar' - end - assert_equal({ span_not: { include: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_or_test.rb b/elasticsearch-dsl/test/unit/queries/span_or_test.rb deleted file mode 100644 index 2fbcf4c58a..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_or_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanOrTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanOr query" do - subject { SpanOr.new } - - should "be converted to a Hash" do - assert_equal({ span_or: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SpanOr.new - - subject.clauses 'bar' - - assert_equal %w[ clauses ], - subject.to_hash[:span_or].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:span_or][:clauses] - end - - should "take a block" do - subject = SpanOr.new do - clauses 'bar' - end - assert_equal({span_or: { clauses: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/span_term_test.rb b/elasticsearch-dsl/test/unit/queries/span_term_test.rb deleted file mode 100644 index cfb2a22d23..0000000000 --- a/elasticsearch-dsl/test/unit/queries/span_term_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class SpanTermTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "SpanTerm query" do - subject { SpanTerm.new } - - should "be converted to a Hash" do - assert_equal({ span_term: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = SpanTerm.new foo: 'bar' - assert_equal({ span_term: { foo: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/template_test.rb b/elasticsearch-dsl/test/unit/queries/template_test.rb deleted file mode 100644 index b958a7dfe6..0000000000 --- a/elasticsearch-dsl/test/unit/queries/template_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class TemplateTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Template query" do - subject { Template.new } - - should "be converted to a Hash" do - assert_equal({ template: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Template.new - - subject.query 'bar' - subject.params 'bar' - - assert_equal %w[ params query ], - subject.to_hash[:template].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:template][:query] - end - - should "take a hash" do - subject = Template.new query: 'bar', params: { foo: 'abc' } - assert_equal({template: { query: 'bar', params: { foo: 'abc' } } }, subject.to_hash) - end - - should "take a block" do - subject = Template.new do - query 'bar' - params foo: 'abc' - end - assert_equal({template: { query: 'bar', params: { foo: 'abc' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/term_test.rb b/elasticsearch-dsl/test/unit/queries/term_test.rb deleted file mode 100644 index e73388a743..0000000000 --- a/elasticsearch-dsl/test/unit/queries/term_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class TermTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - subject { Term.new message: 'test' } - - context "Term Query" do - should "take a concrete value" do - @subject = Term.new message: 'test' - - assert_equal({:term=>{:message=>"test"}}, @subject.to_hash) - end - - should "take a Hash" do - @subject = Term.new message: { query: 'test', boost: 2 } - - assert_equal({:term=>{:message=>{:query=>"test", :boost=>2}}}, @subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/terms_test.rb b/elasticsearch-dsl/test/unit/queries/terms_test.rb deleted file mode 100644 index 0521dc412a..0000000000 --- a/elasticsearch-dsl/test/unit/queries/terms_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class TermsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Terms query" do - subject { Terms.new } - - should "be converted to a Hash" do - assert_equal({ terms: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Terms.new foo: ['abc', 'xyz'] - assert_equal({ terms: { foo: ['abc', 'xyz'] } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/top_children_test.rb b/elasticsearch-dsl/test/unit/queries/top_children_test.rb deleted file mode 100644 index b23667fb8d..0000000000 --- a/elasticsearch-dsl/test/unit/queries/top_children_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class TopChildrenTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "TopChildren query" do - subject { TopChildren.new } - - should "be converted to a Hash" do - assert_equal({ top_children: {} }, subject.to_hash) - end - - should "have option methods" do - subject = TopChildren.new - - subject.type 'bar' - subject.query 'bar' - subject.score 'bar' - subject.factor 'bar' - subject.incremental_factor 'bar' - subject._scope 'bar' - - assert_equal %w[ _scope factor incremental_factor query score type ], - subject.to_hash[:top_children].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:top_children][:type] - end - - should "take a block" do - subject = TopChildren.new do - type 'bar' - query 'foo' - end - assert_equal({ top_children: { type: 'bar', query: 'foo' } }, subject.to_hash) - end - - should "evaluate a block passed to the query method" do - subject = TopChildren.new do - type 'bar' - query do - match foo: 'BLAM' - end - end - - assert_equal({ top_children: { type: 'bar', query: { match: { foo: 'BLAM' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/queries/wildcard_test.rb b/elasticsearch-dsl/test/unit/queries/wildcard_test.rb deleted file mode 100644 index 7d3d3b9662..0000000000 --- a/elasticsearch-dsl/test/unit/queries/wildcard_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Queries - class WildcardTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Queries - - context "Wildcard query" do - subject { Wildcard.new } - - should "be converted to a Hash" do - assert_equal({ wildcard: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Wildcard.new :foo - - subject.value 'bar' - subject.boost 'bar' - - assert_equal %w[ boost value ], - subject.to_hash[:wildcard][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:wildcard][:foo][:value] - end - - should "take a hash" do - subject = Wildcard.new foo: 'bar' - - assert_equal({ wildcard: { foo: 'bar' } }, subject.to_hash) - end - - should "take a block" do - subject = Wildcard.new :foo do - value 'bar' - end - assert_equal({ wildcard: { foo: { value: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end