thinking-sphinx 3.2.0 → 3.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/Gemfile +2 -1
- data/HISTORY +19 -0
- data/README.textile +3 -2
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/thinking_sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
- data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +3 -2
- data/lib/thinking_sphinx/connection.rb +23 -10
- data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
- data/lib/thinking_sphinx/errors.rb +25 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
- data/lib/thinking_sphinx/railtie.rb +1 -1
- data/lib/thinking_sphinx/rake_interface.rb +71 -23
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
- data/lib/thinking_sphinx/real_time/populator.rb +3 -3
- data/lib/thinking_sphinx/tasks.rb +7 -8
- data/lib/thinking_sphinx/wildcard.rb +1 -1
- data/spec/acceptance/association_scoping_spec.rb +5 -5
- data/spec/acceptance/attribute_access_spec.rb +4 -4
- data/spec/acceptance/attribute_updates_spec.rb +3 -3
- data/spec/acceptance/batch_searching_spec.rb +4 -4
- data/spec/acceptance/big_integers_spec.rb +6 -6
- data/spec/acceptance/connection_spec.rb +23 -0
- data/spec/acceptance/excerpts_spec.rb +8 -8
- data/spec/acceptance/facets_spec.rb +13 -13
- data/spec/acceptance/geosearching_spec.rb +8 -8
- data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
- data/spec/acceptance/index_options_spec.rb +16 -16
- data/spec/acceptance/indexing_spec.rb +3 -3
- data/spec/acceptance/paginating_search_results_spec.rb +3 -3
- data/spec/acceptance/real_time_updates_spec.rb +4 -4
- data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
- data/spec/acceptance/search_counts_spec.rb +2 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
- data/spec/acceptance/searching_across_models_spec.rb +6 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
- data/spec/acceptance/searching_on_fields_spec.rb +9 -9
- data/spec/acceptance/searching_with_filters_spec.rb +16 -16
- data/spec/acceptance/searching_with_sti_spec.rb +9 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
- data/spec/acceptance/sorting_search_results_spec.rb +6 -6
- data/spec/acceptance/specifying_sql_spec.rb +62 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
- data/spec/acceptance/sql_deltas_spec.rb +7 -7
- data/spec/acceptance/support/database_cleaner.rb +1 -1
- data/spec/acceptance/support/sphinx_controller.rb +4 -1
- data/spec/acceptance/support/sphinx_helpers.rb +4 -0
- data/spec/acceptance/suspended_deltas_spec.rb +9 -9
- data/spec/internal/app/indices/article_index.rb +2 -2
- data/spec/internal/app/indices/book_index.rb +2 -1
- data/spec/internal/app/indices/product_index.rb +0 -2
- data/spec/internal/app/models/categorisation.rb +8 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/json_column.rb +5 -1
- data/spec/support/multi_schema.rb +3 -1
- data/spec/support/sphinx_yaml_helpers.rb +1 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
- data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
- data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
- data/spec/thinking_sphinx/configuration_spec.rb +81 -81
- data/spec/thinking_sphinx/connection_spec.rb +13 -13
- data/spec/thinking_sphinx/deletion_spec.rb +11 -11
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
- data/spec/thinking_sphinx/deltas_spec.rb +12 -12
- data/spec/thinking_sphinx/errors_spec.rb +30 -30
- data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
- data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
- data/spec/thinking_sphinx/index_set_spec.rb +7 -7
- data/spec/thinking_sphinx/index_spec.rb +24 -24
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
- data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
- data/spec/thinking_sphinx/scopes_spec.rb +5 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
- data/spec/thinking_sphinx/search/query_spec.rb +10 -10
- data/spec/thinking_sphinx/search_spec.rb +28 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
- data/spec/thinking_sphinx_spec.rb +6 -6
- data/thinking-sphinx.gemspec +4 -4
- metadata +12 -9
|
@@ -25,7 +25,7 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
|
|
|
25
25
|
context[:results] << double('instance', :id => 24)
|
|
26
26
|
context[:results] << double('instance', :id => 42)
|
|
27
27
|
|
|
28
|
-
app.
|
|
28
|
+
expect(app).to receive(:call)
|
|
29
29
|
|
|
30
30
|
middleware.call [context]
|
|
31
31
|
end
|
|
@@ -37,11 +37,11 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
|
|
|
37
37
|
context[:results] << double('instance', :id => 24)
|
|
38
38
|
context[:results] << nil
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
expect {
|
|
41
41
|
middleware.call [context]
|
|
42
|
-
}.
|
|
43
|
-
err.ids.
|
|
44
|
-
err.context.
|
|
42
|
+
}.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
|
|
43
|
+
expect(err.ids).to eq([42])
|
|
44
|
+
expect(err.context).to eq(context)
|
|
45
45
|
}
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -15,12 +15,12 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
15
15
|
|
|
16
16
|
describe '#call' do
|
|
17
17
|
before :each do
|
|
18
|
-
context.
|
|
18
|
+
allow(context).to receive_messages :search => search
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
context 'one stale ids exception' do
|
|
22
22
|
before :each do
|
|
23
|
-
app.
|
|
23
|
+
allow(app).to receive(:call) do
|
|
24
24
|
@calls ||= 0
|
|
25
25
|
@calls += 1
|
|
26
26
|
raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
|
|
@@ -30,7 +30,7 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
30
30
|
it "appends the ids to the without_ids filter" do
|
|
31
31
|
middleware.call [context]
|
|
32
32
|
|
|
33
|
-
search.options[:without_ids].
|
|
33
|
+
expect(search.options[:without_ids]).to eq([12])
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "respects existing without_ids filters" do
|
|
@@ -38,13 +38,13 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
38
38
|
|
|
39
39
|
middleware.call [context]
|
|
40
40
|
|
|
41
|
-
search.options[:without_ids].
|
|
41
|
+
expect(search.options[:without_ids]).to eq([11, 12])
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context 'two stale ids exceptions' do
|
|
46
46
|
before :each do
|
|
47
|
-
app.
|
|
47
|
+
allow(app).to receive(:call) do
|
|
48
48
|
@calls ||= 0
|
|
49
49
|
@calls += 1
|
|
50
50
|
raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
|
|
@@ -55,7 +55,7 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
55
55
|
it "appends the ids to the without_ids filter" do
|
|
56
56
|
middleware.call [context]
|
|
57
57
|
|
|
58
|
-
search.options[:without_ids].
|
|
58
|
+
expect(search.options[:without_ids]).to eq([12, 13])
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "respects existing without_ids filters" do
|
|
@@ -63,13 +63,13 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
63
63
|
|
|
64
64
|
middleware.call [context]
|
|
65
65
|
|
|
66
|
-
search.options[:without_ids].
|
|
66
|
+
expect(search.options[:without_ids]).to eq([11, 12, 13])
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
context 'three stale ids exceptions' do
|
|
71
71
|
before :each do
|
|
72
|
-
app.
|
|
72
|
+
allow(app).to receive(:call) do
|
|
73
73
|
@calls ||= 0
|
|
74
74
|
@calls += 1
|
|
75
75
|
|
|
@@ -80,10 +80,10 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "raises the final stale ids exceptions" do
|
|
83
|
-
|
|
83
|
+
expect {
|
|
84
84
|
middleware.call [context]
|
|
85
|
-
}.
|
|
86
|
-
err.ids.
|
|
85
|
+
}.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
|
|
86
|
+
expect(err.ids).to eq([14])
|
|
87
87
|
}
|
|
88
88
|
end
|
|
89
89
|
end
|
|
@@ -92,8 +92,8 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
92
92
|
let(:context2) { {:raw => [], :results => []} }
|
|
93
93
|
let(:search2) { double('search2', :options => {}) }
|
|
94
94
|
before :each do
|
|
95
|
-
context2.
|
|
96
|
-
app.
|
|
95
|
+
allow(context2).to receive_messages :search => search2
|
|
96
|
+
allow(app).to receive(:call) do
|
|
97
97
|
@calls ||= 0
|
|
98
98
|
@calls += 1
|
|
99
99
|
raise ThinkingSphinx::Search::StaleIdsException.new([12], context2) if @calls == 1
|
|
@@ -102,8 +102,8 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
102
102
|
|
|
103
103
|
it "appends the ids to the without_ids filter in the correct context" do
|
|
104
104
|
middleware.call [context, context2]
|
|
105
|
-
search.options[:without_ids].
|
|
106
|
-
search2.options[:without_ids].
|
|
105
|
+
expect(search.options[:without_ids]).to eq(nil)
|
|
106
|
+
expect(search2.options[:without_ids]).to eq([12])
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
|
|
@@ -15,13 +15,13 @@ describe ThinkingSphinx::Panes::DistancePane do
|
|
|
15
15
|
it "returns the object's geodistance attribute by default" do
|
|
16
16
|
raw['geodist'] = 123.45
|
|
17
17
|
|
|
18
|
-
pane.distance.
|
|
18
|
+
expect(pane.distance).to eq(123.45)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "converts string geodistances to floats" do
|
|
22
22
|
raw['geodist'] = '123.450'
|
|
23
23
|
|
|
24
|
-
pane.distance.
|
|
24
|
+
expect(pane.distance).to eq(123.45)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -29,13 +29,13 @@ describe ThinkingSphinx::Panes::DistancePane do
|
|
|
29
29
|
it "returns the object's geodistance attribute by default" do
|
|
30
30
|
raw['geodist'] = 123.45
|
|
31
31
|
|
|
32
|
-
pane.geodist.
|
|
32
|
+
expect(pane.geodist).to eq(123.45)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "converts string geodistances to floats" do
|
|
36
36
|
raw['geodist'] = '123.450'
|
|
37
37
|
|
|
38
|
-
pane.geodist.
|
|
38
|
+
expect(pane.geodist).to eq(123.45)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
|
@@ -13,7 +13,7 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
|
|
|
13
13
|
let(:search) { double('search', :query => 'foo', :options => {}) }
|
|
14
14
|
|
|
15
15
|
before :each do
|
|
16
|
-
context.
|
|
16
|
+
allow(context).to receive_messages :search => search
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
describe '#excerpts' do
|
|
@@ -22,18 +22,18 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
|
|
|
22
22
|
|
|
23
23
|
before :each do
|
|
24
24
|
stub_const 'ThinkingSphinx::Excerpter', double(:new => excerpter)
|
|
25
|
-
ThinkingSphinx::Panes::ExcerptsPane::Excerpts.
|
|
25
|
+
allow(ThinkingSphinx::Panes::ExcerptsPane::Excerpts).to receive_messages :new => excerpts
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "returns an excerpt glazing" do
|
|
29
|
-
pane.excerpts.
|
|
29
|
+
expect(pane.excerpts).to eq(excerpts)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "creates an excerpter with the first index and the query and conditions values" do
|
|
33
33
|
context[:indices] = [double(:name => 'alpha'), double(:name => 'beta')]
|
|
34
34
|
context.search.options[:conditions] = {:baz => 'bar'}
|
|
35
35
|
|
|
36
|
-
ThinkingSphinx::Excerpter.
|
|
36
|
+
expect(ThinkingSphinx::Excerpter).to receive(:new).
|
|
37
37
|
with('alpha', 'foo bar', anything).and_return(excerpter)
|
|
38
38
|
|
|
39
39
|
pane.excerpts
|
|
@@ -42,7 +42,7 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
|
|
|
42
42
|
it "passes through excerpts options" do
|
|
43
43
|
search.options[:excerpts] = {:before_match => 'foo'}
|
|
44
44
|
|
|
45
|
-
ThinkingSphinx::Excerpter.
|
|
45
|
+
expect(ThinkingSphinx::Excerpter).to receive(:new).
|
|
46
46
|
with(anything, anything, :before_match => 'foo').and_return(excerpter)
|
|
47
47
|
|
|
48
48
|
pane.excerpts
|
|
@@ -5,31 +5,31 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
5
5
|
let(:interface) { ThinkingSphinx::RakeInterface.new }
|
|
6
6
|
|
|
7
7
|
before :each do
|
|
8
|
-
ThinkingSphinx::Configuration.
|
|
9
|
-
interface.
|
|
8
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => configuration
|
|
9
|
+
allow(interface).to receive_messages(:puts => nil)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
describe '#clear_all' do
|
|
13
13
|
let(:controller) { double 'controller' }
|
|
14
14
|
|
|
15
15
|
before :each do
|
|
16
|
-
configuration.
|
|
16
|
+
allow(configuration).to receive_messages(
|
|
17
17
|
:indices_location => '/path/to/indices',
|
|
18
18
|
:searchd => double(:binlog_path => '/path/to/binlog')
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
FileUtils.
|
|
22
|
-
File.
|
|
21
|
+
allow(FileUtils).to receive_messages :rm_r => true
|
|
22
|
+
allow(File).to receive_messages :exists? => true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "removes the directory for the index files" do
|
|
26
|
-
FileUtils.
|
|
26
|
+
expect(FileUtils).to receive(:rm_r).with('/path/to/indices')
|
|
27
27
|
|
|
28
28
|
interface.clear_all
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "removes the directory for the binlog files" do
|
|
32
|
-
FileUtils.
|
|
32
|
+
expect(FileUtils).to receive(:rm_r).with('/path/to/binlog')
|
|
33
33
|
|
|
34
34
|
interface.clear_all
|
|
35
35
|
end
|
|
@@ -42,31 +42,32 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
before :each do
|
|
45
|
-
configuration.
|
|
46
|
-
:indices
|
|
47
|
-
:searchd
|
|
45
|
+
allow(configuration).to receive_messages(
|
|
46
|
+
:indices => [double(:type => 'plain'), index],
|
|
47
|
+
:searchd => double(:binlog_path => '/path/to/binlog'),
|
|
48
|
+
:preload_indices => true
|
|
48
49
|
)
|
|
49
50
|
|
|
50
|
-
Dir.
|
|
51
|
-
FileUtils.
|
|
52
|
-
File.
|
|
51
|
+
allow(Dir).to receive_messages :[] => ['foo.a', 'foo.b']
|
|
52
|
+
allow(FileUtils).to receive_messages :rm_r => true, :rm => true
|
|
53
|
+
allow(File).to receive_messages :exists? => true
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
it 'finds each file for real-time indices' do
|
|
56
|
-
Dir.
|
|
57
|
+
expect(Dir).to receive(:[]).with('/path/to/my/index.*').and_return([])
|
|
57
58
|
|
|
58
59
|
interface.clear_real_time
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
it "removes each file for real-time indices" do
|
|
62
|
-
FileUtils.
|
|
63
|
-
FileUtils.
|
|
63
|
+
expect(FileUtils).to receive(:rm).with('foo.a')
|
|
64
|
+
expect(FileUtils).to receive(:rm).with('foo.b')
|
|
64
65
|
|
|
65
66
|
interface.clear_real_time
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
it "removes the directory for the binlog files" do
|
|
69
|
-
FileUtils.
|
|
70
|
+
expect(FileUtils).to receive(:rm_r).with('/path/to/binlog')
|
|
70
71
|
|
|
71
72
|
interface.clear_real_time
|
|
72
73
|
end
|
|
@@ -76,20 +77,20 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
76
77
|
let(:controller) { double('controller') }
|
|
77
78
|
|
|
78
79
|
before :each do
|
|
79
|
-
configuration.
|
|
80
|
+
allow(configuration).to receive_messages(
|
|
80
81
|
:configuration_file => '/path/to/foo.conf',
|
|
81
82
|
:render_to_file => true
|
|
82
83
|
)
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
it "renders the configuration to a file" do
|
|
86
|
-
configuration.
|
|
87
|
+
expect(configuration).to receive(:render_to_file)
|
|
87
88
|
|
|
88
89
|
interface.configure
|
|
89
90
|
end
|
|
90
91
|
|
|
91
92
|
it "prints a message stating the file is being generated" do
|
|
92
|
-
interface.
|
|
93
|
+
expect(interface).to receive(:puts).
|
|
93
94
|
with('Generating configuration to /path/to/foo.conf')
|
|
94
95
|
|
|
95
96
|
interface.configure
|
|
@@ -100,30 +101,30 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
100
101
|
let(:controller) { double('controller', :index => true) }
|
|
101
102
|
|
|
102
103
|
before :each do
|
|
103
|
-
ThinkingSphinx.
|
|
104
|
-
configuration.
|
|
104
|
+
allow(ThinkingSphinx).to receive_messages :before_index_hooks => []
|
|
105
|
+
allow(configuration).to receive_messages(
|
|
105
106
|
:configuration_file => '/path/to/foo.conf',
|
|
106
107
|
:render_to_file => true,
|
|
107
108
|
:indices_location => '/path/to/indices'
|
|
108
109
|
)
|
|
109
110
|
|
|
110
|
-
FileUtils.
|
|
111
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
it "renders the configuration to a file by default" do
|
|
114
|
-
configuration.
|
|
115
|
+
expect(configuration).to receive(:render_to_file)
|
|
115
116
|
|
|
116
117
|
interface.index
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
it "does not render the configuration if requested" do
|
|
120
|
-
configuration.
|
|
121
|
+
expect(configuration).not_to receive(:render_to_file)
|
|
121
122
|
|
|
122
123
|
interface.index false
|
|
123
124
|
end
|
|
124
125
|
|
|
125
126
|
it "creates the directory for the index files" do
|
|
126
|
-
FileUtils.
|
|
127
|
+
expect(FileUtils).to receive(:mkdir_p).with('/path/to/indices')
|
|
127
128
|
|
|
128
129
|
interface.index
|
|
129
130
|
end
|
|
@@ -134,66 +135,73 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
134
135
|
|
|
135
136
|
interface.index
|
|
136
137
|
|
|
137
|
-
called.
|
|
138
|
+
expect(called).to be_truthy
|
|
138
139
|
end
|
|
139
140
|
|
|
140
141
|
it "indexes all indices verbosely" do
|
|
141
|
-
controller.
|
|
142
|
+
expect(controller).to receive(:index).with(:verbose => true)
|
|
142
143
|
|
|
143
144
|
interface.index
|
|
144
145
|
end
|
|
145
146
|
|
|
146
147
|
it "does not index verbosely if requested" do
|
|
147
|
-
controller.
|
|
148
|
+
expect(controller).to receive(:index).with(:verbose => false)
|
|
148
149
|
|
|
149
150
|
interface.index true, false
|
|
150
151
|
end
|
|
151
152
|
end
|
|
152
153
|
|
|
153
154
|
describe '#start' do
|
|
154
|
-
let(:controller) { double('controller', :start =>
|
|
155
|
+
let(:controller) { double('controller', :start => result, :pid => 101) }
|
|
156
|
+
let(:result) { double 'result', :command => 'start', :status => 1,
|
|
157
|
+
:output => '' }
|
|
155
158
|
|
|
156
159
|
before :each do
|
|
157
|
-
controller.
|
|
158
|
-
configuration.
|
|
160
|
+
allow(controller).to receive(:running?).and_return(false, true)
|
|
161
|
+
allow(configuration).to receive_messages(
|
|
162
|
+
:indices_location => 'my/index/files',
|
|
163
|
+
:searchd => double(:log => '/path/to/log')
|
|
164
|
+
)
|
|
159
165
|
|
|
160
|
-
FileUtils.
|
|
166
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
161
167
|
end
|
|
162
168
|
|
|
163
169
|
it "creates the index files directory" do
|
|
164
|
-
FileUtils.
|
|
170
|
+
expect(FileUtils).to receive(:mkdir_p).with('my/index/files')
|
|
165
171
|
|
|
166
172
|
interface.start
|
|
167
173
|
end
|
|
168
174
|
|
|
169
175
|
it "starts the daemon" do
|
|
170
|
-
controller.
|
|
176
|
+
expect(controller).to receive(:start)
|
|
171
177
|
|
|
172
178
|
interface.start
|
|
173
179
|
end
|
|
174
180
|
|
|
175
181
|
it "raises an error if the daemon is already running" do
|
|
176
|
-
controller.
|
|
182
|
+
allow(controller).to receive_messages :running? => true
|
|
177
183
|
|
|
178
|
-
|
|
184
|
+
expect {
|
|
179
185
|
interface.start
|
|
180
|
-
}.
|
|
186
|
+
}.to raise_error(ThinkingSphinx::SphinxAlreadyRunning)
|
|
181
187
|
end
|
|
182
188
|
|
|
183
189
|
it "prints a success message if the daemon has started" do
|
|
184
|
-
controller.
|
|
190
|
+
allow(controller).to receive(:running?).and_return(false, true)
|
|
185
191
|
|
|
186
|
-
interface.
|
|
192
|
+
expect(interface).to receive(:puts).
|
|
187
193
|
with('Started searchd successfully (pid: 101).')
|
|
188
194
|
|
|
189
195
|
interface.start
|
|
190
196
|
end
|
|
191
197
|
|
|
192
198
|
it "prints a failure message if the daemon does not start" do
|
|
193
|
-
controller.
|
|
199
|
+
allow(controller).to receive(:running?).and_return(false, false)
|
|
200
|
+
allow(interface).to receive(:exit)
|
|
194
201
|
|
|
195
|
-
interface.
|
|
196
|
-
|
|
202
|
+
expect(interface).to receive(:puts) do |string|
|
|
203
|
+
expect(string).to match('The Sphinx start command failed')
|
|
204
|
+
end
|
|
197
205
|
|
|
198
206
|
interface.start
|
|
199
207
|
end
|
|
@@ -201,33 +209,38 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
201
209
|
|
|
202
210
|
describe '#stop' do
|
|
203
211
|
let(:controller) { double('controller', :stop => true, :pid => 101) }
|
|
212
|
+
let(:result) { double 'result', :command => 'start', :status => 1,
|
|
213
|
+
:output => '' }
|
|
204
214
|
|
|
205
215
|
before :each do
|
|
206
|
-
controller.
|
|
216
|
+
allow(controller).to receive(:running?).and_return(true, true, false)
|
|
207
217
|
end
|
|
208
218
|
|
|
209
219
|
it "prints a message if the daemon is not already running" do
|
|
210
|
-
controller.
|
|
220
|
+
allow(controller).to receive_messages :running? => false
|
|
211
221
|
|
|
212
|
-
interface.
|
|
222
|
+
expect(interface).to receive(:puts).with('searchd is not currently running.')
|
|
213
223
|
|
|
214
224
|
interface.stop
|
|
215
225
|
end
|
|
216
226
|
|
|
217
227
|
it "stops the daemon" do
|
|
218
|
-
controller.
|
|
228
|
+
expect(controller).to receive(:stop)
|
|
219
229
|
|
|
220
230
|
interface.stop
|
|
221
231
|
end
|
|
222
232
|
|
|
223
233
|
it "prints a message informing the daemon has stopped" do
|
|
224
|
-
interface.
|
|
234
|
+
expect(interface).to receive(:puts).with('Stopped searchd daemon (pid: 101).')
|
|
225
235
|
|
|
226
236
|
interface.stop
|
|
227
237
|
end
|
|
228
238
|
|
|
229
239
|
it "should retry stopping the daemon until it stops" do
|
|
230
|
-
controller.
|
|
240
|
+
allow(controller).to receive(:running?).
|
|
241
|
+
and_return(true, true, true, false)
|
|
242
|
+
|
|
243
|
+
expect(controller).to receive(:stop).twice
|
|
231
244
|
|
|
232
245
|
interface.stop
|
|
233
246
|
end
|
|
@@ -237,18 +250,18 @@ describe ThinkingSphinx::RakeInterface do
|
|
|
237
250
|
let(:controller) { double('controller') }
|
|
238
251
|
|
|
239
252
|
it "reports when the daemon is running" do
|
|
240
|
-
controller.
|
|
253
|
+
allow(controller).to receive_messages :running? => true
|
|
241
254
|
|
|
242
|
-
interface.
|
|
255
|
+
expect(interface).to receive(:puts).
|
|
243
256
|
with('The Sphinx daemon searchd is currently running.')
|
|
244
257
|
|
|
245
258
|
interface.status
|
|
246
259
|
end
|
|
247
260
|
|
|
248
261
|
it "reports when the daemon is not running" do
|
|
249
|
-
controller.
|
|
262
|
+
allow(controller).to receive_messages :running? => false
|
|
250
263
|
|
|
251
|
-
interface.
|
|
264
|
+
expect(interface).to receive(:puts).
|
|
252
265
|
with('The Sphinx daemon searchd is not currently running.')
|
|
253
266
|
|
|
254
267
|
interface.status
|