esearch 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.travis.yml +2 -5
  4. data/Changelog.md +5 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.devtools +22 -18
  7. data/config/flay.yml +2 -2
  8. data/config/reek.yml +5 -4
  9. data/config/rubocop.yml +81 -0
  10. data/esearch.gemspec +7 -7
  11. data/lib/esearch.rb +3 -1
  12. data/lib/esearch/cluster.rb +6 -5
  13. data/lib/esearch/command.rb +15 -7
  14. data/lib/esearch/command/cluster.rb +6 -4
  15. data/lib/esearch/command/document.rb +13 -13
  16. data/lib/esearch/command/exist.rb +6 -4
  17. data/lib/esearch/command/index.rb +7 -5
  18. data/lib/esearch/command/search.rb +5 -4
  19. data/lib/esearch/command/status.rb +5 -3
  20. data/lib/esearch/connection.rb +4 -3
  21. data/lib/esearch/document.rb +4 -2
  22. data/lib/esearch/index.rb +4 -2
  23. data/lib/esearch/indices.rb +8 -6
  24. data/lib/esearch/mixin.rb +8 -6
  25. data/lib/esearch/presenter.rb +5 -3
  26. data/lib/esearch/presenter/aspect.rb +5 -3
  27. data/lib/esearch/presenter/aspect/range.rb +11 -9
  28. data/lib/esearch/presenter/aspect/term.rb +6 -4
  29. data/lib/esearch/presenter/cluster.rb +6 -4
  30. data/lib/esearch/presenter/document.rb +12 -10
  31. data/lib/esearch/presenter/facet.rb +9 -9
  32. data/lib/esearch/presenter/hit.rb +9 -8
  33. data/lib/esearch/presenter/hits.rb +8 -7
  34. data/lib/esearch/presenter/index.rb +9 -7
  35. data/lib/esearch/presenter/search.rb +7 -5
  36. data/lib/esearch/presenter/status.rb +6 -4
  37. data/lib/esearch/request.rb +5 -3
  38. data/lib/esearch/type.rb +5 -2
  39. data/spec/integration/esearch/spike_spec.rb +15 -10
  40. data/spec/spec_helper.rb +6 -5
  41. data/spec/support/example_group_methods.rb +2 -0
  42. data/spec/support/ice_nine_config.rb +2 -0
  43. data/spec/unit/esearch/cluster_spec.rb +59 -0
  44. data/spec/unit/esearch/command/class_methods/run_spec.rb +3 -1
  45. data/spec/unit/esearch/command/cluster/health/run_spec.rb +2 -0
  46. data/spec/unit/esearch/command/document/delete/run_spec.rb +3 -1
  47. data/spec/unit/esearch/command/document/get/result_spec.rb +5 -3
  48. data/spec/unit/esearch/command/document/index/create/run_spec.rb +6 -2
  49. data/spec/unit/esearch/command/document/index/run_create_spec.rb +6 -2
  50. data/spec/unit/esearch/command/document/index/run_spec.rb +3 -1
  51. data/spec/unit/esearch/command/document/index/run_update_spec.rb +6 -2
  52. data/spec/unit/esearch/command/document/index/update/run_spec.rb +6 -2
  53. data/spec/unit/esearch/command/exist/result_spec.rb +5 -3
  54. data/spec/unit/esearch/command/index/create/run_spec.rb +2 -0
  55. data/spec/unit/esearch/command/index/delete/run_spec.rb +3 -1
  56. data/spec/unit/esearch/command/index/refresh/run_spec.rb +3 -1
  57. data/spec/unit/esearch/command/result_spec.rb +17 -7
  58. data/spec/unit/esearch/command/search/run_spec.rb +2 -0
  59. data/spec/unit/esearch/command/status/run_spec.rb +3 -1
  60. data/spec/unit/esearch/connection/class_methods/build_spec.rb +2 -0
  61. data/spec/unit/esearch/connection/run_spec.rb +6 -4
  62. data/spec/unit/esearch/document_spec.rb +44 -0
  63. data/spec/unit/esearch/index_spec.rb +42 -0
  64. data/spec/unit/esearch/indices/all_spec.rb +16 -0
  65. data/spec/unit/esearch/indices_spec.rb +18 -0
  66. data/spec/unit/esearch/mixin/document/index_create_spec.rb +2 -0
  67. data/spec/unit/esearch/mixin/document/index_spec.rb +2 -0
  68. data/spec/unit/esearch/mixin/document/index_update_spec.rb +2 -0
  69. data/spec/unit/esearch/mixin/exist/exist_predicate_spec.rb +2 -0
  70. data/spec/unit/esearch/mixin/index/refresh_spec.rb +2 -0
  71. data/spec/unit/esearch/mixin/index/status_spec.rb +2 -0
  72. data/spec/unit/esearch/mixin/search/search_spec.rb +2 -0
  73. data/spec/unit/esearch/presenter/aspect/range/from_spec.rb +2 -0
  74. data/spec/unit/esearch/presenter/aspect/range/to_spec.rb +2 -0
  75. data/spec/unit/esearch/presenter/class_methods/new_spec.rb +2 -0
  76. data/spec/unit/esearch/presenter/facet_spec.rb +60 -0
  77. data/spec/unit/esearch/presenter/hit/fields_spec.rb +2 -0
  78. data/spec/unit/esearch/presenter/hit/source_spec.rb +2 -0
  79. data/spec/unit/esearch/presenter/hits/each_spec.rb +7 -5
  80. data/spec/unit/esearch/presenter/hits/size_spec.rb +5 -3
  81. data/spec/unit/esearch/presenter/search_spec.rb +50 -0
  82. data/spec/unit/esearch/request_spec.rb +96 -0
  83. data/spec/unit/esearch/type_spec.rb +37 -0
  84. metadata +34 -50
  85. data/spec/unit/esearch/cluster/class_methods/connect_spec.rb +0 -16
  86. data/spec/unit/esearch/cluster/health_spec.rb +0 -10
  87. data/spec/unit/esearch/cluster/index_spec.rb +0 -11
  88. data/spec/unit/esearch/cluster/indices_spec.rb +0 -11
  89. data/spec/unit/esearch/cluster/path_spec.rb +0 -11
  90. data/spec/unit/esearch/document/connection_spec.rb +0 -12
  91. data/spec/unit/esearch/document/delete_spec.rb +0 -12
  92. data/spec/unit/esearch/document/get_spec.rb +0 -12
  93. data/spec/unit/esearch/index/create_spec.rb +0 -12
  94. data/spec/unit/esearch/index/delete_spec.rb +0 -11
  95. data/spec/unit/esearch/index/type_spec.rb +0 -12
  96. data/spec/unit/esearch/indices/all/path_spec.rb +0 -12
  97. data/spec/unit/esearch/presenter/facet/build_spec.rb +0 -26
  98. data/spec/unit/esearch/presenter/facet/class_methods/build_spec.rb +0 -26
  99. data/spec/unit/esearch/request/initialize_spec.rb +0 -39
  100. data/spec/unit/esearch/request/run_spec.rb +0 -39
  101. data/spec/unit/esearch/type/connection_spec.rb +0 -15
  102. data/spec/unit/esearch/type/document_spec.rb +0 -12
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Cluster, '.connect' do
4
- subject { object.connect(*arguments) }
5
-
6
- let(:object) { described_class }
7
- let(:connection) { double('Connection') }
8
-
9
- let(:arguments) { [:foo, :bar] }
10
-
11
- before do
12
- Esearch::Connection.should_receive(:build).with(:foo, :bar).and_return(connection)
13
- end
14
-
15
- it { should eql(described_class.new(connection)) }
16
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Cluster, '#health' do
4
- subject { object.health }
5
-
6
- let(:object) { described_class.new(connection) }
7
- let(:expected_arguments) { [{}] }
8
-
9
- expect_to_run_command(Esearch::Command::Cluster::Health)
10
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Cluster, '#index' do
4
- subject { object.index(name) }
5
-
6
- let(:object) { described_class.new(connection) }
7
- let(:connection) { double('Connection') }
8
- let(:name) { 'foo' }
9
-
10
- it { should eql(Esearch::Index.new(connection, name)) }
11
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Cluster, '#indices' do
4
- subject { object.indices(names) }
5
-
6
- let(:object) { described_class.new(connection) }
7
- let(:connection) { double('Connection') }
8
- let(:names) { %w(foo bar) }
9
-
10
- it { should eql(Esearch::Indices.new(connection, names)) }
11
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Cluster, '#path' do
4
- subject { object.path }
5
-
6
- let(:object) { described_class.new(connection) }
7
-
8
- let(:connection) { double('Connection') }
9
-
10
- it { should eql(Pathname.new('/')) }
11
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Document, '#connection' do
4
- subject { object.connection }
5
-
6
- let(:object) { described_class.new(type, id) }
7
- let(:type) { double('Type', :connection => connection) }
8
- let(:connection) { double('Connection') }
9
- let(:id) { '1' }
10
-
11
- it { should be(connection) }
12
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Document, '#delete' do
4
- subject { object.delete}
5
-
6
- let(:object) { described_class.new(type, id) }
7
- let(:type) { double('Type') }
8
- let(:id) { '1' }
9
- let(:expected_arguments) { [] }
10
-
11
- expect_to_run_command(Esearch::Command::Document::Delete)
12
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Document, '#get' do
4
- subject { object.get}
5
-
6
- let(:object) { described_class.new(type, id) }
7
- let(:type) { double('Type') }
8
- let(:id) { '1' }
9
- let(:expected_arguments) { [] }
10
-
11
- expect_to_run_command(Esearch::Command::Document::Get)
12
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Index, '#create' do
4
- subject { object.create(settings) }
5
-
6
- let(:object) { described_class.new(connection, index_name) }
7
- let(:index_name) { 'foo' }
8
- let(:settings) { { :my => :settings } }
9
- let(:expected_arguments) { [settings] }
10
-
11
- expect_to_run_command(Esearch::Command::Index::Create)
12
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Index, '#delete' do
4
- subject { object.delete }
5
-
6
- let(:object) { described_class.new(connection, index_name) }
7
- let(:index_name) { 'foo' }
8
- let(:expected_arguments) { [] }
9
-
10
- expect_to_run_command(Esearch::Command::Index::Delete)
11
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Index, '#type' do
4
- subject { object.type(name) }
5
-
6
- let(:object) { described_class.new(connection, index_name) }
7
- let(:connection) { double('Connection') }
8
- let(:index_name) { 'foo' }
9
- let(:name) { 'bar' }
10
-
11
- it { should eql(Esearch::Type.new(object, name)) }
12
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Indices::All, '#path' do
4
- subject { object.path }
5
-
6
- let(:object) { described_class.new(connection) }
7
- let(:connection) { double('Connection') }
8
-
9
- it { should eql(Pathname.new('/_all')) }
10
-
11
- it_should_behave_like 'an idempotent method'
12
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Presenter::Facet, '.build' do
4
- subject { object.build(raw) }
5
-
6
- let(:object) { described_class }
7
-
8
- context 'when type is "terms"' do
9
- let(:raw) { { '_type' => 'terms' } }
10
- it { should eql(Esearch::Presenter::Facet::Terms.new(raw)) }
11
- end
12
-
13
- context 'when type is "range"' do
14
- let(:raw) { { '_type' => 'range' } }
15
- it { should eql(Esearch::Presenter::Facet::Range.new(raw)) }
16
- end
17
-
18
- context 'with unknown type' do
19
- let(:raw) { { '_type' => 'foo' } }
20
-
21
- it 'should raise error' do
22
- expect { subject }.to raise_error('Facet with type "foo" is not known')
23
- end
24
- end
25
-
26
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Presenter::Facet, '.build' do
4
- subject { object.build(raw) }
5
-
6
- let(:object) { described_class }
7
-
8
- context 'when type is "terms"' do
9
- let(:raw) { { '_type' => 'terms' } }
10
- it { should eql(Esearch::Presenter::Facet::Terms.new(raw)) }
11
- end
12
-
13
- context 'when type is "range"' do
14
- let(:raw) { { '_type' => 'range' } }
15
- it { should eql(Esearch::Presenter::Facet::Range.new(raw)) }
16
- end
17
-
18
- context 'with unknown type' do
19
- let(:raw) { { '_type' => 'foo' } }
20
-
21
- it 'should raise error' do
22
- expect { subject }.to raise_error('Facet with type "foo" is not known')
23
- end
24
- end
25
-
26
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Request, '.new' do
4
- let(:object) { described_class }
5
-
6
- subject { object.new(*arguments) }
7
-
8
- let(:verb) { double('Verb') }
9
- let(:path) { '/some/path' }
10
- let(:params) { double('Params') }
11
- let(:body) { double('Body') }
12
-
13
- context 'with two args' do
14
- let(:arguments) { [ verb, path ] }
15
-
16
- its(:verb) { should be(verb) }
17
- its(:path) { should be(path) }
18
- its(:body) { should be(described_class::EMPTY_HASH) }
19
- its(:params) { should be(described_class::EMPTY_HASH) }
20
- end
21
-
22
- context 'with three args' do
23
- let(:arguments) { [ verb, path, body ] }
24
-
25
- its(:verb) { should be(verb) }
26
- its(:path) { should be(path) }
27
- its(:body) { should be(body) }
28
- its(:params) { should be(described_class::EMPTY_HASH) }
29
- end
30
-
31
- context 'with four args' do
32
- let(:arguments) { [ verb, path, body, params ] }
33
-
34
- its(:verb) { should be(verb) }
35
- its(:path) { should be(path) }
36
- its(:body) { should be(body) }
37
- its(:params) { should be(params) }
38
- end
39
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Request, '#run' do
4
- let(:object) { described_class.new(verb, path, body, params) }
5
-
6
- subject { object.run(connection) }
7
-
8
- let(:verb) { :get }
9
- let(:path) { '/some/random/path' }
10
- let(:body) { { 'foo' => 'bar' } }
11
- let(:params) { { 'baz' => 'buz' } }
12
-
13
- let(:response_status) { double('Status') }
14
- let(:response_headers) { {} }
15
- let(:response_body) { double('Body') }
16
-
17
- let(:connection) do
18
- Faraday.new do |builder|
19
- builder.adapter :test, stubs
20
- end
21
- end
22
-
23
- let(:stubs) do
24
- Faraday::Adapter::Test::Stubs.new do |stub|
25
- stub.get('/some/random/path') do |env|
26
- env.fetch(:request_headers).fetch('Content-Type').should eql('application/json; charset=UTF-8')
27
- env.fetch(:method).should be(:get)
28
- env.fetch(:params).should eql(params)
29
- env.fetch(:url).should eql(URI.parse('http:/some/random/path?baz=buz'))
30
- env.fetch(:body).should eql('{"foo":"bar"}')
31
- [ response_status, response_headers, response_body ]
32
- end
33
- end
34
- end
35
-
36
- its(:status) { should be(response_status) }
37
- its(:headers) { should eql(Faraday::Utils::Headers.new(response_headers)) }
38
- its(:body) { should be(response_body) }
39
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Type, '#connection' do
4
- subject { object.connection }
5
-
6
- let(:object) { described_class.new(index, type_name) }
7
- let(:index) { double('Index', :connection => connection) }
8
- let(:connection) { double('Connection') }
9
- let(:type_name) { double('Type Name') }
10
-
11
- it { should be(connection) }
12
-
13
- it_should_behave_like 'an idempotent method'
14
- end
15
-
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Esearch::Type, '#document' do
4
- subject { object.document(id) }
5
-
6
- let(:object) { described_class.new(index, type_name) }
7
- let(:index) { double('Index') }
8
- let(:type_name) { 'foo' }
9
- let(:id) { '1' }
10
-
11
- it { should eql(Esearch::Document.new(object, id)) }
12
- end