flying-sphinx 0.8.5 → 1.0.0

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.
@@ -1,172 +0,0 @@
1
- require 'light_spec_helper'
2
- require 'timeout'
3
- require 'flying_sphinx/index_request'
4
-
5
- describe FlyingSphinx::IndexRequest do
6
- let(:api) { fire_double('FlyingSphinx::API') }
7
- let(:configuration) { stub(:configuration, :api => api) }
8
-
9
- let(:index_response) {
10
- stub(:response, :body => stub(:body, :id => 42, :status => 'OK'))
11
- }
12
- let(:blocked_response) {
13
- stub(:response, :body => stub(:body, :id => nil, :status => 'BLOCKED'))
14
- }
15
-
16
- before :each do
17
- stub_const 'FlyingSphinx::Configuration', double(:new => configuration)
18
- stub_const 'FlyingSphinx::IndexRequest::INDEX_COMPLETE_CHECKING_INTERVAL',
19
- 0
20
- end
21
-
22
- describe '.cancel_jobs' do
23
- let(:job_class) { fire_class_double('Delayed::Job').as_replaced_constant }
24
-
25
- before :each do
26
- job_class.stub :delete_all => true
27
- end
28
-
29
- it "should not delete any rows if the delayed_jobs table does not exist" do
30
- job_class.stub :table_exists? => false
31
-
32
- job_class.should_not_receive(:delete_all)
33
-
34
- FlyingSphinx::IndexRequest.cancel_jobs
35
- end
36
-
37
- it "should delete rows if the delayed_jobs table does exist" do
38
- job_class.stub :table_exists? => true
39
-
40
- job_class.should_receive(:delete_all)
41
-
42
- FlyingSphinx::IndexRequest.cancel_jobs
43
- end
44
-
45
- it "should delete only Thinking Sphinx jobs" do
46
- job_class.stub :table_exists? => true
47
-
48
- job_class.should_receive(:delete_all) do |sql|
49
- sql.should match(/handler LIKE '--- !ruby\/object:FlyingSphinx::\%'/)
50
- end
51
-
52
- FlyingSphinx::IndexRequest.cancel_jobs
53
- end
54
- end
55
-
56
- describe '#index' do
57
- let(:index_request) { FlyingSphinx::IndexRequest.new }
58
- let(:index_params) { { :indices => '' } }
59
- let(:status_response) { stub(:response,
60
- :body => stub(:body, :status => 'FINISHED')) }
61
-
62
- before :each do
63
- api.stub :post => index_response, :get => status_response
64
- end
65
-
66
- it "makes a new request" do
67
- api.should_receive(:post).
68
- with('indices', index_params).and_return(index_response)
69
-
70
- index_request.index
71
- end
72
-
73
- it "checks the status of the request" do
74
- api.should_receive(:get).with('indices/42').and_return(status_response)
75
-
76
- index_request.index
77
- end
78
-
79
- context 'delta request without delta support' do
80
- it "should explain why the request failed" do
81
- api.should_receive(:post).
82
- with('indices', index_params).and_return(blocked_response)
83
-
84
- lambda {
85
- index_request.index
86
- }.should raise_error(RuntimeError, 'Your account does not support delta indexing. Upgrading plans is probably the best way around this.')
87
- end
88
- end
89
-
90
- context 'asynchronous' do
91
- let(:index_request) { FlyingSphinx::IndexRequest.new [], true }
92
-
93
- it "makes a new request" do
94
- api.should_receive(:post).
95
- with('indices/unique', index_params).and_return(index_response)
96
-
97
- index_request.index
98
- end
99
-
100
- it "does not check the status" do
101
- api.should_not_receive(:get)
102
-
103
- index_request.index
104
- end
105
- end
106
- end
107
-
108
- describe '#status_message' do
109
- let(:index_request) { FlyingSphinx::IndexRequest.new }
110
- let(:finished_response) {
111
- stub(:response, :body => stub(:body, :status => 'FINISHED',
112
- :log => 'Sphinx log'))
113
- }
114
- let(:failure_response) {
115
- stub(:response, :body => stub(:body, :status => 'FAILED'))
116
- }
117
- let(:pending_response) {
118
- stub(:response, :body => stub(:body, :status => 'PENDING'))
119
- }
120
- let(:unknown_response) {
121
- stub(:response, :body => stub(:body, :status => 'UNKNOWN'))
122
- }
123
-
124
- before :each do
125
- api.stub(:post => index_response)
126
-
127
- index_request.instance_variable_set :@index_id, 42
128
- end
129
-
130
- it "returns with a positive message on success" do
131
- api.stub(:get => finished_response)
132
-
133
- index_request.status_message.should == "Index Request has completed:\nSphinx log"
134
- end
135
-
136
- it "returns with a failure message on failure" do
137
- api.stub(:get => failure_response)
138
-
139
- index_request.status_message.should == 'Index Request failed.'
140
- end
141
-
142
- it "warns the user if the request is still pending" do
143
- api.stub(:get => pending_response)
144
-
145
- index_request.status_message.should == 'Index Request is still pending - something has gone wrong.'
146
- end
147
-
148
- it "treats all other statuses as unknown" do
149
- api.stub(:get => unknown_response)
150
-
151
- index_request.status_message.should == "Unknown index response: 'UNKNOWN'."
152
- end
153
-
154
- it "raises a warning if the index id isn't set" do
155
- index_request.instance_variable_set :@index_id, nil
156
-
157
- lambda {
158
- index_request.status_message
159
- }.should raise_error
160
- end
161
- end
162
-
163
- describe "#display_name" do
164
- let(:index_request) {
165
- FlyingSphinx::IndexRequest.new ['foo_core', 'bar_core']
166
- }
167
-
168
- it "should display class name with all indexes" do
169
- index_request.display_name.should == "FlyingSphinx::IndexRequest for foo_core, bar_core"
170
- end
171
- end
172
- end
@@ -1,42 +0,0 @@
1
- require 'light_spec_helper'
2
- require 'flying_sphinx/sphinx_configuration'
3
-
4
- describe FlyingSphinx::SphinxConfiguration do
5
- let(:configuration) { FlyingSphinx::SphinxConfiguration.new ts_config }
6
- let(:ts_config) { fire_double('ThinkingSphinx::Configuration',
7
- :configuration => riddle_config, :version => '2.1.0-dev',
8
- :generate => true) }
9
- let(:searchd) { fire_double('Riddle::Configuration::Searchd',
10
- :client_key= => true) }
11
- let(:riddle_config) { fire_double('Riddle::Configuration',
12
- :render => 'foo {}', :searchd => searchd) }
13
- let(:fs_config) { fire_double('FlyingSphinx::Configuration',
14
- :client_key => 'foo:bar') }
15
-
16
- describe '#upload_to' do
17
- before :each do
18
- stub_const 'FlyingSphinx::Configuration', double(:new => fs_config)
19
- end
20
-
21
- let(:api) { fire_double('FlyingSphinx::API', :put => true) }
22
-
23
- it "generates the Sphinx configuration" do
24
- ts_config.should_receive(:generate)
25
-
26
- configuration.upload_to api
27
- end
28
-
29
- it "sets the client key" do
30
- searchd.should_receive(:client_key=).with('foo:bar')
31
-
32
- configuration.upload_to api
33
- end
34
-
35
- it "sends the configuration to the API" do
36
- api.should_receive(:put).with('/', :configuration => 'foo {}',
37
- :sphinx_version => '2.1.0-dev')
38
-
39
- configuration.upload_to api
40
- end
41
- end
42
- end