thinking-sphinx 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -37,7 +37,7 @@ describe ThinkingSphinx::FacetSearch do
|
|
37
37
|
|
38
38
|
describe '#[]' do
|
39
39
|
it "populates facet results" do
|
40
|
-
facet_search[:price_bracket].
|
40
|
+
expect(facet_search[:price_bracket]).to eq({3 => 5})
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -45,17 +45,17 @@ describe ThinkingSphinx::FacetSearch do
|
|
45
45
|
it "queries on each facet with a grouped search in a batch" do
|
46
46
|
facet_search.populate
|
47
47
|
|
48
|
-
batch.searches.detect { |search|
|
48
|
+
expect(batch.searches.detect { |search|
|
49
49
|
search.options[:group_by] == 'price_bracket'
|
50
|
-
}.
|
50
|
+
}).not_to be_nil
|
51
51
|
end
|
52
52
|
|
53
53
|
it "limits query for a facet to just indices that have that facet" do
|
54
54
|
facet_search.populate
|
55
55
|
|
56
|
-
batch.searches.detect { |search|
|
56
|
+
expect(batch.searches.detect { |search|
|
57
57
|
search.options[:indices] == ['foo_core']
|
58
|
-
}.
|
58
|
+
}).not_to be_nil
|
59
59
|
end
|
60
60
|
|
61
61
|
it "limits facets to the specified set" do
|
@@ -63,25 +63,25 @@ describe ThinkingSphinx::FacetSearch do
|
|
63
63
|
|
64
64
|
facet_search.populate
|
65
65
|
|
66
|
-
batch.searches.collect { |search|
|
66
|
+
expect(batch.searches.collect { |search|
|
67
67
|
search.options[:group_by]
|
68
|
-
}.
|
68
|
+
}).to eq(['category_id'])
|
69
69
|
end
|
70
70
|
|
71
71
|
it "aliases the class facet from sphinx_internal_class" do
|
72
|
-
property_a.
|
72
|
+
allow(property_a).to receive_messages :name => 'sphinx_internal_class'
|
73
73
|
|
74
74
|
facet_search.populate
|
75
75
|
|
76
|
-
facet_search[:class].
|
76
|
+
expect(facet_search[:class]).to eq({'Foo' => 5})
|
77
77
|
end
|
78
78
|
|
79
79
|
it "uses the @groupby value for MVAs" do
|
80
|
-
property_a.
|
80
|
+
allow(property_a).to receive_messages :name => 'tag_ids', :multi? => true
|
81
81
|
|
82
82
|
facet_search.populate
|
83
83
|
|
84
|
-
facet_search[:tag_ids].
|
84
|
+
expect(facet_search[:tag_ids]).to eq({2 => 5})
|
85
85
|
end
|
86
86
|
|
87
87
|
[:max_matches, :limit].each do |setting|
|
@@ -89,7 +89,7 @@ describe ThinkingSphinx::FacetSearch do
|
|
89
89
|
facet_search.populate
|
90
90
|
|
91
91
|
batch.searches.each { |search|
|
92
|
-
search.options[setting].
|
92
|
+
expect(search.options[setting]).to eq(1000)
|
93
93
|
}
|
94
94
|
end
|
95
95
|
|
@@ -99,7 +99,7 @@ describe ThinkingSphinx::FacetSearch do
|
|
99
99
|
facet_search.populate
|
100
100
|
|
101
101
|
batch.searches.each { |search|
|
102
|
-
search.options[setting].
|
102
|
+
expect(search.options[setting]).to eq(1234)
|
103
103
|
}
|
104
104
|
end
|
105
105
|
end
|
@@ -111,7 +111,7 @@ describe ThinkingSphinx::FacetSearch do
|
|
111
111
|
facet_search.populate
|
112
112
|
|
113
113
|
batch.searches.each { |search|
|
114
|
-
search.options[setting].
|
114
|
+
expect(search.options[setting]).to eq(42)
|
115
115
|
}
|
116
116
|
end
|
117
117
|
|
@@ -122,8 +122,8 @@ describe ThinkingSphinx::FacetSearch do
|
|
122
122
|
facet_search.populate
|
123
123
|
|
124
124
|
batch.searches.each do |search|
|
125
|
-
search.options[setting].
|
126
|
-
search.options[:max_matches].
|
125
|
+
expect(search.options[setting]).to eq(10)
|
126
|
+
expect(search.options[:max_matches]).to eq(500)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -17,13 +17,13 @@ describe ThinkingSphinx::IndexSet do
|
|
17
17
|
|
18
18
|
def class_double(name, *superclasses)
|
19
19
|
klass = double 'class', :name => name, :class => Class
|
20
|
-
klass.
|
20
|
+
allow(klass).to receive_messages :ancestors => ([klass] + superclasses + [ar_base])
|
21
21
|
klass
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#to_a' do
|
25
25
|
it "ensures the indices are loaded" do
|
26
|
-
configuration.
|
26
|
+
expect(configuration).to receive(:preload_indices)
|
27
27
|
|
28
28
|
set.to_a
|
29
29
|
end
|
@@ -37,7 +37,7 @@ describe ThinkingSphinx::IndexSet do
|
|
37
37
|
|
38
38
|
configuration.indices.replace [article_core, user_core, distributed]
|
39
39
|
|
40
|
-
set.to_a.
|
40
|
+
expect(set.to_a).to eq([article_core, user_core])
|
41
41
|
end
|
42
42
|
|
43
43
|
it "uses indices for the given classes" do
|
@@ -49,7 +49,7 @@ describe ThinkingSphinx::IndexSet do
|
|
49
49
|
|
50
50
|
options[:classes] = [class_double('Article')]
|
51
51
|
|
52
|
-
set.to_a.length.
|
52
|
+
expect(set.to_a.length).to eq(1)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "requests indices for any superclasses" do
|
@@ -63,7 +63,7 @@ describe ThinkingSphinx::IndexSet do
|
|
63
63
|
class_double('OpinionArticle', class_double('Article'))
|
64
64
|
]
|
65
65
|
|
66
|
-
set.to_a.length.
|
66
|
+
expect(set.to_a.length).to eq(2)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "uses named indices if names are provided" do
|
@@ -73,7 +73,7 @@ describe ThinkingSphinx::IndexSet do
|
|
73
73
|
|
74
74
|
options[:indices] = ['article_core']
|
75
75
|
|
76
|
-
set.to_a.
|
76
|
+
expect(set.to_a).to eq([article_core])
|
77
77
|
end
|
78
78
|
|
79
79
|
it "selects from the full index set those with matching references" do
|
@@ -85,7 +85,7 @@ describe ThinkingSphinx::IndexSet do
|
|
85
85
|
|
86
86
|
options[:references] = [:book, :article]
|
87
87
|
|
88
|
-
set.to_a.length.
|
88
|
+
expect(set.to_a.length).to eq(2)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -4,7 +4,7 @@ describe ThinkingSphinx::Index do
|
|
4
4
|
let(:configuration) { Struct.new(:indices, :settings).new([], {}) }
|
5
5
|
|
6
6
|
before :each do
|
7
|
-
ThinkingSphinx::Configuration.
|
7
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => configuration
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.define' do
|
@@ -12,29 +12,29 @@ describe ThinkingSphinx::Index do
|
|
12
12
|
|
13
13
|
context 'with ActiveRecord' do
|
14
14
|
before :each do
|
15
|
-
ThinkingSphinx::ActiveRecord::Index.
|
15
|
+
allow(ThinkingSphinx::ActiveRecord::Index).to receive_messages :new => index
|
16
16
|
end
|
17
17
|
|
18
18
|
it "creates an ActiveRecord index" do
|
19
|
-
ThinkingSphinx::ActiveRecord::Index.
|
19
|
+
expect(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
|
20
20
|
with(:user, :with => :active_record).and_return index
|
21
21
|
|
22
22
|
ThinkingSphinx::Index.define(:user, :with => :active_record)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns the ActiveRecord index" do
|
26
|
-
ThinkingSphinx::Index.define(:user, :with => :active_record).
|
27
|
-
|
26
|
+
expect(ThinkingSphinx::Index.define(:user, :with => :active_record)).
|
27
|
+
to eq([index])
|
28
28
|
end
|
29
29
|
|
30
30
|
it "adds the index to the collection of indices" do
|
31
31
|
ThinkingSphinx::Index.define(:user, :with => :active_record)
|
32
32
|
|
33
|
-
configuration.indices.
|
33
|
+
expect(configuration.indices).to include(index)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "sets the block in the index" do
|
37
|
-
index.
|
37
|
+
expect(index).to receive(:definition_block=).with instance_of(Proc)
|
38
38
|
|
39
39
|
ThinkingSphinx::Index.define(:user, :with => :active_record) do
|
40
40
|
indexes name
|
@@ -46,19 +46,19 @@ describe ThinkingSphinx::Index do
|
|
46
46
|
let(:processor) { double('delta processor') }
|
47
47
|
|
48
48
|
before :each do
|
49
|
-
ThinkingSphinx::Deltas.
|
50
|
-
ThinkingSphinx::ActiveRecord::Index.
|
49
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :processor_for => processor
|
50
|
+
allow(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
|
51
51
|
and_return(index, delta_index)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "creates two indices with delta settings" do
|
55
|
-
ThinkingSphinx::ActiveRecord::Index.
|
56
|
-
ThinkingSphinx::ActiveRecord::Index.
|
55
|
+
allow(ThinkingSphinx::ActiveRecord::Index).to receive(:new).and_call_original
|
56
|
+
expect(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
|
57
57
|
with(:user,
|
58
58
|
hash_including(:delta? => false, :delta_processor => processor)
|
59
59
|
).once.
|
60
60
|
and_return index
|
61
|
-
ThinkingSphinx::ActiveRecord::Index.
|
61
|
+
expect(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
|
62
62
|
with(:user,
|
63
63
|
hash_including(:delta? => true, :delta_processor => processor)
|
64
64
|
).once.
|
@@ -74,13 +74,13 @@ describe ThinkingSphinx::Index do
|
|
74
74
|
:with => :active_record,
|
75
75
|
:delta => true
|
76
76
|
|
77
|
-
configuration.indices.
|
78
|
-
configuration.indices.
|
77
|
+
expect(configuration.indices).to include(index)
|
78
|
+
expect(configuration.indices).to include(delta_index)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "sets the block in the index" do
|
82
|
-
index.
|
83
|
-
delta_index.
|
82
|
+
expect(index).to receive(:definition_block=).with instance_of(Proc)
|
83
|
+
expect(delta_index).to receive(:definition_block=).with instance_of(Proc)
|
84
84
|
|
85
85
|
ThinkingSphinx::Index.define(:user,
|
86
86
|
:with => :active_record,
|
@@ -93,29 +93,29 @@ describe ThinkingSphinx::Index do
|
|
93
93
|
|
94
94
|
context 'with Real-Time' do
|
95
95
|
before :each do
|
96
|
-
ThinkingSphinx::RealTime::Index.
|
96
|
+
allow(ThinkingSphinx::RealTime::Index).to receive_messages :new => index
|
97
97
|
end
|
98
98
|
|
99
99
|
it "creates a real-time index" do
|
100
|
-
ThinkingSphinx::RealTime::Index.
|
100
|
+
expect(ThinkingSphinx::RealTime::Index).to receive(:new).
|
101
101
|
with(:user, :with => :real_time).and_return index
|
102
102
|
|
103
103
|
ThinkingSphinx::Index.define(:user, :with => :real_time)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "returns the ActiveRecord index" do
|
107
|
-
ThinkingSphinx::Index.define(:user, :with => :real_time).
|
108
|
-
|
107
|
+
expect(ThinkingSphinx::Index.define(:user, :with => :real_time)).
|
108
|
+
to eq([index])
|
109
109
|
end
|
110
110
|
|
111
111
|
it "adds the index to the collection of indices" do
|
112
112
|
ThinkingSphinx::Index.define(:user, :with => :real_time)
|
113
113
|
|
114
|
-
configuration.indices.
|
114
|
+
expect(configuration.indices).to include(index)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "sets the block in the index" do
|
118
|
-
index.
|
118
|
+
expect(index).to receive(:definition_block=).with instance_of(Proc)
|
119
119
|
|
120
120
|
ThinkingSphinx::Index.define(:user, :with => :real_time) do
|
121
121
|
indexes name
|
@@ -126,13 +126,13 @@ describe ThinkingSphinx::Index do
|
|
126
126
|
|
127
127
|
describe '#initialize' do
|
128
128
|
it "is fine with no defaults from settings" do
|
129
|
-
ThinkingSphinx::Index.new(:user, {}).options.
|
129
|
+
expect(ThinkingSphinx::Index.new(:user, {}).options).to eq({})
|
130
130
|
end
|
131
131
|
|
132
132
|
it "respects defaults from settings" do
|
133
133
|
configuration.settings['index_options'] = {'delta' => true}
|
134
134
|
|
135
|
-
ThinkingSphinx::Index.new(:user, {}).options.
|
135
|
+
expect(ThinkingSphinx::Index.new(:user, {}).options).to eq({:delta => true})
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -12,13 +12,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
12
12
|
|
13
13
|
describe '#first_page?' do
|
14
14
|
it "returns true when on the first page" do
|
15
|
-
mask.
|
15
|
+
expect(mask).to be_first_page
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns false on other pages" do
|
19
|
-
search.
|
19
|
+
allow(search).to receive_messages :current_page => 2
|
20
20
|
|
21
|
-
mask.
|
21
|
+
expect(mask).not_to be_first_page
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -28,13 +28,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "is true when there's no more pages" do
|
31
|
-
search.
|
31
|
+
allow(search).to receive_messages :current_page => 3
|
32
32
|
|
33
|
-
mask.
|
33
|
+
expect(mask).to be_last_page
|
34
34
|
end
|
35
35
|
|
36
36
|
it "is false when there's still more pages" do
|
37
|
-
mask.
|
37
|
+
expect(mask).not_to be_last_page
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -44,13 +44,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return one more than the current page" do
|
47
|
-
mask.next_page.
|
47
|
+
expect(mask.next_page).to eq(2)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return nil if on the last page" do
|
51
|
-
search.
|
51
|
+
allow(search).to receive_messages :current_page => 3
|
52
52
|
|
53
|
-
mask.next_page.
|
53
|
+
expect(mask.next_page).to be_nil
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -60,13 +60,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "is true when there is a second page" do
|
63
|
-
mask.next_page
|
63
|
+
expect(mask.next_page?).to be_truthy
|
64
64
|
end
|
65
65
|
|
66
66
|
it "is false when there's no more pages" do
|
67
|
-
search.
|
67
|
+
allow(search).to receive_messages :current_page => 3
|
68
68
|
|
69
|
-
mask.next_page
|
69
|
+
expect(mask.next_page?).to be_falsey
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -76,13 +76,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should return one less than the current page" do
|
79
|
-
search.
|
79
|
+
allow(search).to receive_messages :current_page => 2
|
80
80
|
|
81
|
-
mask.previous_page.
|
81
|
+
expect(mask.previous_page).to eq(1)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should return nil if on the first page" do
|
85
|
-
mask.previous_page.
|
85
|
+
expect(mask.previous_page).to be_nil
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -92,7 +92,7 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "returns the total found from the search request metadata" do
|
95
|
-
mask.total_entries.
|
95
|
+
expect(mask.total_entries).to eq(12)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -103,19 +103,19 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it "uses the total available from the search request metadata" do
|
106
|
-
mask.total_pages.
|
106
|
+
expect(mask.total_pages).to eq(2)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should allow for custom per_page values" do
|
110
|
-
search.
|
110
|
+
allow(search).to receive_messages :per_page => 40
|
111
111
|
|
112
|
-
mask.total_pages.
|
112
|
+
expect(mask.total_pages).to eq(1)
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should return 0 if there is no index and therefore no results" do
|
116
116
|
search.meta.clear
|
117
117
|
|
118
|
-
mask.total_pages.
|
118
|
+
expect(mask.total_pages).to eq(0)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -10,18 +10,18 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
10
10
|
let(:mask) { ThinkingSphinx::Masks::ScopesMask.new search }
|
11
11
|
|
12
12
|
before :each do
|
13
|
-
FileUtils.
|
13
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#search' do
|
17
17
|
it "replaces the query if one is supplied" do
|
18
|
-
search.
|
18
|
+
expect(search).to receive(:query=).with('bar')
|
19
19
|
|
20
20
|
mask.search('bar')
|
21
21
|
end
|
22
22
|
|
23
23
|
it "keeps the existing query when only options are offered" do
|
24
|
-
search.
|
24
|
+
expect(search).not_to receive(:query=)
|
25
25
|
|
26
26
|
mask.search :with => {:foo => :bar}
|
27
27
|
end
|
@@ -31,7 +31,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
31
31
|
|
32
32
|
mask.search :conditions => {:baz => 'qux'}
|
33
33
|
|
34
|
-
search.options[:conditions].
|
34
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
35
35
|
end
|
36
36
|
|
37
37
|
it "merges filters" do
|
@@ -39,7 +39,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
39
39
|
|
40
40
|
mask.search :with => {:baz => :qux}
|
41
41
|
|
42
|
-
search.options[:with].
|
42
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
43
43
|
end
|
44
44
|
|
45
45
|
it "merges exclusive filters" do
|
@@ -47,7 +47,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
47
47
|
|
48
48
|
mask.search :without => {:baz => :qux}
|
49
49
|
|
50
|
-
search.options[:without].
|
50
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
51
51
|
end
|
52
52
|
|
53
53
|
it "appends excluded ids" do
|
@@ -55,7 +55,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
55
55
|
|
56
56
|
mask.search :without_ids => [5, 7]
|
57
57
|
|
58
|
-
search.options[:without_ids].
|
58
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
59
59
|
end
|
60
60
|
|
61
61
|
it "replaces the retry_stale option" do
|
@@ -63,23 +63,23 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
63
63
|
|
64
64
|
mask.search :retry_stale => 6
|
65
65
|
|
66
|
-
search.options[:retry_stale].
|
66
|
+
expect(search.options[:retry_stale]).to eq(6)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "returns the original search object" do
|
70
|
-
mask.search.object_id.
|
70
|
+
expect(mask.search.object_id).to eq(search.object_id)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
describe '#search_for_ids' do
|
75
75
|
it "replaces the query if one is supplied" do
|
76
|
-
search.
|
76
|
+
expect(search).to receive(:query=).with('bar')
|
77
77
|
|
78
78
|
mask.search_for_ids('bar')
|
79
79
|
end
|
80
80
|
|
81
81
|
it "keeps the existing query when only options are offered" do
|
82
|
-
search.
|
82
|
+
expect(search).not_to receive(:query=)
|
83
83
|
|
84
84
|
mask.search_for_ids :with => {:foo => :bar}
|
85
85
|
end
|
@@ -89,7 +89,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
89
89
|
|
90
90
|
mask.search_for_ids :conditions => {:baz => 'qux'}
|
91
91
|
|
92
|
-
search.options[:conditions].
|
92
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
93
93
|
end
|
94
94
|
|
95
95
|
it "merges filters" do
|
@@ -97,7 +97,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
97
97
|
|
98
98
|
mask.search_for_ids :with => {:baz => :qux}
|
99
99
|
|
100
|
-
search.options[:with].
|
100
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
101
101
|
end
|
102
102
|
|
103
103
|
it "merges exclusive filters" do
|
@@ -105,7 +105,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
105
105
|
|
106
106
|
mask.search_for_ids :without => {:baz => :qux}
|
107
107
|
|
108
|
-
search.options[:without].
|
108
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
109
109
|
end
|
110
110
|
|
111
111
|
it "appends excluded ids" do
|
@@ -113,7 +113,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
113
113
|
|
114
114
|
mask.search_for_ids :without_ids => [5, 7]
|
115
115
|
|
116
|
-
search.options[:without_ids].
|
116
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
117
117
|
end
|
118
118
|
|
119
119
|
it "replaces the retry_stale option" do
|
@@ -121,17 +121,17 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
121
121
|
|
122
122
|
mask.search_for_ids :retry_stale => 6
|
123
123
|
|
124
|
-
search.options[:retry_stale].
|
124
|
+
expect(search.options[:retry_stale]).to eq(6)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "adds the ids_only option" do
|
128
128
|
mask.search_for_ids
|
129
129
|
|
130
|
-
search.options[:ids_only].
|
130
|
+
expect(search.options[:ids_only]).to be_truthy
|
131
131
|
end
|
132
132
|
|
133
133
|
it "returns the original search object" do
|
134
|
-
mask.search_for_ids.object_id.
|
134
|
+
expect(mask.search_for_ids.object_id).to eq(search.object_id)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|