elastic_adapter 0.0.1 → 0.0.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +3 -0
  3. data/.rubocop.yml +8 -0
  4. data/.ruby.yml +261 -0
  5. data/.travis.yml +6 -0
  6. data/README.md +87 -8
  7. data/elastic_adapter.gemspec +1 -0
  8. data/examples/basic_usage.rb +164 -0
  9. data/lib/elastic_adapter/decoration/count_response.rb +0 -2
  10. data/lib/elastic_adapter/decoration/decorator.rb +2 -4
  11. data/lib/elastic_adapter/decoration/response_decorator_factory.rb +3 -6
  12. data/lib/elastic_adapter/decoration/search_response.rb +0 -2
  13. data/lib/elastic_adapter/decoration/suggestion_response.rb +0 -1
  14. data/lib/elastic_adapter/decoration/validation_response.rb +0 -1
  15. data/lib/elastic_adapter/document_type.rb +12 -2
  16. data/lib/elastic_adapter/index.rb +103 -10
  17. data/lib/elastic_adapter/response.rb +2 -1
  18. data/lib/elastic_adapter/version.rb +1 -1
  19. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml +1 -1
  20. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/{returs_the_amount_of_all_documents.yml → returns_the_amount_of_all_documents.yml} +1 -1
  21. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml +57 -0
  22. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml +1 -1
  23. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml +1 -1
  24. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml +84 -0
  25. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml +2 -2
  26. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml +2 -2
  27. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml +57 -0
  28. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml +2 -29
  29. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml +2 -29
  30. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response.yml +30 -0
  31. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml +1 -1
  32. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml +1 -1
  33. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml +1 -28
  34. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exceptionElasticAdapter_Index/_delete_index/index_present/repsonse.yml +30 -0
  35. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml +1 -28
  36. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_ResponseElasticAdapter_Index/_delete_index/index_present/repsonse.yml +30 -0
  37. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/contains_the_document.yml +1 -1
  38. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists.yml +84 -0
  39. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml +3 -3
  40. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml +1 -1
  41. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml +1 -1
  42. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document.yml +84 -0
  43. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml +3 -3
  44. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml +2 -2
  45. data/spec/cassettes/ElasticAdapter_Index/_index/new_document.yml +57 -0
  46. data/spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml +3 -3
  47. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml +3 -3
  48. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml +3 -3
  49. data/spec/cassettes/ElasticAdapter_Index/_search.yml +111 -0
  50. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml +2 -2
  51. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml +2 -2
  52. data/spec/cassettes/ElasticAdapter_Index/_suggest.yml +111 -0
  53. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml +4 -3
  54. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_false.yml +1 -1
  55. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml +3 -3
  56. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml +1 -1
  57. data/spec/cassettes/ElasticAdapter_Index/_validate.yml +57 -0
  58. data/spec/index/count_spec.rb +46 -0
  59. data/spec/index/create_index_spec.rb +39 -0
  60. data/spec/index/delete_index_spec.rb +29 -0
  61. data/spec/index/get_spec.rb +29 -0
  62. data/spec/index/index_spec.rb +60 -0
  63. data/spec/index/search_spec.rb +37 -0
  64. data/spec/index/shared_context.rb +37 -0
  65. data/spec/index/shared_examples.rb +19 -0
  66. data/spec/index/suggest_spec.rb +44 -0
  67. data/spec/index/unit_spec.rb +69 -0
  68. data/spec/index/validate_spec.rb +55 -0
  69. data/spec/spec_helper.rb +6 -1
  70. data/spec/support/index_helper.rb +78 -0
  71. metadata +72 -7
  72. data/spec/index_spec.rb +0 -458
@@ -0,0 +1,111 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://localhost:9200/test_index
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"mappings":{"test_doc":{"properties":{"foo":{"type":"string"},"foo_suggest":{"type":"completion"}}}},"settings":{}}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Content-Length:
24
+ - '21'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"acknowledged":true}'
28
+ http_version:
29
+ recorded_at: Sat, 07 Feb 2015 19:44:49 GMT
30
+ - request:
31
+ method: put
32
+ uri: http://localhost:9200/test_index/test_doc/1
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"foo":"bar","foo_suggest":{"input":"bar"}}'
36
+ headers:
37
+ User-Agent:
38
+ - Faraday v0.9.1
39
+ Accept-Encoding:
40
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
41
+ Accept:
42
+ - "*/*"
43
+ response:
44
+ status:
45
+ code: 201
46
+ message: Created
47
+ headers:
48
+ Content-Type:
49
+ - application/json; charset=UTF-8
50
+ Content-Length:
51
+ - '80'
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"_index":"test_index","_type":"test_doc","_id":"1","_version":1,"created":true}'
55
+ http_version:
56
+ recorded_at: Sat, 07 Feb 2015 19:44:52 GMT
57
+ - request:
58
+ method: put
59
+ uri: http://localhost:9200/test_index/test_doc/2
60
+ body:
61
+ encoding: UTF-8
62
+ string: '{"foo":"zoo","foo_suggest":{"input":"zoo"}}'
63
+ headers:
64
+ User-Agent:
65
+ - Faraday v0.9.1
66
+ Accept-Encoding:
67
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
68
+ Accept:
69
+ - "*/*"
70
+ response:
71
+ status:
72
+ code: 201
73
+ message: Created
74
+ headers:
75
+ Content-Type:
76
+ - application/json; charset=UTF-8
77
+ Content-Length:
78
+ - '80'
79
+ body:
80
+ encoding: UTF-8
81
+ string: '{"_index":"test_index","_type":"test_doc","_id":"2","_version":1,"created":true}'
82
+ http_version:
83
+ recorded_at: Sat, 07 Feb 2015 19:44:55 GMT
84
+ - request:
85
+ method: delete
86
+ uri: http://localhost:9200/test_index
87
+ body:
88
+ encoding: US-ASCII
89
+ string: ''
90
+ headers:
91
+ User-Agent:
92
+ - Faraday v0.9.1
93
+ Accept-Encoding:
94
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
95
+ Accept:
96
+ - "*/*"
97
+ response:
98
+ status:
99
+ code: 200
100
+ message: OK
101
+ headers:
102
+ Content-Type:
103
+ - application/json; charset=UTF-8
104
+ Content-Length:
105
+ - '21'
106
+ body:
107
+ encoding: UTF-8
108
+ string: '{"acknowledged":true}'
109
+ http_version:
110
+ recorded_at: Sat, 07 Feb 2015 19:44:58 GMT
111
+ recorded_with: VCR 2.9.3
@@ -21,10 +21,11 @@ http_interactions:
21
21
  Content-Type:
22
22
  - application/json; charset=UTF-8
23
23
  Content-Length:
24
- - '62'
24
+ - '224'
25
25
  body:
26
26
  encoding: UTF-8
27
- string: '{"valid":true,"_shards":{"total":1,"successful":0,"failed":0}}'
27
+ string: '{"valid":false,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":false,"error":"org.elasticsearch.index.query.QueryParsingException:
28
+ [test_index] request does not support [asd]"}]}'
28
29
  http_version:
29
- recorded_at: Thu, 05 Feb 2015 21:00:43 GMT
30
+ recorded_at: Sat, 07 Feb 2015 19:45:01 GMT
30
31
  recorded_with: VCR 2.9.3
@@ -27,5 +27,5 @@ http_interactions:
27
27
  string: '{"valid":false,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":false,"error":"org.elasticsearch.index.query.QueryParsingException:
28
28
  [test_index] request does not support [asd]"}]}'
29
29
  http_version:
30
- recorded_at: Thu, 05 Feb 2015 19:30:06 GMT
30
+ recorded_at: Sat, 07 Feb 2015 19:45:01 GMT
31
31
  recorded_with: VCR 2.9.3
@@ -21,10 +21,10 @@ http_interactions:
21
21
  Content-Type:
22
22
  - application/json; charset=UTF-8
23
23
  Content-Length:
24
- - '62'
24
+ - '150'
25
25
  body:
26
26
  encoding: UTF-8
27
- string: '{"valid":true,"_shards":{"total":1,"successful":0,"failed":0}}'
27
+ string: '{"valid":true,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":true,"explanation":"ConstantScore(*:*)"}]}'
28
28
  http_version:
29
- recorded_at: Thu, 05 Feb 2015 21:04:08 GMT
29
+ recorded_at: Sat, 07 Feb 2015 19:45:01 GMT
30
30
  recorded_with: VCR 2.9.3
@@ -26,5 +26,5 @@ http_interactions:
26
26
  encoding: UTF-8
27
27
  string: '{"valid":true,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"test_index","valid":true,"explanation":"ConstantScore(*:*)"}]}'
28
28
  http_version:
29
- recorded_at: Thu, 05 Feb 2015 19:30:06 GMT
29
+ recorded_at: Sat, 07 Feb 2015 19:45:01 GMT
30
30
  recorded_with: VCR 2.9.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://localhost:9200/test_index
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"mappings":{"test_doc":{"properties":{"foo":{"type":"string"},"foo_suggest":{"type":"completion"}}}},"settings":{}}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Content-Length:
24
+ - '21'
25
+ body:
26
+ encoding: UTF-8
27
+ string: '{"acknowledged":true}'
28
+ http_version:
29
+ recorded_at: Sat, 07 Feb 2015 19:44:58 GMT
30
+ - request:
31
+ method: delete
32
+ uri: http://localhost:9200/test_index
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ''
36
+ headers:
37
+ User-Agent:
38
+ - Faraday v0.9.1
39
+ Accept-Encoding:
40
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
41
+ Accept:
42
+ - "*/*"
43
+ response:
44
+ status:
45
+ code: 200
46
+ message: OK
47
+ headers:
48
+ Content-Type:
49
+ - application/json; charset=UTF-8
50
+ Content-Length:
51
+ - '21'
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"acknowledged":true}'
55
+ http_version:
56
+ recorded_at: Sat, 07 Feb 2015 19:45:01 GMT
57
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#count", :vcr do
8
+ context "empty index" do
9
+ before :all do
10
+ create_test_index
11
+ end
12
+
13
+ after :all do
14
+ delete_test_index
15
+ end
16
+
17
+ it "returns the amount of all documents" do
18
+ expect(subject.count).to eq 0
19
+ end
20
+
21
+ it "is a response" do
22
+ expect(subject.count).to be_a Decoration::CountResponse
23
+ end
24
+ end
25
+
26
+ context "not empty index" do
27
+ before :all do
28
+ create_test_index
29
+ index_documents foo: "bar"
30
+ end
31
+
32
+ after :all do
33
+ delete_test_index
34
+ end
35
+
36
+ it "returns 1" do
37
+ expect(subject.count).to eq 1
38
+ end
39
+
40
+ it "is a response" do
41
+ expect(subject.count).to be_a Decoration::CountResponse
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#create_index", :vcr do
8
+ context "index is present" do
9
+ before :all do
10
+ create_test_index
11
+ end
12
+
13
+ after :all do
14
+ delete_test_index
15
+ end
16
+
17
+ let(:response) { subject.create_index }
18
+
19
+ describe "response" do
20
+ # TODO fix this
21
+ # Somehow VCR doesn't record the requests for the current context
22
+ include_examples "response with exception"
23
+ end
24
+ end
25
+
26
+ context "index not present" do
27
+ after :each do
28
+ delete_test_index
29
+ end
30
+
31
+ let(:response) { subject.create_index }
32
+
33
+ describe "response" do
34
+ include_examples "response without exception"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#delete_index", :vcr do
8
+ context "index present" do
9
+ let(:response) { subject.delete_index }
10
+
11
+ before :each do |example|
12
+ create_test_index prefix: vcr_cassette_name_for(example.metadata)
13
+ end
14
+
15
+ describe "repsonse" do
16
+ include_examples "response without exception"
17
+ end
18
+ end
19
+
20
+ context "index not present" do
21
+ let(:response) { subject.delete_index }
22
+
23
+ describe "repsonse" do
24
+ include_examples "response with exception"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#get", :vcr do
8
+ context "document exists" do
9
+ let(:document) { {id: "1", foo: "bar"} }
10
+ before :all do
11
+ create_test_index
12
+ index_documents(foo: "bar", id: 1)
13
+ end
14
+
15
+ after :all do
16
+ delete_test_index
17
+ end
18
+
19
+ let(:response) { subject.get(1) }
20
+
21
+ describe "response" do
22
+ it "contains the document" do
23
+ expect(response).to eq document
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#index", :vcr do
8
+ context "new document" do
9
+ let(:document) { { foo: "bar" } }
10
+
11
+ before :all do
12
+ create_test_index
13
+ end
14
+
15
+ after :all do
16
+ delete_test_index
17
+ end
18
+
19
+ it "indexes a document" do
20
+ subject.index(document)
21
+ wait(1)
22
+ expect(subject.count).to eq 1
23
+ end
24
+
25
+ it "invokes to_hash on the document" do
26
+ expect(document).to receive(:to_hash).and_return(document.to_hash)
27
+ subject.index(document)
28
+ end
29
+ end
30
+
31
+ context "existing document" do
32
+ let(:document) { {foo: "baz", id: 1} }
33
+
34
+ before :all do
35
+ create_test_index
36
+ index_documents foo: "bar", id: 1
37
+ end
38
+
39
+ after :all do
40
+ delete_test_index
41
+ end
42
+
43
+ it "doesn't change the document count" do
44
+ expect(subject.count).to eq 1
45
+ subject.index(document)
46
+ expect(subject.count).to eq 1
47
+ end
48
+
49
+ it "invokes to_hash on the document" do
50
+ expect(document).to receive(:to_hash).and_return(document.to_hash)
51
+ subject.index(document)
52
+ end
53
+
54
+ it "updates the document" do
55
+ expect(subject.get(1)[:foo]).to eq "baz"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#search", :vcr do
8
+ before :all do
9
+ create_test_index
10
+ index_documents(id: 1, foo: "bar", foo_suggest: {input: "bar"})
11
+ index_documents(id: 2, foo: "zoo", foo_suggest: {input: "zoo"})
12
+ end
13
+
14
+ after :all do
15
+ delete_test_index
16
+ end
17
+
18
+ context "match_all" do
19
+ it "returns all documents" do
20
+ expect(subject.search({query: {match_all: {}}}).count).to eq 2
21
+ end
22
+ end
23
+
24
+ context "zoo" do
25
+ let(:response) { subject.search(query: {match: {foo: "zoo"}})}
26
+ it "returns one document" do
27
+ expect(response.count).to eq 1
28
+ end
29
+
30
+ it "returns the wanted document" do
31
+ expect(response[:hits].first[:id]).to eq "2"
32
+ expect(response[:hits].first[:foo]).to eq "zoo"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require_relative "./shared_examples.rb"
3
+
4
+ RSpec.shared_context "index context" do
5
+ let(:name) { "test_index" }
6
+ let(:mappings) do
7
+ {
8
+ test_index: {
9
+ properties: {
10
+ foo: {
11
+ type: "string",
12
+ foo_suggest: { type: "completion" }
13
+ }
14
+ }
15
+ }
16
+ }
17
+ end
18
+ let(:document_type) do
19
+ OpenStruct.new(name: "test_doc", mappings: mappings)
20
+ end
21
+ let(:settings) { { number_of_shards: 1 } }
22
+ let(:log) { true }
23
+ let(:url) { "http://localhost:9200"}
24
+
25
+ let(:bar_doc) { { id: 1, foo: "bar", foo_suggest: {input: "bar"} } }
26
+ let(:zoo_doc) { { id: 2, foo: "zoo", foo_suggest: {input: "zoo"} } }
27
+
28
+ subject do
29
+ ElasticAdapter::Index.new(
30
+ name: name,
31
+ settings: settings,
32
+ document_type: document_type,
33
+ url: url,
34
+ log: log
35
+ )
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ RSpec.shared_examples "response without exception" do
2
+ it "is a Response" do
3
+ expect(response).to be_a ElasticAdapter::Response
4
+ end
5
+
6
+ it "has no exception" do
7
+ expect(response).not_to have_key :exception
8
+ end
9
+ end
10
+
11
+ RSpec.shared_examples "response with exception" do
12
+ it "is a Response" do
13
+ expect(response).to be_a ElasticAdapter::Response
14
+ end
15
+
16
+ it "has an exception" do
17
+ expect(response).to have_key :exception
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ require_relative"./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#suggest", :vcr do
8
+ before :all do
9
+ create_test_index
10
+ doc1 = {id: 1, foo: "bar", foo_suggest: {input: "bar"}}
11
+ doc2 = {id: 2, foo: "zoo", foo_suggest: {input: "zoo"}}
12
+ index_documents([doc1, doc2])
13
+ end
14
+
15
+ after :all do
16
+ delete_test_index
17
+ end
18
+
19
+ context "query 'ba'" do
20
+ let(:query) do
21
+ {
22
+ foo_suggest: {
23
+ text: "ba",
24
+ completion: {
25
+ field: "foo_suggest"
26
+ }
27
+ }
28
+ }
29
+ end
30
+
31
+ let(:response) { subject.suggest(query)}
32
+
33
+ it "returns one result" do
34
+ expect(response.count).to eq 1
35
+ end
36
+
37
+ it "returns bar" do
38
+ expect(response[:options].first).to include text: "bar"
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,69 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ describe "unit specs" do
6
+ include_context "index context"
7
+
8
+ describe "#initialize" do
9
+ it "assigns the name" do
10
+ expect(subject.instance_variable_get('@name')).to be name
11
+ end
12
+
13
+ it "assigns the settings" do
14
+ expect(subject.instance_variable_get('@settings')).to be settings
15
+ end
16
+
17
+ it "assigns the document_type" do
18
+ expect(subject.instance_variable_get('@document_type')).to be document_type
19
+ end
20
+
21
+ it "assigns the url" do
22
+ expect(subject.instance_variable_get('@url')).to be url
23
+ end
24
+
25
+ it "assigns the log" do
26
+ expect(subject.instance_variable_get('@log')).to be log
27
+ end
28
+ end
29
+
30
+ describe "getter" do
31
+ describe "name" do
32
+ it "returns the name" do
33
+ expect(subject.name).to eq name
34
+ end
35
+ end
36
+
37
+ describe "settings" do
38
+ it "returns the settings" do
39
+ expect(subject.settings).to eq settings
40
+ end
41
+ end
42
+
43
+ describe "document_type" do
44
+ it "returns the document_type" do
45
+ expect(subject.document_type).to eq document_type
46
+ end
47
+ end
48
+
49
+ describe "url" do
50
+ it "returns the url" do
51
+ expect(subject.url).to eq url
52
+ end
53
+ end
54
+
55
+ describe "log" do
56
+ it "returns the log" do
57
+ expect(subject.log).to eq log
58
+ end
59
+ end
60
+
61
+ describe "client" do
62
+ it "returns the client" do
63
+ expect(subject.client).to be_a ::Elasticsearch::Transport::Client
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "./shared_context.rb"
2
+
3
+ module ElasticAdapter
4
+ describe Index do
5
+ include_context "index context"
6
+
7
+ describe "#validate", :vcr do
8
+ before :all do
9
+ create_test_index
10
+ end
11
+
12
+ after :all do
13
+ delete_test_index
14
+ end
15
+
16
+ context "invalid query" do
17
+ let(:query) do
18
+ {
19
+ asd: "[[[ BOOM! ]]]"
20
+ }
21
+ end
22
+
23
+ let(:response) { subject.validate(query) }
24
+
25
+ it "is false" do
26
+ expect(response).to eq false
27
+ end
28
+
29
+ it "is a response" do
30
+ expect(response).to be_a Decoration::ValidationResponse
31
+ end
32
+ end
33
+
34
+ context "valid query" do
35
+ let(:query) do
36
+ {
37
+ query: {
38
+ match_all: {}
39
+ }
40
+ }
41
+ end
42
+
43
+ let(:response) { subject.validate(query) }
44
+
45
+ it "is true" do
46
+ expect(response).to eq true
47
+ end
48
+
49
+ it "is a response" do
50
+ expect(response).to be_a Decoration::ValidationResponse
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end