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.
- checksums.yaml +4 -4
- data/Gemfile.lock +88 -0
- data/coverage/assets/0.10.0/application.css +799 -0
- data/coverage/assets/0.10.0/application.js +1707 -0
- data/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.0/loading.gif +0 -0
- data/coverage/assets/0.10.0/magnify.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +446 -0
- data/demo/videos +112 -0
- data/demo/videos.json +14292 -0
- data/lib/search_kit/configuration.rb +8 -3
- data/lib/search_kit/logger.rb +1 -2
- data/lib/search_kit/version.rb +1 -1
- data/log/service-layer-development.log +282 -0
- data/log/service-layer-test.log +2874 -0
- data/pkg/search-kit-0.0.3.gem +0 -0
- data/search-kit.gemspec +5 -11
- data/spec/integrations/subscriber_model_spec.rb +91 -0
- data/spec/search_kit/cli/documents_spec.rb +234 -0
- data/spec/search_kit/cli/events_spec.rb +243 -0
- data/spec/search_kit/cli/indices_spec.rb +273 -0
- data/spec/search_kit/cli/search_spec.rb +77 -0
- data/spec/search_kit/cli/subscribers_spec.rb +108 -0
- data/spec/search_kit/clients/documents_spec.rb +210 -0
- data/spec/search_kit/clients/events_spec.rb +202 -0
- data/spec/search_kit/clients/indices_spec.rb +193 -0
- data/spec/search_kit/clients/keys_spec.rb +216 -0
- data/spec/search_kit/clients/populate_spec.rb +195 -0
- data/spec/search_kit/clients/scaffold_spec.rb +70 -0
- data/spec/search_kit/clients/search_spec.rb +87 -0
- data/spec/search_kit/clients/subscribers_spec.rb +166 -0
- data/spec/search_kit/configuration_spec.rb +25 -0
- data/spec/search_kit/messages_spec.rb +45 -0
- data/spec/search_kit/models/document_spec.rb +34 -0
- data/spec/search_kit/models/documents_spec.rb +12 -0
- data/spec/search_kit/models/event_spec.rb +14 -0
- data/spec/search_kit/models/events_spec.rb +12 -0
- data/spec/search_kit/models/key_spec.rb +26 -0
- data/spec/search_kit/models/keys_spec.rb +39 -0
- data/spec/search_kit/models/subscriber_spec.rb +22 -0
- data/spec/search_kit/polling/process_spec.rb +65 -0
- data/spec/search_kit/polling_spec.rb +24 -0
- data/spec/search_kit_spec.rb +7 -0
- data/spec/spec_helper.rb +29 -0
- data/tmp/modeling.rb +22 -0
- data/tmp/vidya.json +1 -0
- metadata +101 -19
- data/.gitignore +0 -16
- data/.rspec +0 -2
- data/.rubocop.yml +0 -39
- data/.ruby-version +0 -1
- data/.travis.yml +0 -4
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SearchKit::Clients::Search do
|
5
|
+
let(:client) { described_class.new }
|
6
|
+
let(:json) { response_body.to_json }
|
7
|
+
let(:response_body) { { data: {} } }
|
8
|
+
let(:response) { OpenStruct.new(body: json, status: status) }
|
9
|
+
let(:status) { 200 }
|
10
|
+
let(:token) { SearchKit.config.app_token }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(client.connection).to receive(:post).and_return(response)
|
14
|
+
allow(JSON).to receive(:parse).and_return(response_body)
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { client }
|
18
|
+
|
19
|
+
it { is_expected.to respond_to :token }
|
20
|
+
|
21
|
+
describe '#connection' do
|
22
|
+
subject { client.connection }
|
23
|
+
it { is_expected.to be_instance_of Faraday::Connection }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#search' do
|
27
|
+
let(:filters) { { size: 10.5, width: "Wide", gender: "Mens" } }
|
28
|
+
let(:options) { { phrase: phrase, filters: filters } }
|
29
|
+
let(:phrase) { "red boots" }
|
30
|
+
let(:slug) { "an-index-slug" }
|
31
|
+
|
32
|
+
let(:params) do
|
33
|
+
{
|
34
|
+
token: token,
|
35
|
+
data: { type: 'searches', attributes: options }
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
subject { client.search(slug, options) }
|
40
|
+
|
41
|
+
it { is_expected.to be_instance_of SearchKit::Models::Search }
|
42
|
+
|
43
|
+
it "calls #connection.get with the base events path" 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
|
+
|
51
|
+
subject
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when the response status is 400' do
|
55
|
+
let(:status) { 400 }
|
56
|
+
|
57
|
+
it "raises a bad request error" do
|
58
|
+
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when the response status is 401' do
|
63
|
+
let(:status) { 401 }
|
64
|
+
|
65
|
+
it "raises an unauthorized error" do
|
66
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the response status is 404' do
|
71
|
+
let(:status) { 404 }
|
72
|
+
|
73
|
+
it "raises an index not found error" do
|
74
|
+
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when the response status is 422' do
|
79
|
+
let(:status) { 422 }
|
80
|
+
|
81
|
+
it "raises an unprocessable error" do
|
82
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SearchKit::Clients::Subscribers do
|
5
|
+
let(:client) { described_class.new }
|
6
|
+
let(:email) { "email@example.com" }
|
7
|
+
let(:json) { response_body.to_json }
|
8
|
+
let(:password) { "password" }
|
9
|
+
let(:response_body) { { data: {} } }
|
10
|
+
let(:response) { OpenStruct.new(status: status, body: json) }
|
11
|
+
let(:subscriber) { SearchKit::Models::Subscriber.new }
|
12
|
+
let(:status) { 200 }
|
13
|
+
let(:token) { SearchKit.config.app_token }
|
14
|
+
|
15
|
+
before do
|
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
|
+
allow(JSON).to receive(:parse).and_return(response_body)
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { client }
|
23
|
+
|
24
|
+
it { is_expected.to respond_to :token }
|
25
|
+
|
26
|
+
describe '#connection' do
|
27
|
+
subject { client.connection }
|
28
|
+
it { is_expected.to be_instance_of Faraday::Connection }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#create' do
|
32
|
+
let(:params) do
|
33
|
+
{
|
34
|
+
data: {
|
35
|
+
type: 'subscribers',
|
36
|
+
attributes: { email: email, password: password }
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { client.create(email: email, password: password) }
|
42
|
+
|
43
|
+
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
|
44
|
+
|
45
|
+
it "calls #connection.post with given name" do
|
46
|
+
expect(client.connection).to receive(:post).with('', params)
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
|
50
|
+
it "parses the json response" do
|
51
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when given status 400' do
|
56
|
+
let(:status) { 400 }
|
57
|
+
|
58
|
+
it "throws a bad request error" do
|
59
|
+
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
|
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 '#info' do
|
74
|
+
subject { client.info }
|
75
|
+
|
76
|
+
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
|
77
|
+
|
78
|
+
it "calls #connection.get" do
|
79
|
+
expect(client.connection).to receive(:get).with("", 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 }
|
101
|
+
.to raise_exception SearchKit::Errors::SubscriberNotFound
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#update' do
|
108
|
+
let(:params) do
|
109
|
+
{
|
110
|
+
token: token,
|
111
|
+
data: {
|
112
|
+
type: 'subscribers',
|
113
|
+
attributes: { email: email, password: password }
|
114
|
+
}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
subject { client.update(email: email, password: password) }
|
119
|
+
|
120
|
+
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
|
121
|
+
|
122
|
+
it "calls #connection.patch with given id and attributes" do
|
123
|
+
expect(client.connection).to receive(:patch).with("", params)
|
124
|
+
subject
|
125
|
+
end
|
126
|
+
|
127
|
+
it "parses the json response" do
|
128
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when given status 400' do
|
133
|
+
let(:status) { 400 }
|
134
|
+
|
135
|
+
it "throws a bad request error" do
|
136
|
+
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when given status 401' do
|
141
|
+
let(:status) { 401 }
|
142
|
+
|
143
|
+
it "throws a not found error" do
|
144
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when given status 404' do
|
149
|
+
let(:status) { 404 }
|
150
|
+
|
151
|
+
it "throws a not found error" do
|
152
|
+
expect { subject }
|
153
|
+
.to raise_exception SearchKit::Errors::SubscriberNotFound
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when given status 422' do
|
158
|
+
let(:status) { 422 }
|
159
|
+
|
160
|
+
it "throws an Unprocessable error" do
|
161
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Configuration do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
|
6
|
+
before { klass.extend(described_class) }
|
7
|
+
|
8
|
+
subject { klass }
|
9
|
+
|
10
|
+
it { is_expected.to respond_to :config }
|
11
|
+
it { is_expected.to respond_to :configure }
|
12
|
+
|
13
|
+
describe "Arbitrary assignment" do
|
14
|
+
it "allows any arbitrary setting to hold a value" do
|
15
|
+
expect {
|
16
|
+
klass.configure do |config|
|
17
|
+
config.arbitrary_setting = "value"
|
18
|
+
end
|
19
|
+
}.to change { klass.config.arbitrary_setting }
|
20
|
+
.from(nil)
|
21
|
+
.to("value")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Messages do
|
4
|
+
let(:messages) { described_class.new }
|
5
|
+
let(:message) { "Just about any string" }
|
6
|
+
|
7
|
+
before do
|
8
|
+
SearchKit.config.verbose = true
|
9
|
+
|
10
|
+
allow(Kernel).to receive(:warn)
|
11
|
+
allow(Kernel).to receive(:puts)
|
12
|
+
allow(SearchKit.logger).to receive(:warn)
|
13
|
+
allow(SearchKit.logger).to receive(:info)
|
14
|
+
end
|
15
|
+
|
16
|
+
after { SearchKit.config.verbose = false }
|
17
|
+
|
18
|
+
describe "#info" do
|
19
|
+
subject { messages.info(message) }
|
20
|
+
|
21
|
+
it "warns in stderr" do
|
22
|
+
expect(Kernel).to receive(:puts)
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "logs a warning" do
|
27
|
+
expect(SearchKit.logger).to receive(:info).with(message)
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#warning" do
|
33
|
+
subject { messages.warning(message) }
|
34
|
+
|
35
|
+
it "warns in stderr" do
|
36
|
+
expect(Kernel).to receive(:warn)
|
37
|
+
subject
|
38
|
+
end
|
39
|
+
|
40
|
+
it "logs a warning" do
|
41
|
+
expect(SearchKit.logger).to receive(:warn).with(message)
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Document do
|
4
|
+
let(:document_data) { {} }
|
5
|
+
let(:document) { described_class.new(document_data) }
|
6
|
+
|
7
|
+
subject { document }
|
8
|
+
|
9
|
+
it { is_expected.to respond_to :id }
|
10
|
+
it { is_expected.to respond_to :source }
|
11
|
+
it { is_expected.to respond_to :score }
|
12
|
+
|
13
|
+
describe '#get' do
|
14
|
+
let(:key) { :a_key }
|
15
|
+
|
16
|
+
subject { document.get(key) }
|
17
|
+
|
18
|
+
context 'when the source has the available content' do
|
19
|
+
let(:content) { :key_content }
|
20
|
+
let(:document_data) { { attributes: { key => content } } }
|
21
|
+
|
22
|
+
it "returns the content" do
|
23
|
+
expect(subject).to eq content
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'otherwise' do
|
28
|
+
it "raises an attribute not found error" do
|
29
|
+
expect { subject }
|
30
|
+
.to raise_exception(described_class::AttributeNotFound)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Documents do
|
4
|
+
let(:document_data) { [{}] }
|
5
|
+
let(:documents) { described_class.new(document_data) }
|
6
|
+
|
7
|
+
subject { documents }
|
8
|
+
|
9
|
+
it { is_expected.to respond_to :contents }
|
10
|
+
it { is_expected.to respond_to :each }
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Event do
|
4
|
+
let(:event_data) { {} }
|
5
|
+
let(:event) { described_class.new(event_data) }
|
6
|
+
|
7
|
+
subject { event }
|
8
|
+
|
9
|
+
it { is_expected.to respond_to :id }
|
10
|
+
it { is_expected.to respond_to :channel }
|
11
|
+
it { is_expected.to respond_to :payload }
|
12
|
+
it { is_expected.to respond_to :state }
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Events do
|
4
|
+
let(:event_data) { [{}] }
|
5
|
+
let(:events) { described_class.new(event_data) }
|
6
|
+
|
7
|
+
subject { events }
|
8
|
+
|
9
|
+
it { is_expected.to respond_to :contents }
|
10
|
+
it { is_expected.to respond_to :each }
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Key do
|
4
|
+
let(:model) { described_class.new }
|
5
|
+
|
6
|
+
subject { model }
|
7
|
+
|
8
|
+
it { is_expected.to be_instance_of SearchKit::Models::Key }
|
9
|
+
it { is_expected.to respond_to :uri }
|
10
|
+
it { is_expected.to respond_to :token }
|
11
|
+
it { is_expected.to respond_to :name }
|
12
|
+
|
13
|
+
describe '#creator?' do
|
14
|
+
subject { model.creator? }
|
15
|
+
|
16
|
+
context 'when #privilege is set to "creator"' do
|
17
|
+
before { model.privilege = 'creator' }
|
18
|
+
it { is_expected.to be true }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'otherwise' do
|
22
|
+
it { is_expected.to be false }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::Models::Keys do
|
4
|
+
let(:creator_key) do
|
5
|
+
SearchKit::Models::Key.new(
|
6
|
+
attributes: {
|
7
|
+
privilege: 'creator',
|
8
|
+
token: creator_token
|
9
|
+
}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:consumer_key) do
|
14
|
+
SearchKit::Models::Key.new(
|
15
|
+
attributes: {
|
16
|
+
privilege: 'consumer',
|
17
|
+
token: consumer_token
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:creator_token) { "12345" }
|
23
|
+
let(:consumer_token) { "67890" }
|
24
|
+
let(:keys) { [ creator_key, consumer_key ] }
|
25
|
+
let(:model) { described_class.new(keys) }
|
26
|
+
|
27
|
+
subject { model }
|
28
|
+
|
29
|
+
describe "#creator" do
|
30
|
+
subject { model.creator }
|
31
|
+
it { is_expected.to be_instance_of described_class }
|
32
|
+
it { is_expected.to match described_class.new([creator_key]) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#tokens" do
|
36
|
+
subject { model.tokens }
|
37
|
+
it { is_expected.to match [creator_token, consumer_token] }
|
38
|
+
end
|
39
|
+
end
|