flying-sphinx 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FlyingSphinx::Configuration do
4
- describe '#initialize' do
5
- let(:api_server) { 'https://flying-sphinx.com/heroku' }
6
- let(:api_key) { 'foo-bar-baz' }
7
- let(:identifier) { 'app@heroku.com' }
8
- let(:encoded_identifier) {
9
- FakeWeb::Utility.encode_unsafe_chars_in_userinfo identifier
10
- }
11
-
12
- before :each do
13
- FakeWeb.register_uri(:get,
14
- "#{api_server}/app?api_key=#{api_key}&identifier=#{encoded_identifier}",
15
- :body => JSON.dump(
16
- :server => 'foo.bar.com',
17
- :port => 9319,
18
- :database_port => 10001
19
- )
20
- )
21
- end
22
-
23
- it "requests details from the server with the given API key" do
24
- FlyingSphinx::Configuration.new identifier, api_key
25
-
26
- FakeWeb.should have_requested :get,
27
- "#{api_server}/app?api_key=#{api_key}&identifier=#{encoded_identifier}"
28
- end
29
-
30
- it "sets the host from the server information" do
31
- config = FlyingSphinx::Configuration.new identifier, api_key
32
- config.host.should == 'foo.bar.com'
33
- end
34
-
35
- it "sets the port from the server information" do
36
- config = FlyingSphinx::Configuration.new identifier, api_key
37
- config.port.should == 9319
38
- end
39
-
40
- it "sets the port from the server information" do
41
- config = FlyingSphinx::Configuration.new identifier, api_key
42
- config.database_port.should == 10001
43
- end
44
- end
45
- end
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FlyingSphinx::IndexRequest do
4
- let(:api) { FlyingSphinx::API.new 'foo', 'bar' }
5
- let(:configuration) {
6
- stub(:configuration, :api => api, :sphinx_configuration => 'foo {}')
7
- }
8
-
9
- before :each do
10
- FlyingSphinx::Configuration.stub!(:new => configuration)
11
- FlyingSphinx::Tunnel.stub(:connect) { |config, block| block.call }
12
- end
13
-
14
- describe '.cancel_jobs' do
15
- before :each do
16
- Delayed::Job.stub!(:delete_all => true)
17
- end
18
-
19
- it "should not delete any rows if the delayed_jobs table does not exist" do
20
- Delayed::Job.stub!(:table_exists? => false)
21
- Delayed::Job.should_not_receive(:delete_all)
22
-
23
- FlyingSphinx::IndexRequest.cancel_jobs
24
- end
25
-
26
- it "should delete rows if the delayed_jobs table does exist" do
27
- Delayed::Job.stub!(:table_exists? => true)
28
- Delayed::Job.should_receive(:delete_all)
29
-
30
- FlyingSphinx::IndexRequest.cancel_jobs
31
- end
32
-
33
- it "should delete only Thinking Sphinx jobs" do
34
- Delayed::Job.stub!(:table_exists? => true)
35
- Delayed::Job.should_receive(:delete_all) do |sql|
36
- sql.should match(/handler LIKE '--- !ruby\/object:FlyingSphinx::\%'/)
37
- end
38
-
39
- FlyingSphinx::IndexRequest.cancel_jobs
40
- end
41
- end
42
-
43
- describe '#update_and_index' do
44
- let(:index_request) { FlyingSphinx::IndexRequest.new }
45
- let(:conf_params) { {:configuration => 'foo {}'} }
46
- let(:index_params) { {:indices => ''} }
47
-
48
- it "makes a new request" do
49
- api.should_receive(:put).with('/app', conf_params).and_return('ok')
50
- api.should_receive(:post).
51
- with('/app/indices', index_params).and_return(42)
52
- api.should_receive(:get).with('/app/indices/42').
53
- and_return(stub(:response, :body => 'PENDING'))
54
-
55
- begin
56
- Timeout::timeout(0.2) {
57
- index_request.update_and_index
58
- }
59
- rescue Timeout::Error
60
- end
61
- end
62
-
63
- it "should finish when the index request has been completed" do
64
- api.should_receive(:put).with('/app', conf_params).and_return('ok')
65
- api.should_receive(:post).
66
- with('/app/indices', index_params).and_return(42)
67
- api.should_receive(:get).with('/app/indices/42').
68
- and_return(stub(:response, :body => 'FINISHED'))
69
-
70
- index_request.update_and_index
71
- end
72
-
73
- context 'delta request without delta support' do
74
- it "should explain why the request failed" do
75
- api.should_receive(:put).with('/app', conf_params).and_return('ok')
76
- api.should_receive(:post).
77
- with('/app/indices', index_params).and_return('BLOCKED')
78
- index_request.should_receive(:puts).with('Your account does not support delta indexing. Upgrading plans is probably the best way around this.')
79
-
80
- index_request.update_and_index
81
- end
82
- end
83
- end
84
-
85
- describe '#perform' do
86
- let(:index_request) { FlyingSphinx::IndexRequest.new ['foo_delta'] }
87
- let(:index_params) { {:indices => 'foo_delta'} }
88
-
89
- it "makes a new request" do
90
- api.should_receive(:post).
91
- with('/app/indices', index_params).and_return(42)
92
- api.should_receive(:get).with('/app/indices/42').
93
- and_return(stub(:response, :body => 'PENDING'))
94
-
95
- begin
96
- Timeout::timeout(0.2) {
97
- index_request.perform
98
- }
99
- rescue Timeout::Error
100
- end
101
- end
102
-
103
- it "should finish when the index request has been completed" do
104
- api.should_receive(:post).
105
- with('/app/indices', index_params).and_return(42)
106
- api.should_receive(:get).with('/app/indices/42').
107
- and_return(stub(:response, :body => 'FINISHED'))
108
-
109
- index_request.perform
110
- end
111
- end
112
-
113
- describe "#display_name" do
114
- let(:index_request) {
115
- FlyingSphinx::IndexRequest.new ['foo_core', 'bar_core']
116
- }
117
-
118
- it "should display class name with all indexes" do
119
- index_request.display_name.should == "FlyingSphinx::IndexRequest for foo_core, bar_core"
120
- end
121
- end
122
- end