diff --git a/elasticsearch-dsl/spec/filters/and_spec.rb b/elasticsearch-dsl/spec/filters/and_spec.rb new file mode 100644 index 0000000000..4d23396289 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/and_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::And do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(and: {}) + end + end + + context 'when enumerable methods are called' do + + before do + search << { term: { foo: 'bar' } } + search << { term: { moo: 'mam' } } + end + + it 'behaves like an enumerable' do + expect(search.size).to eq(2) + expect(search[0][:term][:foo]).to eq('bar') + expect(search.any? { |d| d[:term] == { foo: 'bar' } }).to be(true) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(filters: [ { term: { foo: 'bar' } } ]) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(and: { filters: [ { term: { foo: 'bar' } } ] }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + term foo: 'bar' + term moo: 'mam' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(and: [ { term: { foo: 'bar' } }, { term: { moo: 'mam' } } ]) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/bool_spec.rb b/elasticsearch-dsl/spec/filters/bool_spec.rb new file mode 100644 index 0000000000..d2504af10a --- /dev/null +++ b/elasticsearch-dsl/spec/filters/bool_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Bool do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(bool: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(must: [ {term: { foo: 'bar' } } ]) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' } } ] }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + must { term foo: 'bar' } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' }} ] }) + end + + context 'when the block calls multiple methods' do + + let(:search) do + described_class.new do + must { term foo: 'bar' } + must_not { term moo: 'bam' } + should { term xoo: 'bax' } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(bool: + { must: [ {term: { foo: 'bar' }} ], + must_not: [ {term: { moo: 'bam' }} ], + should: [ {term: { xoo: 'bax' }} ] + }) + end + end + + context 'when the block calls multiple conditions' do + + let(:search) do + described_class.new do + must { term foo: 'bar' } + must { term moo: 'bam' } + + should { term xoo: 'bax' } + should { term zoo: 'baz' } + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(bool: + { must: [ {term: { foo: 'bar' }}, {term: { moo: 'bam' }} ], + should: [ {term: { xoo: 'bax' }}, {term: { zoo: 'baz' }} ] + }) + end + end + end + end + + describe '#must' do + + before do + search.must { term foo: 'bar' } + end + + it 'applies the condition' do + expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' }} ] }) + end + + context 'when the method is called more than once' do + + before do + search.must { term foo: 'bar' } + search.must { term moo: 'bam' } + end + + it 'applies the conditions' do + expect(search.to_hash).to eq(bool: { must: [ {term: { foo: 'bar' } }, { term: { moo: 'bam' } } ] }) + end + end + end + + describe '#should' do + + before do + search.should { term xoo: 'bax' } + end + + it 'applies the condition' do + expect(search.to_hash).to eq(bool: { should: [ {term: { xoo: 'bax' }} ] }) + end + end + + context 'when methods are chained' do + + before do + search.must { term foo: 'bar' } + search.must { term foo: 'baz' }.must { term moo: 'bam' } + search.must_not { term foo: 'biz' } + search.should { term foo: 'bor' } + end + + it 'applies all the conditions' do + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }, { term: { foo: 'baz' } }, + { term: { moo: 'bam' } }], + must_not: [{ term: { foo: 'biz' } }], + should: [{ term: { foo: 'bor' } }] }) + end + end +end diff --git a/elasticsearch-dsl/spec/filters/exists_spec.rb b/elasticsearch-dsl/spec/filters/exists_spec.rb new file mode 100644 index 0000000000..35c1fa520b --- /dev/null +++ b/elasticsearch-dsl/spec/filters/exists_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Exists do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(exists: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#field' do + + before do + search.field('bar') + end + + it 'applies the option' do + expect(search.to_hash[:exists][:foo][:field]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + field 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(exists: { field: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geo_bounding_box_spec.rb b/elasticsearch-dsl/spec/filters/geo_bounding_box_spec.rb new file mode 100644 index 0000000000..e27b97f3d5 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geo_bounding_box_spec.rb @@ -0,0 +1,127 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::GeoBoundingBox do + + describe '#to_hash' do + + let(:search) do + described_class.new + end + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(geo_bounding_box: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#top_left' do + + before do + search.top_left('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:top_left]).to eq('bar') + end + end + + describe '#bottom_right' do + + before do + search.bottom_right('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:bottom_right]).to eq('bar') + end + end + + describe '#top_right' do + + before do + search.top_right('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:top_right]).to eq('bar') + end + end + + describe '#bottom_left' do + + before do + search.bottom_left('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:bottom_left]).to eq('bar') + end + end + + describe '#top' do + + before do + search.top('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:top]).to eq('bar') + end + end + + describe '#left' do + + before do + search.left('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:left]).to eq('bar') + end + end + + describe '#bottom' do + + before do + search.bottom('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:bottom]).to eq('bar') + end + end + + describe '#right' do + + before do + search.right('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_bounding_box][:right]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + top_left [0,1] + bottom_right [3,2] + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_bounding_box: { top_left: [0,1], bottom_right: [3,2] }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geo_distance_range_spec.rb b/elasticsearch-dsl/spec/filters/geo_distance_range_spec.rb new file mode 100644 index 0000000000..f6b4f32deb --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geo_distance_range_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::GeoDistanceRange 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_distance_range: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#lat' do + + before do + search.lat('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance_range][:foo][:lat]).to eq('bar') + end + end + + describe '#lon' do + + before do + search.lon('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance_range][:foo][:lon]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + lat 40 + lon -70 + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance_range: { lat: 40, lon: -70 }) + end + + context 'when options are also provided' do + + let(:search) do + described_class.new :foo, from: '10km', to: '20km' do + lat 40 + lon -70 + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance_range: { foo: { lat: 40, lon: -70 }, from: '10km', to: '20km' }) + end + end + end + + context 'when options are provided' do + + let(:search) do + described_class.new(from: '10km', to: '20km', foo: { lat: 40, lon: -70 }) + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance_range: { foo: { lat: 40, lon: -70 }, from: '10km', to: '20km' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geo_distance_spec.rb b/elasticsearch-dsl/spec/filters/geo_distance_spec.rb new file mode 100644 index 0000000000..6def1d0ff0 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geo_distance_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::GeoDistance 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_distance: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#distance' do + + before do + search.distance('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance][:distance]).to eq('bar') + end + end + + describe '#distance_type' do + + before do + search.distance_type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance][:distance_type]).to eq('bar') + end + end + + describe '#lat' do + + before do + search.lat('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance][:foo][:lat]).to eq('bar') + end + end + + describe '#lon' do + + before do + search.lon('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_distance][:foo][:lon]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new :foo do + distance '1km' + lat 40 + lon -70 + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance: { distance: '1km', foo: { lat: 40, lon: -70 } }) + end + + context 'when options are also provided' do + + let(:search) do + described_class.new(:foo, distance: '10km') do + lat 40 + lon -70 + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance: { foo: { lat: 40, lon: -70 }, distance: '10km' }) + end + end + end + + context 'when options are provided' do + + let(:search) do + described_class.new(distance: '10km', foo: { lat: 40, lon: -70 }) + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_distance: { foo: { lat: 40, lon: -70 }, distance: '10km' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geo_polygon_spec.rb b/elasticsearch-dsl/spec/filters/geo_polygon_spec.rb new file mode 100644 index 0000000000..38ef0061e5 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geo_polygon_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::GeoPolygon 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_polygon: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#points' do + + before do + search.points('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_polygon][:foo][:points]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new :foo do + points 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geo_polygon: { foo: { points: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geo_shape_spec.rb b/elasticsearch-dsl/spec/filters/geo_shape_spec.rb new file mode 100644 index 0000000000..c951689ab3 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geo_shape_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::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(:foo) + end + + describe '#shape' do + + before do + search.shape('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geo_shape][:foo][: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][:foo][: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).to eq(geo_shape: { foo: { shape: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/geohash_cell_spec.rb b/elasticsearch-dsl/spec/filters/geohash_cell_spec.rb new file mode 100644 index 0000000000..5cf232939d --- /dev/null +++ b/elasticsearch-dsl/spec/filters/geohash_cell_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::GeohashCell 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(geohash_cell: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#precision' do + + before do + search.precision('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geohash_cell][:precision]).to eq('bar') + end + end + + describe '#neighbors' do + + before do + search.neighbors('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geohash_cell][:neighbors]).to eq('bar') + end + end + + describe '#lat' do + + before do + search.lat('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geohash_cell][:foo][:lat]).to eq('bar') + end + end + + describe '#lon' do + + before do + search.lon('bar') + end + + it 'applies the option' do + expect(search.to_hash[:geohash_cell][:foo][:lon]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new :foo do + lat 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(geohash_cell: { foo: { lat: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/has_child_spec.rb b/elasticsearch-dsl/spec/filters/has_child_spec.rb new file mode 100644 index 0000000000..5c5736097c --- /dev/null +++ b/elasticsearch-dsl/spec/filters/has_child_spec.rb @@ -0,0 +1,122 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::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(:foo) + end + + describe '#type' do + + before do + search.type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:foo][: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 '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_child][:filter]).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][:foo][: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][:foo][:max_children]).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[:has_child][:foo][:inner_hits]).to eq(size: 1) + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + type 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(has_child: { foo: { type: 'bar' } }) + end + end + + context 'when a block is provided to an option method' 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/filters/has_parent_spec.rb b/elasticsearch-dsl/spec/filters/has_parent_spec.rb new file mode 100644 index 0000000000..6ae2531036 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/has_parent_spec.rb @@ -0,0 +1,111 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::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(:foo) + end + + describe '#parent_type' do + + before do + search.parent_type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_parent][:foo][: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 '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:has_parent][:filter]).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][:foo][:score_mode]).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[:has_parent][:foo][:inner_hits]).to eq(size: 1) + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + parent_type 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(has_parent: { foo: { parent_type: 'bar' } }) + end + end + + context 'when a block is provided to an option method' do + + let(:search) do + described_class.new do + parent_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_parent: { parent_type: 'bar', query: { match: { foo: { query: 'bar'} } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/ids_spec.rb b/elasticsearch-dsl/spec/filters/ids_spec.rb new file mode 100644 index 0000000000..9e3fb7c04a --- /dev/null +++ b/elasticsearch-dsl/spec/filters/ids_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::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(:foo) + end + + describe '#type' do + + before do + search.type('bar') + end + + it 'applies the option' do + expect(search.to_hash[:ids][:foo][: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][:foo][: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/filters/indices_spec.rb b/elasticsearch-dsl/spec/filters/indices_spec.rb new file mode 100644 index 0000000000..c9c470131e --- /dev/null +++ b/elasticsearch-dsl/spec/filters/indices_spec.rb @@ -0,0 +1,92 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::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 '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:indices][:filter]).to eq('bar') + end + end + + describe '#no_match_filter' do + + before do + search.no_match_filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:indices][:no_match_filter]).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' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(indices: { indices: 'bar' }) + end + end + + context 'when a block is provided to an option method' do + + let(:search) do + described_class.new do + indices 'bar' + + filter do + term foo: 'bar' + end + no_match_filter do + term foo: 'bam' + end + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(indices: { indices: 'bar', filter: { term: { foo: 'bar' } }, + no_match_filter: { term: { foo: 'bam' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/limit_spec.rb b/elasticsearch-dsl/spec/filters/limit_spec.rb new file mode 100644 index 0000000000..e94e5d8a30 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/limit_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Limit do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(limit: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#value' do + + before do + search.value('bar') + end + + it 'applies the option' do + expect(search.to_hash[:limit][:foo][:value]).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).to eq(limit: { value: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/match_all_spec.rb b/elasticsearch-dsl/spec/filters/match_all_spec.rb new file mode 100644 index 0000000000..f458b283dd --- /dev/null +++ b/elasticsearch-dsl/spec/filters/match_all_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::MatchAll do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(match_all: {}) + end + end +end diff --git a/elasticsearch-dsl/spec/filters/missing_spec.rb b/elasticsearch-dsl/spec/filters/missing_spec.rb new file mode 100644 index 0000000000..1efeb162f9 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/missing_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Missing do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(missing: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#field' do + + before do + search.field('bar') + end + + it 'applies the option' do + expect(search.to_hash[:missing][:foo][:field]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + field 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(missing: { field: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/nested_spec.rb b/elasticsearch-dsl/spec/filters/nested_spec.rb new file mode 100644 index 0000000000..add2ff6d67 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/nested_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Nested do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(nested: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new + end + + describe '#path' do + + before do + search.path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:nested][:path]).to eq('bar') + end + end + + describe '#query' do + + before do + search.query('bar') + end + + it 'applies the option' do + expect(search.to_hash[:nested][:query]).to eq('bar') + end + end + + describe '#filter' do + + before do + search.filter('bar') + end + + it 'applies the option' do + expect(search.to_hash[:nested][:filter]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new do + path 'bar' + filter do + term foo: 'bar' + end + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(nested: { path: 'bar', filter: { term: { foo: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/not_spec.rb b/elasticsearch-dsl/spec/filters/not_spec.rb new file mode 100644 index 0000000000..b2415bee71 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/not_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Not do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(not: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(filters: [ { term: { foo: 'bar' } } ]) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(not: { filters: [ { term: { foo: 'bar' } } ] }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + term foo: 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(not: { term: { foo: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/or_spec.rb b/elasticsearch-dsl/spec/filters/or_spec.rb new file mode 100644 index 0000000000..314963cf22 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/or_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Or do + + let(:search) do + described_class.new + end + + it 'responds to enumerable methods' do + expect(search.empty?).to be(true) + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(or: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(filters: [ { term: { foo: 'bar' } } ]) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(or: { filters: [ { term: { foo: 'bar' } } ] }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + term foo: 'bar' + term moo: 'mam' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(or: [ {term: { foo: 'bar'}}, {term: { moo: 'mam'}} ]) + end + end + end + + context 'when the filter is appended to' do + + before do + search << { term: { foo: 'bar' } } + end + + it 'appends the predicate' do + expect(search.to_hash).to eq(or: [ { term: { foo: 'bar' } } ]) + end + end +end diff --git a/elasticsearch-dsl/spec/filters/prefix_spec.rb b/elasticsearch-dsl/spec/filters/prefix_spec.rb new file mode 100644 index 0000000000..6f848776e3 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/prefix_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Prefix do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(prefix: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: 'bar') + end + + it 'applies the hash' do + expect(search.to_hash).to eq(prefix: { foo: 'bar' }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/query_spec.rb b/elasticsearch-dsl/spec/filters/query_spec.rb new file mode 100644 index 0000000000..67e9ddb4f7 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/query_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Query do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(query: {}) + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(query_string: { query: 'foo' }) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(query: { query_string: { query: 'foo' } }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new do + match foo: 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(query: { match: { foo: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/range_spec.rb b/elasticsearch-dsl/spec/filters/range_spec.rb new file mode 100644 index 0000000000..b5194a2fd2 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/range_spec.rb @@ -0,0 +1,94 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Range do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(range: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#gte' do + + before do + search.gte('bar') + end + + it 'applies the option' do + expect(search.to_hash[:range][:foo][:gte]).to eq('bar') + end + end + + describe '#lte' do + + before do + search.lte('bar') + end + + it 'applies the option' do + expect(search.to_hash[:range][:foo][:lte]).to eq('bar') + end + end + + describe '#time_zone' do + + before do + search.time_zone('bar') + end + + it 'applies the option' do + expect(search.to_hash[:range][:foo][:time_zone]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:range][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(age: { gte: 10, lte: 20 }) + end + + it 'applies the hash' do + expect(search.to_hash).to eq(range: { age: { gte: 10, lte: 20 } }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new(:age) do + gte 10 + lte 20 + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(range: { age: { gte: 10, lte: 20 } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/regexp_spec.rb b/elasticsearch-dsl/spec/filters/regexp_spec.rb new file mode 100644 index 0000000000..ef161c7c30 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/regexp_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Regexp do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(regexp: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#value' do + + before do + search.value('bar') + end + + it 'applies the option' do + expect(search.to_hash[:regexp][:foo][:value]).to eq('bar') + end + end + + describe '#flags' do + + before do + search.flags('bar') + end + + it 'applies the option' do + expect(search.to_hash[:regexp][:foo][:flags]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a hash is provided' do + + let(:search) do + described_class.new(foo: 'b.*r') + end + + it 'applies the hash' do + expect(search.to_hash).to eq(regexp: { foo: 'b.*r' }) + end + end + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + value 'b*r' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(regexp: { foo: { value: 'b*r' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/script_spec.rb b/elasticsearch-dsl/spec/filters/script_spec.rb new file mode 100644 index 0000000000..05ea2b9245 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/script_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Script do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(script: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#script' do + + before do + search.script('bar') + end + + it 'applies the option' do + expect(search.to_hash[:script][:foo][:script]).to eq('bar') + end + end + + describe '#params' do + + before do + search.params(foo: 'bar') + end + + it 'applies the option' do + expect(search.to_hash[:script][:foo][:params]).to eq(foo: 'bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + script 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq(script: { foo: { script: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/term_spec.rb b/elasticsearch-dsl/spec/filters/term_spec.rb new file mode 100644 index 0000000000..2054f66975 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/term_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Term do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(term: {}) + end + end + + describe '#initialize' do + + context 'when a scalar is specified' do + + let(:search) do + described_class.new(message: 'test') + end + + it 'sets the value' do + expect(search.to_hash).to eq(term: { message: 'test' }) + end + end + + context 'when a hash is specified' do + + let(:search) do + described_class.new(message: { query: 'test' }) + end + + it 'sets the value' do + expect(search.to_hash).to eq(term: { message: { query: 'test' } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/terms_spec.rb b/elasticsearch-dsl/spec/filters/terms_spec.rb new file mode 100644 index 0000000000..964839f6d4 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/terms_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Terms do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(terms: {}) + end + end + + describe '#initialize' do + + context 'when a hash is specified' do + + let(:search) do + described_class.new(foo: ['abc', 'xyz']) + end + + it 'sets the value' do + expect(search.to_hash).to eq(terms: { foo: ['abc', 'xyz'] }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/filters/type_spec.rb b/elasticsearch-dsl/spec/filters/type_spec.rb new file mode 100644 index 0000000000..a1efe6c126 --- /dev/null +++ b/elasticsearch-dsl/spec/filters/type_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Filters::Type do + + let(:search) do + described_class.new + end + + describe '#to_hash' do + + it 'can be converted to a hash' do + expect(search.to_hash).to eq(type: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#value' do + + before do + search.value('bar') + end + + it 'applies the option' do + expect(search.to_hash[:type][:foo][:value]).to eq('bar') + end + end + end + + describe '#initialize' do + + 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).to eq(type: { foo: { value: 'bar' } }) + end + end + end +end diff --git a/elasticsearch-dsl/test/unit/filters/and_test.rb b/elasticsearch-dsl/test/unit/filters/and_test.rb deleted file mode 100644 index e9df2c72b4..0000000000 --- a/elasticsearch-dsl/test/unit/filters/and_test.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class AndTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "And filter" do - subject { And.new } - - should "be converted to a Hash" do - assert_equal({ and: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = And.new filters: [ { term: { foo: 'bar' } } ] - assert_equal({ and: { filters: [ { term: { foo: 'bar' } } ] } }, subject.to_hash) - end - - should "take a block" do - subject = And.new do - term foo: 'bar' - term moo: 'mam' - end - assert_equal({and: [ {term: { foo: 'bar'}}, {term: { moo: 'mam'}} ]}, subject.to_hash) - end - - should "behave like an Enumerable" do - subject = And.new - subject << { term: { foo: 'bar' } } - subject << { term: { moo: 'mam' } } - - assert_equal 2, subject.size - assert_equal 'bar', subject[0][:term][:foo] - assert subject.any? { |d| d[:term] == { foo: 'bar' } } - end - - should "behave like an Enumerable with a block" do - subject = And.new do - term foo: 'bar' - term moo: 'mam' - end - - subject.call - assert_equal 2, subject.size - - hash = subject.to_hash - assert_equal 'bar', hash[:and][0][:term][:foo] - assert hash[:and].any? { |d| d[:term] == { foo: 'bar' } } - end - - should "behave like an Array" do - subject = And.new - - assert subject.empty? - - subject << { term: { foo: 'bar' } } - subject << { term: { moo: 'xam' } } - - assert ! subject.empty? - - assert_equal({ and: [ { term: { foo: 'bar' } }, { term: { moo: 'xam' } } ] }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/bool_test.rb b/elasticsearch-dsl/test/unit/filters/bool_test.rb deleted file mode 100644 index 886031f1bc..0000000000 --- a/elasticsearch-dsl/test/unit/filters/bool_test.rb +++ /dev/null @@ -1,98 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class BoolTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Bool Filter" 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: [ {term: { foo: 'bar' } } ] - - assert_equal( { bool: { must: [ {term: { foo: 'bar' } } ] } }, subject.to_hash ) - end - - should "take a block" do - subject = Bool.new do - must { term foo: 'bar' } - end - - assert_equal( { bool: { must: [ {term: { foo: 'bar' }} ] } }, subject.to_hash ) - end - - should "take a block with multiple methods" do - subject = Bool.new do - must { term foo: 'bar' } - must_not { term moo: 'bam' } - should { term xoo: 'bax' } - end - - assert_equal( { bool: - { must: [ {term: { foo: 'bar' }} ], - must_not: [ {term: { moo: 'bam' }} ], - should: [ {term: { xoo: 'bax' }} ] - } - }, - subject.to_hash ) - end - - should "take a block with multiple conditions" do - subject = Bool.new do - must { term foo: 'bar' } - must { term moo: 'bam' } - - should { term xoo: 'bax' } - should { term zoo: 'baz' } - end - - # Make sure we're not additive - subject.to_hash - subject.to_hash - - assert_equal( { bool: - { must: [ {term: { foo: 'bar' }}, {term: { moo: 'bam' }} ], - should: [ {term: { xoo: 'bax' }}, {term: { zoo: 'baz' }} ] - } - }, - subject.to_hash ) - end - - should "take method calls" do - subject = Bool.new - - subject.must { term foo: 'bar' } - assert_equal( { bool: { must: [ {term: { foo: 'bar' }} ] } }, subject.to_hash ) - - subject.must { term moo: 'bam' } - assert_equal( { bool: { must: [ {term: { foo: 'bar' }}, {term: { moo: 'bam' }} ]} }, - subject.to_hash ) - - subject.should { term xoo: 'bax' } - assert_equal( { bool: - { must: [ {term: { foo: 'bar' }}, {term: { moo: 'bam' }} ], - should: [ {term: { xoo: 'bax' }} ] } - }, - subject.to_hash ) - end - - should "be chainable" do - subject = Bool.new - - assert_instance_of Bool, subject.must { term foo: 'bar' } - assert_instance_of Bool, subject.must { term foo: 'bar' }.must { term moo: 'bam' } - assert_instance_of Bool, subject.must_not { term foo: 'bar' } - assert_instance_of Bool, subject.should { term foo: 'bar' } - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/exists_test.rb b/elasticsearch-dsl/test/unit/filters/exists_test.rb deleted file mode 100644 index 025bd74c16..0000000000 --- a/elasticsearch-dsl/test/unit/filters/exists_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class ExistsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Exists filter" 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/filters/geo_bounding_box_test.rb b/elasticsearch-dsl/test/unit/filters/geo_bounding_box_test.rb deleted file mode 100644 index df73e00ed6..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geo_bounding_box_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeoBoundingBoxTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeoBoundingBox filter" do - subject { GeoBoundingBox.new } - - should "be converted to a Hash" do - assert_equal({ geo_bounding_box: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeoBoundingBox.new :foo - - subject.top_left 'bar' - subject.bottom_right 'bar' - subject.top_right 'bar' - subject.bottom_left 'bar' - subject.top 'bar' - subject.left 'bar' - subject.bottom 'bar' - subject.right 'bar' - - assert_equal %w[ bottom bottom_left bottom_right left right top top_left top_right ], - subject.to_hash[:geo_bounding_box][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:geo_bounding_box][:foo][:top_left] - end - - should "take a block" do - subject = GeoBoundingBox.new :foo do - top_left [0,1] - bottom_right [3,2] - end - - assert_equal({geo_bounding_box: { foo: { top_left: [0,1], bottom_right: [3,2] } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/geo_distance_range_test.rb b/elasticsearch-dsl/test/unit/filters/geo_distance_range_test.rb deleted file mode 100644 index 16a9a67c16..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geo_distance_range_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeoDistanceRangeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeoDistanceRange filter" do - subject { GeoDistanceRange.new } - - should "be converted to a Hash" do - assert_equal({ geo_distance_range: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeoDistanceRange.new :foo - - subject.lat 'bar' - subject.lon 'bar' - - assert_equal %w[ lat lon ], - subject.to_hash[:geo_distance_range][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:geo_distance_range][:foo][:lat] - end - - should "take a block" do - subject = GeoDistanceRange.new :foo do - lat 40 - lon -70 - end - assert_equal({geo_distance_range: { foo: { lat: 40, lon: -70 } } }, subject.to_hash) - end - - should "take a Hash" do - subject = GeoDistanceRange.new from: '10km', to: '20km', foo: { lat: 40, lon: -70 } - assert_equal({geo_distance_range: { foo: { lat: 40, lon: -70 }, from: '10km', to: '20km' }}, subject.to_hash) - end - - should "take options" do - subject = GeoDistanceRange.new :foo, from: '10km', to: '20km' do - lat 40 - lon -70 - end - assert_equal({geo_distance_range: { foo: { lat: 40, lon: -70 }, from: '10km', to: '20km' }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/geo_distance_test.rb b/elasticsearch-dsl/test/unit/filters/geo_distance_test.rb deleted file mode 100644 index f65edc5c0f..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geo_distance_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeoDistanceTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeoDistance filter" do - subject { GeoDistance.new } - - should "be converted to a Hash" do - assert_equal({ geo_distance: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeoDistance.new :foo - - subject.distance 'bar' - subject.distance_type 'bar' - subject.lat 'bar' - subject.lon 'bar' - - assert_equal %w[ distance distance_type foo ], - subject.to_hash[:geo_distance].keys.map(&:to_s).sort - assert_equal %w[ lat lon ], - subject.to_hash[:geo_distance][:foo].keys.map(&:to_s).sort - - assert_equal 'bar', subject.to_hash[:geo_distance][:distance] - assert_equal 'bar', subject.to_hash[:geo_distance][:foo][:lat] - end - - should "take a block" do - subject = GeoDistance.new :foo do - distance '1km' - lat 40 - lon -70 - end - assert_equal({geo_distance: { distance: '1km', foo: { lat: 40, lon: -70 } }}, subject.to_hash) - end - - should "take a Hash" do - subject = GeoDistance.new distance: '10km', foo: { lat: 40, lon: -70 } - assert_equal({geo_distance: { foo: { lat: 40, lon: -70 }, distance: '10km' }}, subject.to_hash) - end - - should "take options" do - subject = GeoDistance.new :foo, distance: '10km' do - lat 40 - lon -70 - end - assert_equal({geo_distance: { foo: { lat: 40, lon: -70 }, distance: '10km' }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/geo_polygon_test.rb b/elasticsearch-dsl/test/unit/filters/geo_polygon_test.rb deleted file mode 100644 index 0845b9e87a..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geo_polygon_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeoPolygonTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeoPolygon filter" do - subject { GeoPolygon.new } - - should "be converted to a Hash" do - assert_equal({ geo_polygon: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeoPolygon.new :foo - - subject.points 'bar' - - assert_equal %w[ points ], - subject.to_hash[:geo_polygon][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:geo_polygon][:foo][:points] - end - - should "take a block" do - subject = GeoPolygon.new :foo do - points 'bar' - end - assert_equal({geo_polygon: { foo: { points: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/geo_shape_test.rb b/elasticsearch-dsl/test/unit/filters/geo_shape_test.rb deleted file mode 100644 index 7cbe182ec1..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geo_shape_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeoShapeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeoShape filter" 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/filters/geohash_cell_test.rb b/elasticsearch-dsl/test/unit/filters/geohash_cell_test.rb deleted file mode 100644 index 3bfa244794..0000000000 --- a/elasticsearch-dsl/test/unit/filters/geohash_cell_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class GeohashCellTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "GeohashCell filter" do - subject { GeohashCell.new } - - should "be converted to a Hash" do - assert_equal({ geohash_cell: {} }, subject.to_hash) - end - - should "have option methods" do - subject = GeohashCell.new :foo - - subject.precision 'bar' - subject.neighbors 'bar' - subject.lat 'bar' - subject.lon 'bar' - - assert_equal %w[ foo neighbors precision ], - subject.to_hash[:geohash_cell].keys.map(&:to_s).sort - assert_equal %w[ lat lon ], - subject.to_hash[:geohash_cell][:foo].keys.map(&:to_s).sort - - assert_equal 'bar', subject.to_hash[:geohash_cell][:precision] - assert_equal 'bar', subject.to_hash[:geohash_cell][:foo][:lat] - end - - should "take a block" do - subject = GeohashCell.new :foo do - lat 'bar' - end - assert_equal({geohash_cell: { foo: { lat: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/has_child_test.rb b/elasticsearch-dsl/test/unit/filters/has_child_test.rb deleted file mode 100644 index d28363e67f..0000000000 --- a/elasticsearch-dsl/test/unit/filters/has_child_test.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class HasChildTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "HasChild filter" 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.filter 'bar' - subject.min_children 'bar' - subject.max_children 'bar' - subject.inner_hits({ size: 1 }) - - assert_equal %w[ filter inner_hits max_children min_children query type ], - subject.to_hash[:has_child].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:has_child][:type] - assert_equal({ size: 1 }, subject.to_hash[:has_child][:inner_hits]) - end - - should "take a block" do - subject = HasChild.new do - type 'bar' - end - assert_equal({has_child: { type: '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/filters/has_parent_test.rb b/elasticsearch-dsl/test/unit/filters/has_parent_test.rb deleted file mode 100644 index 7520d18451..0000000000 --- a/elasticsearch-dsl/test/unit/filters/has_parent_test.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class HasParentTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "HasParent filter" 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.filter 'bar' - subject.query 'bar' - subject.score_mode 'bar' - subject.inner_hits({ size: 1 }) - - assert_equal %w[ filter inner_hits 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] - assert_equal({ size: 1 }, subject.to_hash[:has_parent][:inner_hits]) - 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 - - should "take a block for option method" do - subject = HasParent.new do - parent_type 'bar' - query do - match :foo do - query 'bar' - end - end - end - assert_equal({ has_parent: { parent_type: 'bar', query: { match: { foo: { query: 'bar'} } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/ids_test.rb b/elasticsearch-dsl/test/unit/filters/ids_test.rb deleted file mode 100644 index bc5c2bbd14..0000000000 --- a/elasticsearch-dsl/test/unit/filters/ids_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class IdsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Ids filter" 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/filters/indices_test.rb b/elasticsearch-dsl/test/unit/filters/indices_test.rb deleted file mode 100644 index c9679df3d9..0000000000 --- a/elasticsearch-dsl/test/unit/filters/indices_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class IndicesTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Indices filter" 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.filter 'bar' - subject.no_match_filter 'bar' - - assert_equal %w[ filter indices no_match_filter ], - 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' - end - assert_equal({indices: { indices: 'bar' } }, subject.to_hash) - end - - should "take a block for methods" do - subject = Indices.new do - indices 'bar' - - filter do - term foo: 'bar' - end - no_match_filter do - term foo: 'bam' - end - end - assert_equal({ indices: { indices: 'bar', filter: { term: { foo: 'bar' } }, no_match_filter: { term: { foo: 'bar' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/limit_test.rb b/elasticsearch-dsl/test/unit/filters/limit_test.rb deleted file mode 100644 index eccca6c3da..0000000000 --- a/elasticsearch-dsl/test/unit/filters/limit_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class LimitTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Limit filter" do - subject { Limit.new } - - should "be converted to a Hash" do - assert_equal({ limit: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Limit.new - - subject.value 'bar' - - assert_equal %w[ value ], - subject.to_hash[:limit].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:limit][:value] - end - - should "take a block" do - subject = Limit.new do - value 'bar' - end - assert_equal({limit: { value: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/match_all_test.rb b/elasticsearch-dsl/test/unit/filters/match_all_test.rb deleted file mode 100644 index 58db4cabd0..0000000000 --- a/elasticsearch-dsl/test/unit/filters/match_all_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class MatchAllTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "MatchAll filter" do - subject { MatchAll.new } - - should "be converted to a Hash" do - assert_equal({ match_all: {} }, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/missing_test.rb b/elasticsearch-dsl/test/unit/filters/missing_test.rb deleted file mode 100644 index 3fd15c87b4..0000000000 --- a/elasticsearch-dsl/test/unit/filters/missing_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class MissingTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Missing filter" do - subject { Missing.new } - - should "be converted to a Hash" do - assert_equal({ missing: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Missing.new - - subject.field 'bar' - subject.existence 'bar' - subject.null_value 'bar' - - assert_equal %w[ existence field null_value ], - subject.to_hash[:missing].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:missing][:field] - end - - should "take a block" do - subject = Missing.new do - field 'bar' - end - assert_equal({missing: { field: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/nested_test.rb b/elasticsearch-dsl/test/unit/filters/nested_test.rb deleted file mode 100644 index bd80adcb0d..0000000000 --- a/elasticsearch-dsl/test/unit/filters/nested_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class NestedTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Nested filter" 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.query 'bar' - subject.filter 'bar' - - assert_equal %w[ filter path query ], - subject.to_hash[:nested].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:nested][:path] - end - - should "take a block" do - subject = Nested.new do - path 'bar' - filter do - term foo: 'bar' - end - end - assert_equal({nested: { path: 'bar', filter: { term: { foo: 'bar' } } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/not_test.rb b/elasticsearch-dsl/test/unit/filters/not_test.rb deleted file mode 100644 index 98e04bf21d..0000000000 --- a/elasticsearch-dsl/test/unit/filters/not_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class NotTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Not filter" do - subject { Not.new } - - should "be converted to a Hash" do - assert_equal({ not: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Not.new filters: [ { term: { foo: 'bar' } } ] - assert_equal({ not: { filters: [ { term: { foo: 'bar' } } ] } }, subject.to_hash) - end - - should "take a block" do - subject = Not.new do - term foo: 'bar' - end - assert_equal({not: {term: { foo: 'bar'}} }, subject.to_hash) - end - - should "raise an exception for unknown DSL method" do - assert_raise(NoMethodError) { subject.foofoo } - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/or_test.rb b/elasticsearch-dsl/test/unit/filters/or_test.rb deleted file mode 100644 index 10656803a6..0000000000 --- a/elasticsearch-dsl/test/unit/filters/or_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class OrTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Or filter" do - subject { Or.new } - - should "be converted to a Hash" do - assert_equal({ or: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Or.new filters: [ { term: { foo: 'bar' } } ] - assert_equal({ or: { filters: [ { term: { foo: 'bar' } } ] } }, subject.to_hash) - end - - should "take a block" do - subject = Or.new do - term foo: 'bar' - term moo: 'mam' - end - assert_equal({or: [ {term: { foo: 'bar'}}, {term: { moo: 'mam'}} ]}, subject.to_hash) - end - - should "behave like an Enumerable" do - subject = Or.new - subject << { term: { foo: 'bar' } } - - assert_equal 1, subject.size - assert subject.any? { |d| d[:term] == { foo: 'bar' } } - end - - should "behave like an Array" do - subject = Or.new - - assert subject.empty? - - subject << { term: { foo: 'bar' } } - subject << { term: { moo: 'xam' } } - - assert ! subject.empty? - - assert_equal({ or: [ { term: { foo: 'bar' } }, { term: { moo: 'xam' } } ] }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/prefix_test.rb b/elasticsearch-dsl/test/unit/filters/prefix_test.rb deleted file mode 100644 index 9c0b2a83af..0000000000 --- a/elasticsearch-dsl/test/unit/filters/prefix_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class PrefixTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Prefix filter" do - subject { Prefix.new } - - should "be converted to a Hash" do - assert_equal({ prefix: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Prefix.new foo: 'bar' - - assert_equal({ prefix: { foo: 'bar' } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/query_test.rb b/elasticsearch-dsl/test/unit/filters/query_test.rb deleted file mode 100644 index 3516588773..0000000000 --- a/elasticsearch-dsl/test/unit/filters/query_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class QueryTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Query filter" do - subject { Query.new } - - should "be converted to a Hash" do - assert_equal({ query: {} }, subject.to_hash) - end - - should "take a Hash" do - subject = Query.new query_string: { query: 'foo' } - - assert_equal({ query: { query_string: { query: 'foo' } } }, subject.to_hash) - end - - should "take a block" do - subject = Query.new do - match foo: 'bar' - end - - assert_equal({ query: { match: { foo: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/range_test.rb b/elasticsearch-dsl/test/unit/filters/range_test.rb deleted file mode 100644 index 67c5745e48..0000000000 --- a/elasticsearch-dsl/test/unit/filters/range_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class RangeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Range filter" do - subject { Range.new } - - should "be converted to a Hash" do - assert_equal({ range: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Range.new :foo - - subject.gte 'bar' - subject.lte 'bar' - subject.time_zone 'bar' - subject.format 'bar' - - assert_equal %w[ format gte lte time_zone ], - subject.to_hash[:range][:foo].keys.map(&:to_s).sort - - assert_equal 'bar', subject.to_hash[:range][:foo][:gte] - end - - 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 - end - - assert_equal({ range: { age: { gte: 10, lte: 20 } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/regexp_test.rb b/elasticsearch-dsl/test/unit/filters/regexp_test.rb deleted file mode 100644 index e5b9553408..0000000000 --- a/elasticsearch-dsl/test/unit/filters/regexp_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class RegexpTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Regexp filter" 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.flags 'bar' - - assert_equal %w[ 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 'b*r' - end - assert_equal({regexp: { foo: { value: 'b*r' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/script_test.rb b/elasticsearch-dsl/test/unit/filters/script_test.rb deleted file mode 100644 index 7a604bb28e..0000000000 --- a/elasticsearch-dsl/test/unit/filters/script_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class ScriptTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Script filter" do - subject { Script.new } - - should "be converted to a Hash" do - assert_equal({ script: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Script.new :foo - - subject.script 'bar' - subject.params foo: 'bar' - - assert_equal %w[ params script ], - subject.to_hash[:script][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:script][:foo][:script] - assert_equal 'bar', subject.to_hash[:script][:foo][:params][:foo] - end - - should "take a block" do - subject = Script.new :foo do - script 'bar' - end - assert_equal({script: { foo: { script: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/filters/term_test.rb b/elasticsearch-dsl/test/unit/filters/term_test.rb deleted file mode 100644 index 5450386862..0000000000 --- a/elasticsearch-dsl/test/unit/filters/term_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class TermTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - subject { Term.new message: 'test' } - - context "Term Filter" 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/filters/terms_test.rb b/elasticsearch-dsl/test/unit/filters/terms_test.rb deleted file mode 100644 index 3f2607ca2d..0000000000 --- a/elasticsearch-dsl/test/unit/filters/terms_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class TermsTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Terms filter" do - subject { Terms.new } - - should "be converted to a Hash" do - assert_equal({ terms: {} }, subject.to_hash) - end - - should "be 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/filters/type_test.rb b/elasticsearch-dsl/test/unit/filters/type_test.rb deleted file mode 100644 index e2e02ab11d..0000000000 --- a/elasticsearch-dsl/test/unit/filters/type_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Filters - class TypeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Filters - - context "Type filter" do - subject { Type.new } - - should "be converted to a Hash" do - assert_equal({ type: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Type.new :foo - - subject.value 'bar' - - assert_equal %w[ value ], - subject.to_hash[:type][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:type][:foo][:value] - end - - should "take a block" do - subject = Type.new :foo do - value 'bar' - end - assert_equal({type: { foo: { value: 'bar' } }}, subject.to_hash) - end - end - end - end - end -end