search-kit 0.0.3 → 0.0.4

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +88 -0
  3. data/coverage/assets/0.10.0/application.css +799 -0
  4. data/coverage/assets/0.10.0/application.js +1707 -0
  5. data/coverage/assets/0.10.0/colorbox/border.png +0 -0
  6. data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  7. data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  8. data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  9. data/coverage/assets/0.10.0/favicon_green.png +0 -0
  10. data/coverage/assets/0.10.0/favicon_red.png +0 -0
  11. data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  12. data/coverage/assets/0.10.0/loading.gif +0 -0
  13. data/coverage/assets/0.10.0/magnify.png +0 -0
  14. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  15. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  16. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  17. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  18. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  19. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  20. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  21. data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  22. data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  23. data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  24. data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  25. data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  26. data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  27. data/coverage/index.html +446 -0
  28. data/demo/videos +112 -0
  29. data/demo/videos.json +14292 -0
  30. data/lib/search_kit/configuration.rb +8 -3
  31. data/lib/search_kit/logger.rb +1 -2
  32. data/lib/search_kit/version.rb +1 -1
  33. data/log/service-layer-development.log +282 -0
  34. data/log/service-layer-test.log +2874 -0
  35. data/pkg/search-kit-0.0.3.gem +0 -0
  36. data/search-kit.gemspec +5 -11
  37. data/spec/integrations/subscriber_model_spec.rb +91 -0
  38. data/spec/search_kit/cli/documents_spec.rb +234 -0
  39. data/spec/search_kit/cli/events_spec.rb +243 -0
  40. data/spec/search_kit/cli/indices_spec.rb +273 -0
  41. data/spec/search_kit/cli/search_spec.rb +77 -0
  42. data/spec/search_kit/cli/subscribers_spec.rb +108 -0
  43. data/spec/search_kit/clients/documents_spec.rb +210 -0
  44. data/spec/search_kit/clients/events_spec.rb +202 -0
  45. data/spec/search_kit/clients/indices_spec.rb +193 -0
  46. data/spec/search_kit/clients/keys_spec.rb +216 -0
  47. data/spec/search_kit/clients/populate_spec.rb +195 -0
  48. data/spec/search_kit/clients/scaffold_spec.rb +70 -0
  49. data/spec/search_kit/clients/search_spec.rb +87 -0
  50. data/spec/search_kit/clients/subscribers_spec.rb +166 -0
  51. data/spec/search_kit/configuration_spec.rb +25 -0
  52. data/spec/search_kit/messages_spec.rb +45 -0
  53. data/spec/search_kit/models/document_spec.rb +34 -0
  54. data/spec/search_kit/models/documents_spec.rb +12 -0
  55. data/spec/search_kit/models/event_spec.rb +14 -0
  56. data/spec/search_kit/models/events_spec.rb +12 -0
  57. data/spec/search_kit/models/key_spec.rb +26 -0
  58. data/spec/search_kit/models/keys_spec.rb +39 -0
  59. data/spec/search_kit/models/subscriber_spec.rb +22 -0
  60. data/spec/search_kit/polling/process_spec.rb +65 -0
  61. data/spec/search_kit/polling_spec.rb +24 -0
  62. data/spec/search_kit_spec.rb +7 -0
  63. data/spec/spec_helper.rb +29 -0
  64. data/tmp/modeling.rb +22 -0
  65. data/tmp/vidya.json +1 -0
  66. metadata +101 -19
  67. data/.gitignore +0 -16
  68. data/.rspec +0 -2
  69. data/.rubocop.yml +0 -39
  70. data/.ruby-version +0 -1
  71. data/.travis.yml +0 -4
@@ -0,0 +1,216 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ describe SearchKit::Clients::Keys do
5
+ let(:response) { OpenStruct.new(status: status, body: json) }
6
+ let(:json) { response_body.to_json }
7
+ let(:status) { 200 }
8
+ let(:client) { described_class.new }
9
+ let(:response_body) { { data: [] } }
10
+ let(:token) { SearchKit.config.app_token }
11
+
12
+ before do
13
+ allow(client.connection).to receive(:delete).and_return(response)
14
+ allow(client.connection).to receive(:get).and_return(response)
15
+ allow(client.connection).to receive(:patch).and_return(response)
16
+ allow(client.connection).to receive(:post).and_return(response)
17
+ end
18
+
19
+ subject { client }
20
+
21
+ it { is_expected.to respond_to :token }
22
+
23
+ describe '#connection' do
24
+ subject { client.connection }
25
+ it { is_expected.to be_instance_of Faraday::Connection }
26
+ end
27
+
28
+ describe '#create' do
29
+ let(:name) { "name" }
30
+
31
+ let(:params) do
32
+ { token: token, data: { type: 'keys', attributes: { name: name } } }
33
+ end
34
+
35
+ subject { client.create(name) }
36
+
37
+ it "calls #connection.post with given name" do
38
+ expect(client.connection).to receive(:post).with('', params)
39
+ subject
40
+ end
41
+
42
+ it "parses the json response" do
43
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
44
+ subject
45
+ end
46
+
47
+ context 'when given status 400' do
48
+ let(:status) { 400 }
49
+
50
+ it "throws a bad request error" do
51
+ expect { subject }.to raise_exception SearchKit::Errors::BadRequest
52
+ end
53
+ end
54
+
55
+ context 'when given status 401' do
56
+ let(:status) { 401 }
57
+
58
+ it "throws an unauthorized error" do
59
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
60
+ end
61
+ end
62
+
63
+ context 'when given status 422' do
64
+ let(:status) { 422 }
65
+
66
+ it "throws an unprocessable error" do
67
+ expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe '#expire' do
74
+ let(:id) { 1 }
75
+
76
+ subject { client.expire(id) }
77
+
78
+ it "calls #connection.delete with given slug" do
79
+ expect(client.connection).to receive(:delete).with(id, token: token)
80
+ subject
81
+ end
82
+
83
+ it "parses the json response" do
84
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
85
+ subject
86
+ end
87
+
88
+ context 'when given status 401' do
89
+ let(:status) { 401 }
90
+
91
+ it "throws an unauthorized error" do
92
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
93
+ end
94
+ end
95
+
96
+ context 'when given status 404' do
97
+ let(:status) { 404 }
98
+
99
+ it "throws a not found error" do
100
+ expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#index' do
106
+ subject { client.index }
107
+
108
+ it "calls #connection.get" do
109
+ expect(client.connection).to receive(:get).with("", token: token)
110
+ subject
111
+ end
112
+
113
+ it "parses the json response" do
114
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
115
+ subject
116
+ end
117
+
118
+ context 'when given status 401' do
119
+ let(:status) { 401 }
120
+
121
+ it "throws an unauthorized error" do
122
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
123
+ end
124
+ end
125
+ end
126
+
127
+ describe '#show' do
128
+ let(:id) { 1 }
129
+
130
+ subject { client.show(id) }
131
+
132
+ it "calls #connection.get with given id" do
133
+ expect(client.connection).to receive(:get).with(id, token: token)
134
+ subject
135
+ end
136
+
137
+ it "parses the json response" do
138
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
139
+ subject
140
+ end
141
+
142
+ context 'when given status 401' do
143
+ let(:status) { 401 }
144
+
145
+ it "throws an unauthorized error" do
146
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
147
+ end
148
+ end
149
+
150
+ context 'when given status 404' do
151
+ let(:status) { 404 }
152
+
153
+ it "throws a not found error" do
154
+ expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
155
+ end
156
+ end
157
+ end
158
+
159
+ describe '#update' do
160
+ let(:name) { "name" }
161
+ let(:new_name) { "New name" }
162
+ let(:id) { 1 }
163
+
164
+ let(:params) do
165
+ {
166
+ token: token,
167
+ data: { type: 'keys', attributes: { name: new_name } }
168
+ }
169
+ end
170
+
171
+ subject { client.update(id, name: new_name) }
172
+
173
+ it "calls #connection.patch with given id and attributes" do
174
+ expect(client.connection).to receive(:patch).with(id, params)
175
+ subject
176
+ end
177
+
178
+ it "parses the json response" do
179
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
180
+ subject
181
+ end
182
+
183
+ context 'when given status 400' do
184
+ let(:status) { 400 }
185
+
186
+ it "throws a bad request error" do
187
+ expect { subject }.to raise_exception SearchKit::Errors::BadRequest
188
+ end
189
+ end
190
+
191
+ context 'when given status 401' do
192
+ let(:status) { 401 }
193
+
194
+ it "throws an unauthorized error" do
195
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
196
+ end
197
+ end
198
+
199
+ context 'when given status 404' do
200
+ let(:status) { 404 }
201
+
202
+ it "throws a not found error" do
203
+ expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
204
+ end
205
+ end
206
+
207
+ context 'when given status 422' do
208
+ let(:status) { 422 }
209
+
210
+ it "throws an Unprocessable error" do
211
+ expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
212
+ end
213
+ end
214
+
215
+ end
216
+ end
@@ -0,0 +1,195 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ describe SearchKit::Clients::Populate do
5
+ let(:response) { OpenStruct.new(status: status, body: json) }
6
+ let(:json) { response_body.to_json }
7
+ let(:status) { 200 }
8
+ let(:client) { described_class.new }
9
+ let(:id) { 1 }
10
+ let(:response_body) { { data: [] } }
11
+ let(:slug) { "an-index-slug" }
12
+ let(:token) { SearchKit.config.app_token }
13
+
14
+ before do
15
+ allow(client.connection).to receive(:delete).and_return(response)
16
+ allow(client.connection).to receive(:get).and_return(response)
17
+ allow(client.connection).to receive(:patch).and_return(response)
18
+ allow(client.connection).to receive(:post).and_return(response)
19
+ end
20
+
21
+ subject { client }
22
+
23
+ it { is_expected.to respond_to :token }
24
+
25
+ describe '#connection' do
26
+ subject { client.connection }
27
+ it { is_expected.to be_instance_of Faraday::Connection }
28
+ end
29
+
30
+ describe '#create' do
31
+ let(:document) { { id: id, title: "The first document" } }
32
+ let(:documents) { [document] }
33
+
34
+ let(:params) do
35
+ {
36
+ token: token,
37
+ data: [{ type: "documents", attributes: document }]
38
+ }
39
+ end
40
+
41
+ subject { client.create(slug, documents) }
42
+
43
+ it "calls #connection.post with the base path and a document" do
44
+ expect(client.connection).to receive(:post).with(slug, params)
45
+ subject
46
+ end
47
+
48
+ it "parses the json response" do
49
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
50
+ subject
51
+ end
52
+
53
+ context 'when the response status is 400' do
54
+ let(:status) { 400 }
55
+
56
+ it "raises a bad request error" do
57
+ expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
58
+ end
59
+ end
60
+
61
+ context 'when the response status is 401' do
62
+ let(:status) { 401 }
63
+
64
+ it "raises an index not found error" do
65
+ expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
66
+ end
67
+ end
68
+
69
+ context 'when the response status is 404' do
70
+ let(:status) { 404 }
71
+
72
+ it "raises an index not found error" do
73
+ expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
74
+ end
75
+ end
76
+
77
+ context 'when the response status is 422' do
78
+ let(:status) { 422 }
79
+
80
+ it "raises an unprocessable error" do
81
+ expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#update' do
87
+ let(:document) { { id: id, title: "The first document" } }
88
+ let(:documents) { [document] }
89
+
90
+ let(:params) do
91
+ {
92
+ token: token,
93
+ data: [{ type: "documents", id: id, attributes: document }]
94
+ }
95
+ end
96
+
97
+ subject { client.update(slug, documents) }
98
+
99
+ it "calls #connection.patch with the slug and documents" do
100
+ expect(client.connection).to receive(:patch).with(slug, params)
101
+ subject
102
+ end
103
+
104
+ it "parses the json response" do
105
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
106
+ subject
107
+ end
108
+
109
+ context 'when the response status is 400' do
110
+ let(:status) { 400 }
111
+
112
+ it "raises a bad request error" do
113
+ expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
114
+ end
115
+ end
116
+
117
+ context 'when the response status is 401' do
118
+ let(:status) { 401 }
119
+
120
+ it "raises an index not found error" do
121
+ expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
122
+ end
123
+ end
124
+
125
+ context 'when the response status is 404' do
126
+ let(:status) { 404 }
127
+
128
+ it "raises an index not found error" do
129
+ expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
130
+ end
131
+ end
132
+
133
+ context 'when the response status is 422' do
134
+ let(:status) { 422 }
135
+
136
+ it "raises an unprocessable error" do
137
+ expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#delete' do
143
+ let(:params) do
144
+ {
145
+ token: token,
146
+ data: [{ type: 'documents', id: id, attributes: { id: id } }]
147
+ }
148
+ end
149
+
150
+ subject { client.delete(slug, [id]) }
151
+
152
+ it "calls #connection.get with the correct params" do
153
+ expect(client.connection).to receive(:delete).with(slug, params)
154
+ subject
155
+ end
156
+
157
+ it "parses the json response" do
158
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
159
+ subject
160
+ end
161
+
162
+ context 'when the response status is 400' do
163
+ let(:status) { 400 }
164
+
165
+ it "raises a bad request error" do
166
+ expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
167
+ end
168
+ end
169
+
170
+ context 'when the response status is 401' do
171
+ let(:status) { 401 }
172
+
173
+ it "raises an index not found error" do
174
+ expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
175
+ end
176
+ end
177
+
178
+ context 'when the response status is 404' do
179
+ let(:status) { 404 }
180
+
181
+ it "raises an index not found error" do
182
+ expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
183
+ end
184
+ end
185
+
186
+ context 'when the response status is 422' do
187
+ let(:status) { 422 }
188
+
189
+ it "raises an unprocessable error" do
190
+ expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
191
+ end
192
+ end
193
+
194
+ end
195
+ end
@@ -0,0 +1,70 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ describe SearchKit::Clients::Scaffold do
5
+ let(:client) { described_class.new }
6
+ let(:json) { response_body.to_json }
7
+ let(:response_body) { { data: [] } }
8
+ let(:response) { OpenStruct.new(status: status, body: json) }
9
+ let(:status) { 200 }
10
+ let(:token) { SearchKit.config.app_token }
11
+
12
+ before { allow(client.connection).to receive(:post).and_return(response) }
13
+
14
+ subject { client }
15
+
16
+ it { is_expected.to respond_to :token }
17
+
18
+ describe '#create' do
19
+ let(:name) { "My Favorite Scaffolded Index" }
20
+ let(:documents) { [{ its: "A", plain: "Hash", with: "An", id: 1 }] }
21
+
22
+ let(:params) do
23
+ {
24
+ token: token,
25
+ data: {
26
+ type: 'indices',
27
+ attributes: { name: name },
28
+ relationships: { documents: documents }
29
+ }
30
+ }
31
+ end
32
+
33
+ subject { client.create(name, documents) }
34
+
35
+ it "calls #connection.post with given name" do
36
+ expect(client.connection).to receive(:post).with('', params)
37
+ subject
38
+ end
39
+
40
+ it "parses the json response" do
41
+ expect(JSON).to receive(:parse).with(json, symbolize_names: true)
42
+ subject
43
+ end
44
+
45
+ context 'when gven status 400' do
46
+ let(:status) { 400 }
47
+
48
+ it "throws a bad request error" do
49
+ expect { subject }.to raise_exception SearchKit::Errors::BadRequest
50
+ end
51
+ end
52
+
53
+ context 'when given status 401' do
54
+ let(:status) { 401 }
55
+
56
+ it "throws an unprocessable error" do
57
+ expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
58
+ end
59
+ end
60
+
61
+ context 'when given status 422' do
62
+ let(:status) { 422 }
63
+
64
+ it "throws an unprocessable error" do
65
+ expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
66
+ end
67
+ end
68
+
69
+ end
70
+ end