esearch 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,3 +1,7 @@
1
+ # # encoding: UTF-8
2
+
3
+ # encoding: UTF-8
4
+
1
5
  require 'spec_helper'
2
6
 
3
7
  describe Esearch::Command::Document::Index::Update, '.run' do
@@ -5,10 +9,10 @@ describe Esearch::Command::Document::Index::Update, '.run' do
5
9
 
6
10
  let(:object) { described_class }
7
11
  let(:document) { double('Document') }
8
- let(:options) { { :foo => :bar } }
12
+ let(:options) { { foo: :bar } }
9
13
 
10
14
  let(:expected_request) do
11
- Esearch::Request.new(:post, '/foo', document, { :foo => :bar, :op_type => :index })
15
+ Esearch::Request.new(:post, '/foo', document, foo: :bar, op_type: :index)
12
16
  end
13
17
 
14
18
  expect_presenter(Esearch::Presenter::Document::Operation::Index)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Exist, '.run' do
@@ -13,11 +15,11 @@ describe Esearch::Command::Exist, '.run' do
13
15
  connection.should_receive(:run).with(expected_request).and_return(response)
14
16
  end
15
17
 
16
- let(:context) { double('Context', :connection => connection, :path => Pathname.new('/foo')) }
18
+ let(:context) { double('Context', connection: connection, path: Pathname.new('/foo')) }
17
19
  let(:connection) { double('Connection') }
18
20
 
19
- let(:headers) { {'content-type' => 'application/json; charset=UTF-8'} }
20
- let(:response) { double('Response', :frozen? => true, :status => status, :headers => headers, :body => '{}') }
21
+ let(:headers) { { 'content-type' => 'application/json; charset=UTF-8' } }
22
+ let(:response) { double('Response', :frozen? => true, status: status, headers: headers, body: '{}') }
21
23
 
22
24
  context 'with status 200' do
23
25
  let(:status) { 200 }
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Index::Create, '.run' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Index::Delete, '.run' do
@@ -8,6 +10,6 @@ describe Esearch::Command::Index::Delete, '.run' do
8
10
  let(:expected_request) do
9
11
  Esearch::Request.new(:delete, '/foo', {}, {})
10
12
  end
11
-
13
+
12
14
  expect_presenter(Esearch::Presenter::Index::Delete)
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Index::Refresh, '.run' do
@@ -8,6 +10,6 @@ describe Esearch::Command::Index::Refresh, '.run' do
8
10
  let(:expected_request) do
9
11
  Esearch::Request.new(:post, '/foo/_refresh', {}, {})
10
12
  end
11
-
13
+
12
14
  expect_presenter(Esearch::Presenter::Index::Refresh)
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command, '#result' do
@@ -18,13 +20,12 @@ describe Esearch::Command, '#result' do
18
20
  end
19
21
  end
20
22
 
21
-
22
- let(:context) { double('Context', :connection => connection, :path => Pathname.new('/foo')) }
23
+ let(:context) { double('Context', connection: connection, path: Pathname.new('/foo')) }
23
24
  let(:connection) { double('Connection') }
24
25
 
25
- let(:headers) { {'content-type' => content_type } }
26
+ let(:headers) { { 'content-type' => content_type } }
26
27
  let(:content_type) { 'application/json; charset=UTF-8' }
27
- let(:response) { double('Response', :frozen? => true, :status => status, :headers => headers, :body => body) }
28
+ let(:response) { double('Response', :frozen? => true, status: status, headers: headers, body: body) }
28
29
  let(:body) { '{}' }
29
30
 
30
31
  let(:status) { 200 }
@@ -43,7 +44,10 @@ describe Esearch::Command, '#result' do
43
44
  let(:content_type) { 'text/plain' }
44
45
 
45
46
  it 'should raise error' do
46
- expect { subject }.to raise_error(Esearch::ProtocolError, 'Expected json content type, but got: "text/plain"')
47
+ expect { subject }.to raise_error(
48
+ Esearch::ProtocolError,
49
+ 'Expected json content type, but got: "text/plain"'
50
+ )
47
51
  end
48
52
  end
49
53
 
@@ -52,7 +56,10 @@ describe Esearch::Command, '#result' do
52
56
 
53
57
  context 'with json body' do
54
58
  it 'should raise error' do
55
- expect { subject }.to raise_error(Esearch::ProtocolError, 'expected response stati: [200] but got: 201, remote message: {}')
59
+ expect { subject }.to raise_error(
60
+ Esearch::ProtocolError,
61
+ 'expected response stati: [200] but got: 201, remote message: {}'
62
+ )
56
63
  end
57
64
  end
58
65
 
@@ -61,7 +68,10 @@ describe Esearch::Command, '#result' do
61
68
  let(:body) { 'message' }
62
69
 
63
70
  it 'should raise error' do
64
- expect { subject }.to raise_error(Esearch::ProtocolError, 'expected response stati: [200] but got: 201, remote message: "message"')
71
+ expect { subject }.to raise_error(
72
+ Esearch::ProtocolError,
73
+ 'expected response stati: [200] but got: 201, remote message: "message"'
74
+ )
65
75
  end
66
76
  end
67
77
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Search, '.run' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Status, '.run' do
@@ -8,6 +10,6 @@ describe Esearch::Command::Status, '.run' do
8
10
  let(:expected_request) do
9
11
  Esearch::Request.new(:get, '/foo/_status', {}, {})
10
12
  end
11
-
13
+
12
14
  expect_presenter(Esearch::Presenter::Status)
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Connection, '.build' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Connection, '#run' do
@@ -5,10 +7,10 @@ describe Esearch::Connection, '#run' do
5
7
 
6
8
  let(:object) { described_class.new(connection, logger) }
7
9
 
8
- let(:connection) { double('Connection') }
9
- let(:logger) { DummyLogger.new }
10
- let(:request) { double('Request', :log_string => 'the-logged-string') }
11
- let(:response) { double('Response', :status => 200) }
10
+ let(:connection) { double('Connection') }
11
+ let(:logger) { DummyLogger.new }
12
+ let(:request) { double('Request', log_string: 'the-logged-string') }
13
+ let(:response) { double('Response', status: 200) }
12
14
 
13
15
  class DummyLogger
14
16
  attr_reader :messages
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Document do
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
+ describe '#connection' do
12
+ subject { object.connection }
13
+
14
+ it { should be(connection) }
15
+ end
16
+
17
+ describe '#delete' do
18
+ subject { object.delete }
19
+
20
+ let(:expected_arguments) { [] }
21
+
22
+ expect_to_run_command(Esearch::Command::Document::Delete)
23
+ end
24
+
25
+ describe '#get' do
26
+ subject { object.get }
27
+
28
+ let(:expected_arguments) { [] }
29
+
30
+ expect_to_run_command(Esearch::Command::Document::Get)
31
+ end
32
+
33
+ describe '#path' do
34
+ subject { object.path }
35
+
36
+ let(:type) { double('Type', connection: connection, path: Pathname.new('a-index/b-type')) }
37
+
38
+ let(:id) { 'c-id' }
39
+
40
+ it { should eql(Pathname.new('a-index/b-type/c-id')) }
41
+
42
+ it_should_behave_like 'an idempotent method'
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Index do
6
+ let(:object) { described_class.new(connection, index_name) }
7
+ let(:connection) { double('Connection') }
8
+ let(:index_name) { 'foo' }
9
+
10
+ describe '#create' do
11
+ subject { object.create(settings) }
12
+
13
+ let(:settings) { { my: :settings } }
14
+ let(:expected_arguments) { [settings] }
15
+
16
+ expect_to_run_command(Esearch::Command::Index::Create)
17
+ end
18
+
19
+ describe '#delete' do
20
+ subject { object.delete }
21
+
22
+ let(:expected_arguments) { [] }
23
+
24
+ expect_to_run_command(Esearch::Command::Index::Delete)
25
+ end
26
+
27
+ describe '#path' do
28
+ subject { object.path }
29
+
30
+ it { should eql(Pathname.new('/foo')) }
31
+
32
+ it_should_behave_like 'an idempotent method'
33
+ end
34
+
35
+ describe '#type' do
36
+ subject { object.type(name) }
37
+
38
+ let(:name) { 'bar' }
39
+
40
+ it { should eql(Esearch::Type.new(object, name)) }
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Indices::All do
6
+ let(:object) { described_class.new(connection) }
7
+ let(:connection) { double('Connection') }
8
+
9
+ describe '#path' do
10
+ subject { object.path }
11
+
12
+ it { should eql(Pathname.new('/_all')) }
13
+
14
+ it_should_behave_like 'an idempotent method'
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Indices do
6
+ let(:object) { described_class.new(connection, names) }
7
+ let(:connection) { double('Connection') }
8
+
9
+ let(:names) { %w(foo bar) }
10
+
11
+ describe '#path' do
12
+ subject { object.path }
13
+
14
+ it { should eql(Pathname.new('/foo,bar')) }
15
+
16
+ it_should_behave_like 'an idempotent method'
17
+ end
18
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Document, '#index_create' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Document, '#index' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Document, '#index_update' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Exist, '#exist?' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Index, '#refresh' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Index, '#status' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Mixin::Search, '#search' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Presenter::Aspect::Range, '#from' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Presenter::Aspect::Range, '#to' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Presenter, '.new' do
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Presenter::Facet do
6
+ describe '.build' do
7
+ subject { object.build(raw) }
8
+
9
+ let(:object) { described_class }
10
+
11
+ context 'when type is "terms"' do
12
+ let(:raw) { { '_type' => 'terms' } }
13
+ it { should eql(Esearch::Presenter::Facet::Terms.new(raw)) }
14
+ end
15
+
16
+ context 'when type is "range"' do
17
+ let(:raw) { { '_type' => 'range' } }
18
+ it { should eql(Esearch::Presenter::Facet::Range.new(raw)) }
19
+ end
20
+
21
+ context 'with unknown type' do
22
+ let(:raw) { { '_type' => 'foo' } }
23
+
24
+ it 'should raise error' do
25
+ expect { subject }.to raise_error('Facet with type "foo" is not known')
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ describe '#aspects' do
32
+ subject { object.aspects }
33
+
34
+ class DummyAspect
35
+ include Concord.new(:value)
36
+ end
37
+
38
+ class DummyFacet < Esearch::Presenter::Facet
39
+ ASPECT_CLASS = DummyAspect
40
+ FACET_KEY = 'foo'.freeze
41
+ end
42
+
43
+ let(:object) do
44
+ DummyFacet.new(raw)
45
+ end
46
+
47
+ let(:raw) do
48
+ {
49
+ 'foo' => [
50
+ 'a',
51
+ 'b'
52
+ ]
53
+ }
54
+ end
55
+
56
+ it { should eql([ DummyAspect.new('a'), DummyAspect.new('b') ]) }
57
+
58
+ it_should_behave_like 'an idempotent method'
59
+ end
60
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Presenter::Hit, '#fields' do