flying-sphinx 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +7 -0
- data/flying-sphinx.gemspec +3 -3
- data/lib/flying_sphinx.rb +4 -0
- data/lib/flying_sphinx/api.rb +12 -15
- data/lib/flying_sphinx/configuration.rb +4 -123
- data/lib/flying_sphinx/delayed_delta.rb +21 -25
- data/lib/flying_sphinx/index_request.rb +15 -22
- data/lib/flying_sphinx/rails.rb +1 -0
- data/lib/flying_sphinx/railtie.rb +1 -0
- data/lib/flying_sphinx/setting_files.rb +55 -0
- data/lib/flying_sphinx/sphinx_configuration.rb +23 -0
- data/lib/flying_sphinx/tasks.rb +0 -1
- data/lib/flying_sphinx/tunnel.rb +1 -1
- data/lib/flying_sphinx/version.rb +1 -1
- data/spec/light_spec_helper.rb +7 -0
- data/spec/spec_helper.rb +2 -12
- data/spec/specs/api_spec.rb +92 -0
- data/spec/specs/configuration_spec.rb +14 -163
- data/spec/specs/index_request_spec.rb +63 -61
- data/spec/specs/setting_files_spec.rb +92 -0
- data/spec/specs/sphinx_configuration_spec.rb +35 -0
- metadata +34 -25
@@ -0,0 +1,55 @@
|
|
1
|
+
class FlyingSphinx::SettingFiles
|
2
|
+
INDEX_SETTINGS = [:stopwords, :wordforms, :exceptions]
|
3
|
+
SOURCE_SETTINGS = [:mysql_ssl_cert, :mysql_ssl_key, :mysql_ssl_ca]
|
4
|
+
|
5
|
+
def initialize(indices = nil)
|
6
|
+
@indices = indices ||
|
7
|
+
ThinkingSphinx::Configuration.instance.configuration.indices
|
8
|
+
end
|
9
|
+
|
10
|
+
def upload_to(api)
|
11
|
+
each_file_for_setting do |setting, file|
|
12
|
+
api.post '/add_file',
|
13
|
+
:setting => setting.to_s,
|
14
|
+
:file_name => File.basename(file),
|
15
|
+
:content => File.read(file)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :indices
|
22
|
+
|
23
|
+
def each_file_for_setting(&block)
|
24
|
+
index_settings &block
|
25
|
+
source_settings &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def index_settings(&block)
|
29
|
+
settings_in_list_from_collection INDEX_SETTINGS, indices, &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def sources
|
33
|
+
@sources ||= indices.collect { |index|
|
34
|
+
index.respond_to?(:sources) ? index.sources : []
|
35
|
+
}.flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def source_settings(&block)
|
39
|
+
settings_in_list_from_collection SOURCE_SETTINGS, sources, &block
|
40
|
+
end
|
41
|
+
|
42
|
+
def setting_from(collection, setting)
|
43
|
+
collection.collect { |object|
|
44
|
+
object.respond_to?(setting) ? object.send(setting).to_s.split(' ') : []
|
45
|
+
}.flatten.uniq.compact
|
46
|
+
end
|
47
|
+
|
48
|
+
def settings_in_list_from_collection(settings, collection, &block)
|
49
|
+
settings.each do |setting|
|
50
|
+
setting_from(collection, setting).each { |file|
|
51
|
+
block.call setting, file
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class FlyingSphinx::SphinxConfiguration
|
2
|
+
def initialize(thinking_sphinx = ThinkingSphinx::Configuration.instance)
|
3
|
+
@thinking_sphinx = thinking_sphinx
|
4
|
+
end
|
5
|
+
|
6
|
+
def upload_to(api, tunnel = false)
|
7
|
+
api.put '/',
|
8
|
+
:configuration => content,
|
9
|
+
:sphinx_version => thinking_sphinx.version,
|
10
|
+
:tunnel => tunnel.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :thinking_sphinx
|
16
|
+
|
17
|
+
def content
|
18
|
+
@content ||= begin
|
19
|
+
thinking_sphinx.generate
|
20
|
+
thinking_sphinx.configuration.render
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/flying_sphinx/tasks.rb
CHANGED
data/lib/flying_sphinx/tunnel.rb
CHANGED
@@ -18,7 +18,7 @@ class FlyingSphinx::Tunnel
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def open(&block)
|
21
|
-
session = Net::SSH.start(@configuration.
|
21
|
+
session = Net::SSH.start(@configuration.ssh_server, 'sphinx', ssh_options)
|
22
22
|
session.forward.remote(
|
23
23
|
db_port, db_host, @configuration.database_port, '0.0.0.0'
|
24
24
|
)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
require 'bundler'
|
4
|
-
rescue LoadError
|
5
|
-
puts "although not required, it's recommended you use bundler during development"
|
6
|
-
end
|
2
|
+
require 'bundler'
|
7
3
|
|
8
4
|
require 'timeout'
|
9
|
-
|
10
5
|
require 'thinking-sphinx'
|
11
6
|
require 'flying_sphinx'
|
12
7
|
require 'delayed_job'
|
@@ -15,9 +10,4 @@ require 'fakeweb'
|
|
15
10
|
require 'fakeweb_matcher'
|
16
11
|
|
17
12
|
FakeWeb.allow_net_connect = false
|
18
|
-
|
19
|
-
Delayed::Worker.backend = :active_record
|
20
|
-
|
21
|
-
# we don't want a checking of interval in testing
|
22
|
-
FlyingSphinx::IndexRequest.send(:remove_const, :INDEX_COMPLETE_CHECKING_INTERVAL)
|
23
|
-
FlyingSphinx::IndexRequest::INDEX_COMPLETE_CHECKING_INTERVAL = 0
|
13
|
+
Delayed::Worker.backend = :active_record
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'light_spec_helper'
|
2
|
+
require 'flying_sphinx/api'
|
3
|
+
require 'flying_sphinx/version'
|
4
|
+
|
5
|
+
describe FlyingSphinx::API do
|
6
|
+
let(:api) { FlyingSphinx::API.new 'foo', 'bar', adapter }
|
7
|
+
let(:faraday) { fire_class_double('Faraday', :new => connection) }
|
8
|
+
let(:adapter) { double('adapter') }
|
9
|
+
let(:connection) { double('connection') }
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
faraday.as_replaced_constant
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples_for 'an API call' do
|
16
|
+
it "sets up a connection with the appropriate headers" do
|
17
|
+
faraday.should_receive(:new) do |options|
|
18
|
+
options[:headers].should == {
|
19
|
+
'Accept' => 'application/vnd.flying-sphinx-v3+json',
|
20
|
+
'X-Flying-Sphinx-Token' => 'foo:bar',
|
21
|
+
'X-Flying-Sphinx-Version' => FlyingSphinx::Version
|
22
|
+
}
|
23
|
+
|
24
|
+
connection
|
25
|
+
end
|
26
|
+
|
27
|
+
send_request
|
28
|
+
end
|
29
|
+
|
30
|
+
it "connects to flying-sphinx.com with SSL" do
|
31
|
+
faraday.should_receive(:new) do |options|
|
32
|
+
options[:url].should == 'https://flying-sphinx.com'
|
33
|
+
|
34
|
+
connection
|
35
|
+
end
|
36
|
+
|
37
|
+
send_request
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#get' do
|
42
|
+
let(:request) { double('request', :url => true) }
|
43
|
+
let(:send_request) { api.get '/resource', 'param' => 'value'}
|
44
|
+
|
45
|
+
before :each do
|
46
|
+
connection.stub(:get).and_yield(request)
|
47
|
+
end
|
48
|
+
|
49
|
+
it_should_behave_like 'an API call'
|
50
|
+
|
51
|
+
it "sends the GET request with the given path and data" do
|
52
|
+
request.should_receive(:url).
|
53
|
+
with('/api/my/app/resource', 'param' => 'value')
|
54
|
+
|
55
|
+
send_request
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#post' do
|
60
|
+
let(:send_request) { api.post '/resource', 'param' => 'value' }
|
61
|
+
|
62
|
+
before :each do
|
63
|
+
connection.stub(:post => true)
|
64
|
+
end
|
65
|
+
|
66
|
+
it_should_behave_like 'an API call'
|
67
|
+
|
68
|
+
it "sends the POST request with the given path and data" do
|
69
|
+
connection.should_receive(:post).
|
70
|
+
with('/api/my/app/resource', 'param' => 'value')
|
71
|
+
|
72
|
+
send_request
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#put' do
|
77
|
+
let(:send_request) { api.put '/resource', 'param' => 'value' }
|
78
|
+
|
79
|
+
before :each do
|
80
|
+
connection.stub(:put => true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it_should_behave_like 'an API call'
|
84
|
+
|
85
|
+
it "sends the PUT request with the given path and data" do
|
86
|
+
connection.should_receive(:put).
|
87
|
+
with('/api/my/app/resource', 'param' => 'value')
|
88
|
+
|
89
|
+
send_request
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,184 +1,35 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'light_spec_helper'
|
2
|
+
require 'flying_sphinx/configuration'
|
3
3
|
|
4
4
|
describe FlyingSphinx::Configuration do
|
5
|
-
let(:
|
5
|
+
let(:api) { fire_double('FlyingSphinx::API',
|
6
|
+
:get => double(:body => body, :status => 200)) }
|
7
|
+
let(:body) { double(:server => 'foo.bar.com', :port => 9319,
|
8
|
+
:ssh_server => 'ssh.bar.com', :database_port => 10319) }
|
6
9
|
|
7
10
|
before :each do
|
8
|
-
|
9
|
-
:body => MultiJson.encode(
|
10
|
-
:server => 'foo.bar.com',
|
11
|
-
:port => 9319,
|
12
|
-
:database_port => 10001
|
13
|
-
)
|
14
|
-
)
|
11
|
+
fire_class_double('FlyingSphinx::API', :new => api).as_replaced_constant
|
15
12
|
end
|
16
13
|
|
17
14
|
describe '#initialize' do
|
18
15
|
let(:api_key) { 'foo-bar-baz' }
|
19
|
-
let(:identifier) { '
|
16
|
+
let(:identifier) { 'my-identifier' }
|
20
17
|
let(:config) { FlyingSphinx::Configuration.new identifier, api_key }
|
21
18
|
|
22
|
-
it "
|
23
|
-
config
|
24
|
-
FakeWeb.should have_requested :get, "#{api_server}/app"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets the host from the server information" do
|
19
|
+
it "sets the host from the API information" do
|
28
20
|
config.host.should == 'foo.bar.com'
|
29
21
|
end
|
30
22
|
|
31
|
-
it "sets the port from the
|
23
|
+
it "sets the port from the API information" do
|
32
24
|
config.port.should == 9319
|
33
25
|
end
|
34
26
|
|
35
|
-
it "sets the
|
36
|
-
config.
|
27
|
+
it "sets the ssh server address" do
|
28
|
+
config.ssh_server.should == 'ssh.bar.com'
|
37
29
|
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#file_setting_pairs' do
|
41
|
-
let(:config) { FlyingSphinx::Configuration.new 'ident' }
|
42
|
-
let(:riddle) { ThinkingSphinx::Configuration.instance.configuration }
|
43
|
-
let(:base_path) { '/mnt/sphinx/flying-sphinx/ident' }
|
44
|
-
|
45
|
-
context 'index setting' do
|
46
|
-
it "pairs each local file path to a server file path" do
|
47
|
-
riddle.stub! :indices => [
|
48
|
-
double('index', :wordforms => '/path/to/wordforms-foo.txt',
|
49
|
-
:sources => [double('source'), double('source')]),
|
50
|
-
double('index', :wordforms => '/path/to/wordforms-bar.txt',
|
51
|
-
:sources => [double('source'), double('source')])
|
52
|
-
]
|
53
|
-
|
54
|
-
config.file_setting_pairs(:wordforms).should == {
|
55
|
-
'/path/to/wordforms-foo.txt' => "#{base_path}/wordforms/0.txt",
|
56
|
-
'/path/to/wordforms-bar.txt' => "#{base_path}/wordforms/1.txt"
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
it "doesn't duplicate multiple references to the same local file" do
|
61
|
-
riddle.stub! :indices => [
|
62
|
-
double('index', :wordforms => '/path/to/wordforms-foo.txt',
|
63
|
-
:sources => [double('source'), double('source')]),
|
64
|
-
double('index', :wordforms => '/path/to/wordforms-foo.txt',
|
65
|
-
:sources => [double('source'), double('source')])
|
66
|
-
]
|
67
|
-
|
68
|
-
config.file_setting_pairs(:wordforms).should == {
|
69
|
-
'/path/to/wordforms-foo.txt' => "#{base_path}/wordforms/0.txt"
|
70
|
-
}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'source setting' do
|
75
|
-
it "pairs each local file path to a server file path" do
|
76
|
-
riddle.stub! :indices => [
|
77
|
-
double('index', :sources => [
|
78
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-foo.txt'),
|
79
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-bar.txt')
|
80
|
-
]),
|
81
|
-
double('index', :sources => [
|
82
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-baz.txt'),
|
83
|
-
double('source', :mysql_ssl_cert => nil)
|
84
|
-
])
|
85
|
-
]
|
86
|
-
|
87
|
-
config.file_setting_pairs(:mysql_ssl_cert).should == {
|
88
|
-
'/path/to/cert-foo.txt' => "#{base_path}/mysql_ssl_cert/0.txt",
|
89
|
-
'/path/to/cert-bar.txt' => "#{base_path}/mysql_ssl_cert/1.txt",
|
90
|
-
'/path/to/cert-baz.txt' => "#{base_path}/mysql_ssl_cert/2.txt"
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
it "doesn't duplicate multiple references to the same local file" do
|
95
|
-
riddle.stub! :indices => [
|
96
|
-
double('index', :sources => [
|
97
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-foo.txt'),
|
98
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-bar.txt')
|
99
|
-
]),
|
100
|
-
double('index', :sources => [
|
101
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-foo.txt'),
|
102
|
-
double('source', :mysql_ssl_cert => nil)
|
103
|
-
])
|
104
|
-
]
|
105
|
-
|
106
|
-
config.file_setting_pairs(:mysql_ssl_cert).should == {
|
107
|
-
'/path/to/cert-foo.txt' => "#{base_path}/mysql_ssl_cert/0.txt",
|
108
|
-
'/path/to/cert-bar.txt' => "#{base_path}/mysql_ssl_cert/1.txt"
|
109
|
-
}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#sphinx_configuration' do
|
115
|
-
let(:config) { FlyingSphinx::Configuration.new 'ident' }
|
116
|
-
let(:riddle) { double('riddle configuration').as_null_object }
|
117
|
-
let(:base_path) { '/mnt/sphinx/flying-sphinx/ident' }
|
118
|
-
let(:source) { double('source') }
|
119
|
-
|
120
|
-
before :each do
|
121
|
-
ThinkingSphinx::Configuration.instance.stub!(
|
122
|
-
:generate => nil,
|
123
|
-
:configuration => riddle
|
124
|
-
)
|
125
|
-
FlyingSphinx::Tunnel.stub! :required? => false
|
126
|
-
end
|
127
|
-
|
128
|
-
it "sets database settings to match Flying Sphinx port forward" do
|
129
|
-
FlyingSphinx::Tunnel.stub! :required? => true
|
130
|
-
|
131
|
-
riddle.stub! :indices => [
|
132
|
-
double('distributed index'),
|
133
|
-
double('index', :sources => [source])
|
134
|
-
]
|
135
|
-
|
136
|
-
source.should_receive(:sql_host=).with('127.0.0.1')
|
137
|
-
source.should_receive(:sql_port=).with(10001)
|
138
|
-
|
139
|
-
config.sphinx_configuration
|
140
|
-
end
|
141
|
-
|
142
|
-
it "sets file path to match server directories for index settings" do
|
143
|
-
riddle.stub! :indices => [
|
144
|
-
double('index', :wordforms => '/path/to/wordforms-foo.txt',
|
145
|
-
:sources => [double('source'), double('source')]),
|
146
|
-
double('index', :wordforms => '/path/to/wordforms-bar.txt',
|
147
|
-
:sources => [double('source'), double('source')]),
|
148
|
-
double('distributed index')
|
149
|
-
]
|
150
|
-
|
151
|
-
riddle.indices[0].should_receive(:wordforms=).
|
152
|
-
with("#{base_path}/wordforms/0.txt")
|
153
|
-
riddle.indices[1].should_receive(:wordforms=).
|
154
|
-
with("#{base_path}/wordforms/1.txt")
|
155
|
-
|
156
|
-
config.sphinx_configuration
|
157
|
-
end
|
158
|
-
|
159
|
-
it "sets file path to match server directories for source settings" do
|
160
|
-
riddle.stub! :indices => [
|
161
|
-
double('index', :sources => [
|
162
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-foo.txt'),
|
163
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-bar.txt')
|
164
|
-
]),
|
165
|
-
double('index', :sources => [
|
166
|
-
double('source', :mysql_ssl_cert => '/path/to/cert-baz.txt'),
|
167
|
-
double('source', :mysql_ssl_cert => nil)
|
168
|
-
]),
|
169
|
-
double('distributed index')
|
170
|
-
]
|
171
|
-
|
172
|
-
riddle.indices[0].sources[0].should_receive(:mysql_ssl_cert=).
|
173
|
-
with("#{base_path}/mysql_ssl_cert/0.txt")
|
174
|
-
riddle.indices[0].sources[1].should_receive(:mysql_ssl_cert=).
|
175
|
-
with("#{base_path}/mysql_ssl_cert/1.txt")
|
176
|
-
riddle.indices[1].sources[0].should_receive(:mysql_ssl_cert=).
|
177
|
-
with("#{base_path}/mysql_ssl_cert/2.txt")
|
178
|
-
riddle.indices[1].sources[1].should_receive(:mysql_ssl_cert=).
|
179
|
-
with(nil)
|
180
30
|
|
181
|
-
|
31
|
+
it "sets the database port" do
|
32
|
+
config.database_port.should == 10319
|
182
33
|
end
|
183
34
|
end
|
184
35
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'light_spec_helper'
|
2
|
+
require 'net/ssh/errors'
|
3
|
+
require 'timeout'
|
4
|
+
require 'flying_sphinx/index_request'
|
2
5
|
|
3
6
|
describe FlyingSphinx::IndexRequest do
|
4
|
-
let(:api) { FlyingSphinx::API
|
5
|
-
let(:configuration) {
|
6
|
-
|
7
|
-
|
8
|
-
}
|
7
|
+
let(:api) { fire_double('FlyingSphinx::API') }
|
8
|
+
let(:configuration) { stub(:configuration, :api => api) }
|
9
|
+
let(:tunnel_class) { fire_class_double('FlyingSphinx::Tunnel').
|
10
|
+
as_replaced_constant }
|
9
11
|
|
10
12
|
let(:index_response) {
|
11
13
|
stub(:response, :body => stub(:body, :id => 42, :status => 'OK'))
|
@@ -15,34 +17,39 @@ describe FlyingSphinx::IndexRequest do
|
|
15
17
|
}
|
16
18
|
|
17
19
|
before :each do
|
18
|
-
|
20
|
+
stub_const 'FlyingSphinx::Configuration', double(:new => configuration)
|
19
21
|
|
20
|
-
FlyingSphinx::
|
21
|
-
|
22
|
+
stub_const 'FlyingSphinx::IndexRequest::INDEX_COMPLETE_CHECKING_INTERVAL',
|
23
|
+
0
|
22
24
|
end
|
23
25
|
|
24
26
|
describe '.cancel_jobs' do
|
27
|
+
let(:job_class) { fire_class_double('Delayed::Job').as_replaced_constant }
|
28
|
+
|
25
29
|
before :each do
|
26
|
-
|
30
|
+
job_class.stub :delete_all => true
|
27
31
|
end
|
28
32
|
|
29
33
|
it "should not delete any rows if the delayed_jobs table does not exist" do
|
30
|
-
|
31
|
-
|
34
|
+
job_class.stub :table_exists? => false
|
35
|
+
|
36
|
+
job_class.should_not_receive(:delete_all)
|
32
37
|
|
33
38
|
FlyingSphinx::IndexRequest.cancel_jobs
|
34
39
|
end
|
35
40
|
|
36
41
|
it "should delete rows if the delayed_jobs table does exist" do
|
37
|
-
|
38
|
-
|
42
|
+
job_class.stub :table_exists? => true
|
43
|
+
|
44
|
+
job_class.should_receive(:delete_all)
|
39
45
|
|
40
46
|
FlyingSphinx::IndexRequest.cancel_jobs
|
41
47
|
end
|
42
48
|
|
43
49
|
it "should delete only Thinking Sphinx jobs" do
|
44
|
-
|
45
|
-
|
50
|
+
job_class.stub :table_exists? => true
|
51
|
+
|
52
|
+
job_class.should_receive(:delete_all) do |sql|
|
46
53
|
sql.should match(/handler LIKE '--- !ruby\/object:FlyingSphinx::\%'/)
|
47
54
|
end
|
48
55
|
|
@@ -55,16 +62,23 @@ describe FlyingSphinx::IndexRequest do
|
|
55
62
|
let(:conf_params) { { :configuration => 'foo {}',
|
56
63
|
:sphinx_version => '2.1.0-dev' } }
|
57
64
|
let(:index_params) { { :indices => '' } }
|
58
|
-
let(:
|
65
|
+
let(:sphinx) { fire_double('FlyingSphinx::SphinxConfiguration',
|
66
|
+
:upload_to => true)}
|
67
|
+
let(:setting_files) { fire_double('FlyingSphinx::SettingFiles',
|
68
|
+
:upload_to => true) }
|
59
69
|
|
60
70
|
before :each do
|
61
|
-
|
71
|
+
stub_const 'FlyingSphinx::SettingFiles', double(:new => setting_files)
|
72
|
+
stub_const 'FlyingSphinx::SphinxConfiguration', double(:new => sphinx)
|
73
|
+
|
74
|
+
api.stub :post => index_response
|
75
|
+
|
76
|
+
tunnel_class.stub :required? => true
|
77
|
+
tunnel_class.stub(:connect).and_yield
|
62
78
|
end
|
63
79
|
|
64
|
-
it "
|
65
|
-
|
66
|
-
api.should_receive(:post).
|
67
|
-
with('indices', index_params).and_return(index_response)
|
80
|
+
it "uploads the configuration file" do
|
81
|
+
sphinx.should_receive(:upload_to).with(api, true)
|
68
82
|
|
69
83
|
begin
|
70
84
|
Timeout::timeout(0.2) {
|
@@ -74,44 +88,31 @@ describe FlyingSphinx::IndexRequest do
|
|
74
88
|
end
|
75
89
|
end
|
76
90
|
|
77
|
-
|
78
|
-
:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
{:setting => setting.to_s, :file_name => 'bar.txt', :content => 'baz'}
|
91
|
+
it "uploads setting files" do
|
92
|
+
setting_files.should_receive(:upload_to).with(api)
|
93
|
+
|
94
|
+
begin
|
95
|
+
Timeout::timeout(0.2) {
|
96
|
+
index_request.update_and_index
|
84
97
|
}
|
98
|
+
rescue Timeout::Error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "makes a new request" do
|
103
|
+
api.should_receive(:post).
|
104
|
+
with('indices', index_params).and_return(index_response)
|
85
105
|
|
86
|
-
|
87
|
-
|
88
|
-
index_request.
|
89
|
-
|
90
|
-
|
91
|
-
it "sends the #{setting} file" do
|
92
|
-
api.should_receive(:put).with('/', conf_params).and_return('ok')
|
93
|
-
api.should_receive(:post).with('/add_file', file_params).
|
94
|
-
and_return('ok')
|
95
|
-
api.should_receive(:post).
|
96
|
-
with('indices', index_params).and_return(index_response)
|
97
|
-
|
98
|
-
configuration.should_receive(:file_setting_pairs).
|
99
|
-
with(setting).and_return({'foo.txt' => 'bar.txt'})
|
100
|
-
|
101
|
-
begin
|
102
|
-
Timeout::timeout(0.2) {
|
103
|
-
index_request.update_and_index
|
104
|
-
}
|
105
|
-
rescue Timeout::Error
|
106
|
-
end
|
107
|
-
end
|
106
|
+
begin
|
107
|
+
Timeout::timeout(0.2) {
|
108
|
+
index_request.update_and_index
|
109
|
+
}
|
110
|
+
rescue Timeout::Error
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
111
114
|
context 'delta request without delta support' do
|
112
115
|
it "should explain why the request failed" do
|
113
|
-
api.should_receive(:put).
|
114
|
-
with('/', conf_params).and_return('ok')
|
115
116
|
api.should_receive(:post).
|
116
117
|
with('indices', index_params).and_return(blocked_response)
|
117
118
|
index_request.should_receive(:puts).
|
@@ -123,17 +124,12 @@ describe FlyingSphinx::IndexRequest do
|
|
123
124
|
|
124
125
|
context 'request for a MySQL database' do
|
125
126
|
before :each do
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
after :each do
|
130
|
-
ThinkingSphinx.database_adapter = FlyingSphinx::HerokuSharedAdapter
|
127
|
+
tunnel_class.stub :required? => false
|
131
128
|
end
|
132
129
|
|
133
130
|
it "should not establish an SSH connection" do
|
134
131
|
FlyingSphinx::Tunnel.should_not_receive(:connect)
|
135
132
|
|
136
|
-
api.should_receive(:put).with('/', conf_params).and_return('ok')
|
137
133
|
api.should_receive(:post).
|
138
134
|
with('indices', index_params).and_return(index_response)
|
139
135
|
api.should_receive(:get).with('indices/42').
|
@@ -148,6 +144,11 @@ describe FlyingSphinx::IndexRequest do
|
|
148
144
|
let(:index_request) { FlyingSphinx::IndexRequest.new ['foo_delta'] }
|
149
145
|
let(:index_params) { { :indices => 'foo_delta' } }
|
150
146
|
|
147
|
+
before :each do
|
148
|
+
tunnel_class.stub :required? => true
|
149
|
+
tunnel_class.stub(:connect).and_yield
|
150
|
+
end
|
151
|
+
|
151
152
|
it "makes a new request" do
|
152
153
|
api.should_receive(:post).
|
153
154
|
with('indices', index_params).and_return(index_response)
|
@@ -164,7 +165,8 @@ describe FlyingSphinx::IndexRequest do
|
|
164
165
|
describe '#status_message' do
|
165
166
|
let(:index_request) { FlyingSphinx::IndexRequest.new }
|
166
167
|
let(:finished_response) {
|
167
|
-
stub(:response, :body => stub(:body, :status => 'FINISHED'
|
168
|
+
stub(:response, :body => stub(:body, :status => 'FINISHED',
|
169
|
+
:log => 'Sphinx log'))
|
168
170
|
}
|
169
171
|
let(:failure_response) {
|
170
172
|
stub(:response, :body => stub(:body, :status => 'FAILED'))
|
@@ -185,7 +187,7 @@ describe FlyingSphinx::IndexRequest do
|
|
185
187
|
it "returns with a positive message on success" do
|
186
188
|
api.stub(:get => finished_response)
|
187
189
|
|
188
|
-
index_request.status_message.should ==
|
190
|
+
index_request.status_message.should == "Index Request has completed:\nSphinx log"
|
189
191
|
end
|
190
192
|
|
191
193
|
it "returns with a failure message on failure" do
|