From efa463992d4cbb7046fe94cdf569fd5e5f097d6b Mon Sep 17 00:00:00 2001 From: Emily Stolfo Date: Mon, 5 Nov 2018 12:22:43 +0100 Subject: [PATCH] [DSL] Convert aggregations/pipeline tests to rspec --- elasticsearch-dsl/Gemfile | 5 + elasticsearch-dsl/Rakefile | 5 + .../spec/aggregations/pipeline/avg_spec.rb | 71 +++++++++++ .../pipeline/bucket_script_spec.rb | 82 +++++++++++++ .../pipeline/bucket_selector_spec.rb | 71 +++++++++++ .../pipeline/cumulative_sum_spec.rb | 60 +++++++++ .../aggregations/pipeline/derivative_spec.rb | 71 +++++++++++ .../pipeline/extended_stats_bucket_spec.rb | 71 +++++++++++ .../aggregations/pipeline/max_bucket_spec.rb | 71 +++++++++++ .../aggregations/pipeline/min_bucket_spec.rb | 71 +++++++++++ .../pipeline/moving_avg_test_spec.rb | 115 ++++++++++++++++++ .../pipeline/percentiles_bucket_spec.rb | 82 +++++++++++++ .../aggregations/pipeline/serial_diff_spec.rb | 82 +++++++++++++ .../pipeline/stats_bucket_spec.rb | 71 +++++++++++ .../aggregations/pipeline/sum_bucket_spec.rb | 71 +++++++++++ elasticsearch-dsl/spec/spec_helper.rb | 7 ++ .../aggregations/pipeline/avg_bucket_test.rb | 39 ------ .../pipeline/bucket_script_test.rb | 39 ------ .../pipeline/bucket_selector_test.rb | 38 ------ .../pipeline/cumulative_sum_test.rb | 37 ------ .../aggregations/pipeline/derivative_test.rb | 39 ------ .../pipeline/extended_stats_bucket_test.rb | 38 ------ .../aggregations/pipeline/max_bucket_test.rb | 38 ------ .../aggregations/pipeline/min_bucket_test.rb | 38 ------ .../aggregations/pipeline/moving_avg_test.rb | 41 ------- .../pipeline/percentiles_bucket_test.rb | 39 ------ .../aggregations/pipeline/serial_diff_test.rb | 39 ------ .../pipeline/stats_bucket_test.rb | 38 ------ .../aggregations/pipeline/sum_bucket_test.rb | 38 ------ 29 files changed, 1006 insertions(+), 501 deletions(-) create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/avg_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/bucket_script_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/bucket_selector_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/cumulative_sum_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/derivative_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/extended_stats_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/max_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/min_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/moving_avg_test_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/percentiles_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/serial_diff_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/stats_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/aggregations/pipeline/sum_bucket_spec.rb create mode 100644 elasticsearch-dsl/spec/spec_helper.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/avg_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_script_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_selector_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/cumulative_sum_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/derivative_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/max_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/min_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/moving_avg_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/percentiles_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/serial_diff_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/stats_bucket_test.rb delete mode 100644 elasticsearch-dsl/test/unit/aggregations/pipeline/sum_bucket_test.rb diff --git a/elasticsearch-dsl/Gemfile b/elasticsearch-dsl/Gemfile index 2665ffba75..e52df375a1 100644 --- a/elasticsearch-dsl/Gemfile +++ b/elasticsearch-dsl/Gemfile @@ -18,3 +18,8 @@ end if File.exist? File.expand_path("../../elasticsearch-extensions", __FILE__) gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => false end + +group :development do + gem 'rspec' + gem 'pry-nav' +end diff --git a/elasticsearch-dsl/Rakefile b/elasticsearch-dsl/Rakefile index 97d9db6cdd..a867d0e97c 100644 --- a/elasticsearch-dsl/Rakefile +++ b/elasticsearch-dsl/Rakefile @@ -6,11 +6,16 @@ task :test => 'test:unit' # ----- Test tasks ------------------------------------------------------------ require 'rake/testtask' +require 'rspec/core/rake_task' + namespace :test do + RSpec::Core::RakeTask.new(:spec) + Rake::TestTask.new(:unit) do |test| test.libs << 'lib' << 'test' test.test_files = FileList["test/unit/**/*_test.rb"] + test.deps = [ :spec ] test.verbose = false test.warning = false end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/avg_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/avg_spec.rb new file mode 100644 index 0000000000..7ed508b241 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/avg_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::AvgBucket 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(avg_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:avg_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('skip') + end + + it 'applies the option' do + expect(search.to_hash[:avg_bucket][:foo][:gap_policy]).to eq('skip') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:avg_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ avg_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/bucket_script_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/bucket_script_spec.rb new file mode 100644 index 0000000000..7992cfd9f2 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/bucket_script_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::BucketScript 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(bucket_script: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_script][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#script' do + + before do + search.script('bar') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_script][:foo][:script]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('skip') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_script][:foo][:gap_policy]).to eq('skip') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_script][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ bucket_script: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/bucket_selector_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/bucket_selector_spec.rb new file mode 100644 index 0000000000..3aecf6ee5b --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/bucket_selector_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::BucketSelector 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(bucket_selector: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_selector][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#script' do + + before do + search.script('bar') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_selector][:foo][:script]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('skip') + end + + it 'applies the option' do + expect(search.to_hash[:bucket_selector][:foo][:gap_policy]).to eq('skip') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + gap_policy 'skip' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ bucket_selector: { foo: { gap_policy: 'skip' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/cumulative_sum_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/cumulative_sum_spec.rb new file mode 100644 index 0000000000..2b7db78d53 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/cumulative_sum_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::CumulativeSum 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(cumulative_sum: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:cumulative_sum][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#script' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:cumulative_sum][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ cumulative_sum: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/derivative_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/derivative_spec.rb new file mode 100644 index 0000000000..3d3441abf5 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/derivative_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::Derivative 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(derivative: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:derivative][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:derivative][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#script' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:derivative][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ derivative: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/extended_stats_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/extended_stats_bucket_spec.rb new file mode 100644 index 0000000000..fb573bdc9a --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/extended_stats_bucket_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::ExtendedStatsBucket 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(extended_stats_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:extended_stats_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:extended_stats_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:extended_stats_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ extended_stats_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/max_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/max_bucket_spec.rb new file mode 100644 index 0000000000..9bd65d02ae --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/max_bucket_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::MaxBucket 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(max_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:max_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:max_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:max_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ max_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/min_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/min_bucket_spec.rb new file mode 100644 index 0000000000..6f6b6cf9fd --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/min_bucket_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::MinBucket 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(min_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:min_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:min_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:min_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ min_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/moving_avg_test_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/moving_avg_test_spec.rb new file mode 100644 index 0000000000..3991e0fa0f --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/moving_avg_test_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::MovingAvg 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(moving_avg: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#minimize' do + + before do + search.minimize(false) + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:minimize]).to eq(false) + end + end + + describe '#model' do + + before do + search.model('simple') + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:model]).to eq('simple') + end + end + + describe '#settings' do + + before do + search.settings(period: 7) + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:settings]).to eq(period: 7) + end + end + + describe '#window' do + + before do + search.window(5) + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:window]).to eq(5) + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:moving_avg][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ moving_avg: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/percentiles_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/percentiles_bucket_spec.rb new file mode 100644 index 0000000000..d1c201a806 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/percentiles_bucket_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::PercentilesBucket 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(percentiles_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:percentiles_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:percentiles_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:percentiles_bucket][:foo][:format]).to eq('bar') + end + end + + describe '#percents' do + + before do + search.percents([ 1, 5, 25, 50, 75, 95, 99 ]) + end + + it 'applies the option' do + expect(search.to_hash[:percentiles_bucket][:foo][:percents]).to eq([ 1, 5, 25, 50, 75, 95, 99 ]) + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ percentiles_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/serial_diff_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/serial_diff_spec.rb new file mode 100644 index 0000000000..9d2be1a1c1 --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/serial_diff_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::SerialDiff 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(serial_diff: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:serial_diff][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#lag' do + + before do + search.lag(1) + end + + it 'applies the option' do + expect(search.to_hash[:serial_diff][:foo][:lag]).to eq(1) + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:serial_diff][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:serial_diff][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ serial_diff: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/stats_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/stats_bucket_spec.rb new file mode 100644 index 0000000000..64a7af556d --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/stats_bucket_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::StatsBucket 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(stats_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:stats_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:stats_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:stats_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ stats_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/aggregations/pipeline/sum_bucket_spec.rb b/elasticsearch-dsl/spec/aggregations/pipeline/sum_bucket_spec.rb new file mode 100644 index 0000000000..9393905e2d --- /dev/null +++ b/elasticsearch-dsl/spec/aggregations/pipeline/sum_bucket_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Elasticsearch::DSL::Search::Aggregations::SumBucket 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(sum_bucket: {}) + end + end + + context 'when options methods are called' do + + let(:search) do + described_class.new(:foo) + end + + describe '#buckets_path' do + + before do + search.buckets_path('bar') + end + + it 'applies the option' do + expect(search.to_hash[:sum_bucket][:foo][:buckets_path]).to eq('bar') + end + end + + describe '#gap_policy' do + + before do + search.gap_policy('bar') + end + + it 'applies the option' do + expect(search.to_hash[:sum_bucket][:foo][:gap_policy]).to eq('bar') + end + end + + describe '#format' do + + before do + search.format('bar') + end + + it 'applies the option' do + expect(search.to_hash[:sum_bucket][:foo][:format]).to eq('bar') + end + end + end + + describe '#initialize' do + + context 'when a block is provided' do + + let(:search) do + described_class.new(:foo) do + format 'bar' + end + end + + it 'executes the block' do + expect(search.to_hash).to eq({ sum_bucket: { foo: { format: 'bar' } } }) + end + end + end +end diff --git a/elasticsearch-dsl/spec/spec_helper.rb b/elasticsearch-dsl/spec/spec_helper.rb new file mode 100644 index 0000000000..a94be7cab7 --- /dev/null +++ b/elasticsearch-dsl/spec/spec_helper.rb @@ -0,0 +1,7 @@ +require 'elasticsearch' +require 'elasticsearch-dsl' + +RSpec.configure do |config| + config.formatter = 'documentation' + config.color = true +end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/avg_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/avg_bucket_test.rb deleted file mode 100644 index d3907677d8..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/avg_bucket_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class AvgBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Avg Bucket agg" do - subject { AvgBucket.new } - - should "be converted to a hash" do - assert_equal({ avg_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = AvgBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:avg_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:avg_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = AvgBucket.new :foo do - format 'bar' - end - assert_equal({avg_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_script_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_script_test.rb deleted file mode 100644 index d40a152203..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_script_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class BucketScriptTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Bucket Script agg" do - subject { BucketScript.new } - - should "be converted to a hash" do - assert_equal({ bucket_script: {} }, subject.to_hash) - end - - should "have option methods" do - subject = BucketScript.new :foo - - subject.buckets_path foo: 'foo', bar: 'bar' - subject.script 'bar' - subject.gap_policy 'skip' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy script ], - subject.to_hash[:bucket_script][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:bucket_script][:foo][:buckets_path][:bar] - end - - should "take a block" do - subject = BucketScript.new :foo do - format 'bar' - end - assert_equal({bucket_script: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_selector_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_selector_test.rb deleted file mode 100644 index cb29e78df5..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/bucket_selector_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class BucketSelectorTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Bucket Selector agg" do - subject { BucketSelector.new } - - should "be converted to a hash" do - assert_equal({ bucket_selector: {} }, subject.to_hash) - end - - should "have option methods" do - subject = BucketSelector.new :foo - - subject.buckets_path foo: 'foo', bar: 'bar' - subject.script 'bar' - subject.gap_policy 'skip' - - assert_equal %w[ buckets_path gap_policy script ], - subject.to_hash[:bucket_selector][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:bucket_selector][:foo][:buckets_path][:bar] - end - - should "take a block" do - subject = BucketSelector.new :foo do - gap_policy 'skip' - end - assert_equal({bucket_selector: { foo: { gap_policy: 'skip' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/cumulative_sum_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/cumulative_sum_test.rb deleted file mode 100644 index 60143918e8..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/cumulative_sum_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class CumulativeSumTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Cumulative Sum Bucket agg" do - subject { CumulativeSum.new } - - should "be converted to a hash" do - assert_equal({ cumulative_sum: {} }, subject.to_hash) - end - - should "have option methods" do - subject = CumulativeSum.new :foo - - subject.buckets_path 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format ], - subject.to_hash[:cumulative_sum][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:cumulative_sum][:foo][:buckets_path] - end - - should "take a block" do - subject = CumulativeSum.new :foo do - format 'bar' - end - assert_equal({cumulative_sum: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/derivative_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/derivative_test.rb deleted file mode 100644 index ff766b7590..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/derivative_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class DerivativeTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Derivative agg" do - subject { Derivative.new } - - should "be converted to a hash" do - assert_equal({ derivative: {} }, subject.to_hash) - end - - should "have option methods" do - subject = Derivative.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:derivative][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:derivative][:foo][:buckets_path] - end - - should "take a block" do - subject = Derivative.new :foo do - format 'bar' - end - assert_equal({derivative: { foo: { format: 'bar' } } }, subject.to_hash) - end - - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb deleted file mode 100644 index e137ee7349..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class ExtendedStatsBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Extended Stats Bucket agg" do - subject { ExtendedStatsBucket.new } - - should "be converted to a hash" do - assert_equal({ extended_stats_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = ExtendedStatsBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'skip' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:extended_stats_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:extended_stats_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = ExtendedStatsBucket.new :foo do - format 'bar' - end - assert_equal({extended_stats_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/max_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/max_bucket_test.rb deleted file mode 100644 index b1d4b7e643..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/max_bucket_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class MaxBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Max Bucket agg" do - subject { MaxBucket.new } - - should "be converted to a hash" do - assert_equal({ max_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MaxBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:max_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:max_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = MaxBucket.new :foo do - format 'bar' - end - assert_equal({max_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/min_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/min_bucket_test.rb deleted file mode 100644 index 0dc4b8a76d..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/min_bucket_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class MinBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Min Bucket agg" do - subject { MinBucket.new } - - should "be converted to a hash" do - assert_equal({ min_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MinBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:min_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:min_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = MinBucket.new :foo do - format 'bar' - end - assert_equal({min_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/moving_avg_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/moving_avg_test.rb deleted file mode 100644 index 9c8a64939b..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/moving_avg_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class MovingAvgTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Moving Average Bucket agg" do - subject { MovingAvg.new } - - should "be converted to a hash" do - assert_equal({ moving_avg: {} }, subject.to_hash) - end - - should "have option methods" do - subject = MovingAvg.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'skip' - subject.minimize false - subject.model 'simple' - subject.settings({ period: 7 }) - subject.window 5 - - assert_equal %w[ buckets_path gap_policy minimize model settings window ], - subject.to_hash[:moving_avg][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:moving_avg][:foo][:buckets_path] - end - - should "take a block" do - subject = MovingAvg.new :foo do - format 'bar' - end - assert_equal({moving_avg: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/percentiles_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/percentiles_bucket_test.rb deleted file mode 100644 index 994d19febb..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/percentiles_bucket_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class PercentilesBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Percentiles Bucket agg" do - subject { PercentilesBucket.new } - - should "be converted to a hash" do - assert_equal({ percentiles_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = PercentilesBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'skip' - subject.format 'bar' - subject.percents [ 1, 5, 25, 50, 75, 95, 99 ] - - assert_equal %w[ buckets_path format gap_policy percents ], - subject.to_hash[:percentiles_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:percentiles_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = PercentilesBucket.new :foo do - format 'bar' - end - assert_equal({percentiles_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/serial_diff_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/serial_diff_test.rb deleted file mode 100644 index 4633fa5127..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/serial_diff_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class SerialDiffTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Serial Defferencing agg" do - subject { SerialDiff.new } - - should "be converted to a hash" do - assert_equal({ serial_diff: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SerialDiff.new :foo - - subject.buckets_path 'bar' - subject.lag 1 - subject.gap_policy 'skip' - subject.format 'foo' - - assert_equal %w[ buckets_path format gap_policy lag ], - subject.to_hash[:serial_diff][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:serial_diff][:foo][:buckets_path] - end - - should "take a block" do - subject = SerialDiff.new :foo do - gap_policy 'skip' - end - assert_equal({serial_diff: { foo: { gap_policy: 'skip' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/stats_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/stats_bucket_test.rb deleted file mode 100644 index 494e00b016..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/stats_bucket_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class StatsBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Stats Bucket agg" do - subject { StatsBucket.new } - - should "be converted to a hash" do - assert_equal({ stats_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = StatsBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:stats_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:stats_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = StatsBucket.new :foo do - format 'bar' - end - assert_equal({stats_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end diff --git a/elasticsearch-dsl/test/unit/aggregations/pipeline/sum_bucket_test.rb b/elasticsearch-dsl/test/unit/aggregations/pipeline/sum_bucket_test.rb deleted file mode 100644 index fe351bc3ac..0000000000 --- a/elasticsearch-dsl/test/unit/aggregations/pipeline/sum_bucket_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'test_helper' - -module Elasticsearch - module Test - module Aggregations - class SumBucketTest < ::Elasticsearch::Test::UnitTestCase - include Elasticsearch::DSL::Search::Aggregations - - context "Sum Bucket agg" do - subject { SumBucket.new } - - should "be converted to a hash" do - assert_equal({ sum_bucket: {} }, subject.to_hash) - end - - should "have option methods" do - subject = SumBucket.new :foo - - subject.buckets_path 'bar' - subject.gap_policy 'bar' - subject.format 'bar' - - assert_equal %w[ buckets_path format gap_policy ], - subject.to_hash[:sum_bucket][:foo].keys.map(&:to_s).sort - assert_equal 'bar', subject.to_hash[:sum_bucket][:foo][:buckets_path] - end - - should "take a block" do - subject = SumBucket.new :foo do - format 'bar' - end - assert_equal({sum_bucket: { foo: { format: 'bar' } } }, subject.to_hash) - end - end - end - end - end -end