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
|
@@ -12,15 +12,15 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
12
12
|
let(:instance) { double('interpreter', :translate! => true) }
|
|
13
13
|
|
|
14
14
|
it "creates a new interpreter instance with the given block and index" do
|
|
15
|
-
ThinkingSphinx::RealTime::Interpreter.
|
|
15
|
+
expect(ThinkingSphinx::RealTime::Interpreter).to receive(:new).
|
|
16
16
|
with(index, block).and_return(instance)
|
|
17
17
|
|
|
18
18
|
ThinkingSphinx::RealTime::Interpreter.translate! index, block
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "calls translate! on the instance" do
|
|
22
|
-
ThinkingSphinx::RealTime::Interpreter.
|
|
23
|
-
instance.
|
|
22
|
+
allow(ThinkingSphinx::RealTime::Interpreter).to receive_messages(:new => instance)
|
|
23
|
+
expect(instance).to receive(:translate!)
|
|
24
24
|
|
|
25
25
|
ThinkingSphinx::RealTime::Interpreter.translate! index, block
|
|
26
26
|
end
|
|
@@ -31,18 +31,18 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
31
31
|
let(:attribute) { double('attribute') }
|
|
32
32
|
|
|
33
33
|
before :each do
|
|
34
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
34
|
+
allow(ThinkingSphinx::RealTime::Attribute).to receive_messages :new => attribute
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "creates a new attribute with the provided column" do
|
|
38
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
38
|
+
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
|
|
39
39
|
with(column, {}).and_return(attribute)
|
|
40
40
|
|
|
41
41
|
instance.has column
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "passes through options to the attribute" do
|
|
45
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
45
|
+
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
|
|
46
46
|
with(column, :as => :other_name).and_return(attribute)
|
|
47
47
|
|
|
48
48
|
instance.has column, :as => :other_name
|
|
@@ -51,15 +51,15 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
51
51
|
it "adds an attribute to the index" do
|
|
52
52
|
instance.has column
|
|
53
53
|
|
|
54
|
-
index.attributes.
|
|
54
|
+
expect(index.attributes).to include(attribute)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "adds multiple attributes when passed multiple columns" do
|
|
58
58
|
instance.has column, column
|
|
59
59
|
|
|
60
|
-
index.attributes.select { |saved_attribute|
|
|
60
|
+
expect(index.attributes.select { |saved_attribute|
|
|
61
61
|
saved_attribute == attribute
|
|
62
|
-
}.length.
|
|
62
|
+
}.length).to eq(2)
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -68,18 +68,18 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
68
68
|
let(:field) { double('field') }
|
|
69
69
|
|
|
70
70
|
before :each do
|
|
71
|
-
ThinkingSphinx::RealTime::Field.
|
|
71
|
+
allow(ThinkingSphinx::RealTime::Field).to receive_messages :new => field
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "creates a new field with the provided column" do
|
|
75
|
-
ThinkingSphinx::RealTime::Field.
|
|
75
|
+
expect(ThinkingSphinx::RealTime::Field).to receive(:new).
|
|
76
76
|
with(column, {}).and_return(field)
|
|
77
77
|
|
|
78
78
|
instance.indexes column
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "passes through options to the field" do
|
|
82
|
-
ThinkingSphinx::RealTime::Field.
|
|
82
|
+
expect(ThinkingSphinx::RealTime::Field).to receive(:new).
|
|
83
83
|
with(column, :as => :other_name).and_return(field)
|
|
84
84
|
|
|
85
85
|
instance.indexes column, :as => :other_name
|
|
@@ -88,28 +88,28 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
88
88
|
it "adds a field to the index" do
|
|
89
89
|
instance.indexes column
|
|
90
90
|
|
|
91
|
-
index.fields.
|
|
91
|
+
expect(index.fields).to include(field)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "adds multiple fields when passed multiple columns" do
|
|
95
95
|
instance.indexes column, column
|
|
96
96
|
|
|
97
|
-
index.fields.select { |saved_field|
|
|
97
|
+
expect(index.fields.select { |saved_field|
|
|
98
98
|
saved_field == field
|
|
99
|
-
}.length.
|
|
99
|
+
}.length).to eq(2)
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
context 'sortable' do
|
|
103
103
|
let(:attribute) { double('attribute') }
|
|
104
104
|
|
|
105
105
|
before :each do
|
|
106
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
106
|
+
allow(ThinkingSphinx::RealTime::Attribute).to receive_messages :new => attribute
|
|
107
107
|
|
|
108
|
-
column.
|
|
108
|
+
allow(column).to receive_messages :__name => :col
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "adds the _sort suffix to the field's name" do
|
|
112
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
112
|
+
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
|
|
113
113
|
with(column, :as => :col_sort, :type => :string).
|
|
114
114
|
and_return(attribute)
|
|
115
115
|
|
|
@@ -117,7 +117,7 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
it "respects given aliases" do
|
|
120
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
120
|
+
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
|
|
121
121
|
with(column, :as => :other_sort, :type => :string).
|
|
122
122
|
and_return(attribute)
|
|
123
123
|
|
|
@@ -125,7 +125,7 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
it "respects symbols instead of columns" do
|
|
128
|
-
ThinkingSphinx::RealTime::Attribute.
|
|
128
|
+
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
|
|
129
129
|
with(:title, :as => :title_sort, :type => :string).
|
|
130
130
|
and_return(attribute)
|
|
131
131
|
|
|
@@ -135,7 +135,7 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
135
135
|
it "adds an attribute to the index" do
|
|
136
136
|
instance.indexes column, :sortable => true
|
|
137
137
|
|
|
138
|
-
index.attributes.
|
|
138
|
+
expect(index.attributes).to include(attribute)
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
141
|
end
|
|
@@ -144,15 +144,15 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
144
144
|
let(:column) { double('column') }
|
|
145
145
|
|
|
146
146
|
before :each do
|
|
147
|
-
ThinkingSphinx::ActiveRecord::Column.
|
|
147
|
+
allow(ThinkingSphinx::ActiveRecord::Column).to receive_messages(:new => column)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "returns a new column for the given method" do
|
|
151
|
-
instance.id.
|
|
151
|
+
expect(instance.id).to eq(column)
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "should initialise the column with the method name and arguments" do
|
|
155
|
-
ThinkingSphinx::ActiveRecord::Column.
|
|
155
|
+
expect(ThinkingSphinx::ActiveRecord::Column).to receive(:new).
|
|
156
156
|
with(:users, :posts, :subject).and_return(column)
|
|
157
157
|
|
|
158
158
|
instance.users(:posts, :subject)
|
|
@@ -161,7 +161,7 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
161
161
|
|
|
162
162
|
describe '#scope' do
|
|
163
163
|
it "passes the scope block through to the index" do
|
|
164
|
-
index.
|
|
164
|
+
expect(index).to receive(:scope=).with(instance_of(Proc))
|
|
165
165
|
|
|
166
166
|
instance.scope { :foo }
|
|
167
167
|
end
|
|
@@ -169,18 +169,18 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
169
169
|
|
|
170
170
|
describe '#set_property' do
|
|
171
171
|
before :each do
|
|
172
|
-
index.class.
|
|
172
|
+
allow(index.class).to receive_messages :settings => [:morphology]
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
it 'saves other settings as index options' do
|
|
176
176
|
instance.set_property :field_weights => {:name => 10}
|
|
177
177
|
|
|
178
|
-
index.options[:field_weights].
|
|
178
|
+
expect(index.options[:field_weights]).to eq({:name => 10})
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
context 'index settings' do
|
|
182
182
|
it "sets the provided setting" do
|
|
183
|
-
index.
|
|
183
|
+
expect(index).to receive(:morphology=).with('stem_en')
|
|
184
184
|
|
|
185
185
|
instance.set_property :morphology => 'stem_en'
|
|
186
186
|
end
|
|
@@ -194,8 +194,8 @@ describe ThinkingSphinx::RealTime::Interpreter do
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
interpreter = ThinkingSphinx::RealTime::Interpreter.new index, block
|
|
197
|
-
interpreter.translate
|
|
198
|
-
|
|
197
|
+
expect(interpreter.translate!).
|
|
198
|
+
to eq(interpreter.__id__)
|
|
199
199
|
end
|
|
200
200
|
end
|
|
201
201
|
end
|
|
@@ -17,29 +17,29 @@ describe ThinkingSphinx::Scopes do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "creates new search" do
|
|
20
|
-
model.foo.class.
|
|
20
|
+
expect(model.foo.class).to eq(ThinkingSphinx::Search)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "passes block result to constructor" do
|
|
24
|
-
model.foo.options[:with].
|
|
24
|
+
expect(model.foo.options[:with]).to eq({:foo => :bar})
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "passes non-scopes through to the standard method error call" do
|
|
28
|
-
|
|
28
|
+
expect { model.bar }.to raise_error(NoMethodError)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
describe '#sphinx_scope' do
|
|
33
33
|
it "saves the given block with a name" do
|
|
34
34
|
model.sphinx_scope(:foo) { 27 }
|
|
35
|
-
model.sphinx_scopes[:foo].call.
|
|
35
|
+
expect(model.sphinx_scopes[:foo].call).to eq(27)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
describe '#default_sphinx_scope' do
|
|
40
40
|
it "gets and sets the default scope depending on the argument" do
|
|
41
41
|
model.default_sphinx_scope :foo
|
|
42
|
-
model.default_sphinx_scope.
|
|
42
|
+
expect(model.default_sphinx_scope).to eq(:foo)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -12,11 +12,11 @@ describe ThinkingSphinx::Search::Glaze do
|
|
|
12
12
|
|
|
13
13
|
describe '#!=' do
|
|
14
14
|
it "is true for objects that don't match" do
|
|
15
|
-
(glaze != double('foo')).
|
|
15
|
+
expect(glaze != double('foo')).to be_truthy
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "is false when the underlying object is a match" do
|
|
19
|
-
(glaze != object).
|
|
19
|
+
expect(glaze != object).to be_falsey
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -28,50 +28,50 @@ describe ThinkingSphinx::Search::Glaze do
|
|
|
28
28
|
let(:pane_two) { double('pane two', :foo => 'two', :bar => 'two') }
|
|
29
29
|
|
|
30
30
|
before :each do
|
|
31
|
-
klass.
|
|
31
|
+
allow(klass).to receive(:new).and_return(pane_one, pane_two)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "respects objects existing methods" do
|
|
35
|
-
object.
|
|
35
|
+
allow(object).to receive_messages :foo => 'original'
|
|
36
36
|
|
|
37
|
-
glaze.foo.
|
|
37
|
+
expect(glaze.foo).to eq('original')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "uses the first pane that responds to the method" do
|
|
41
|
-
glaze.foo.
|
|
42
|
-
glaze.bar.
|
|
41
|
+
expect(glaze.foo).to eq('one')
|
|
42
|
+
expect(glaze.bar).to eq('two')
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "raises the method missing error otherwise" do
|
|
46
|
-
object.
|
|
47
|
-
object.
|
|
46
|
+
allow(object).to receive_messages :respond_to? => false
|
|
47
|
+
allow(object).to receive(:baz).and_raise(NoMethodError)
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
expect { glaze.baz }.to raise_error(NoMethodError)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
describe '#respond_to?' do
|
|
54
54
|
it "responds to underlying object methods" do
|
|
55
|
-
object.
|
|
55
|
+
allow(object).to receive_messages :foo => true
|
|
56
56
|
|
|
57
|
-
glaze.respond_to?(:foo).
|
|
57
|
+
expect(glaze.respond_to?(:foo)).to be_truthy
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "responds to underlying pane methods" do
|
|
61
61
|
pane = double('Pane Class', :new => double('pane', :bar => true))
|
|
62
62
|
glaze = ThinkingSphinx::Search::Glaze.new context, object, raw, [pane]
|
|
63
63
|
|
|
64
|
-
glaze.respond_to?(:bar).
|
|
64
|
+
expect(glaze.respond_to?(:bar)).to be_truthy
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "does not to respond to methods that don't exist" do
|
|
68
|
-
glaze.respond_to?(:something).
|
|
68
|
+
expect(glaze.respond_to?(:something)).to be_falsey
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
describe '#unglazed' do
|
|
73
73
|
it "returns the original object" do
|
|
74
|
-
glaze.unglazed.
|
|
74
|
+
expect(glaze.unglazed).to eq(object)
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -14,30 +14,30 @@ describe ThinkingSphinx::Search::Query do
|
|
|
14
14
|
it "passes through the keyword as provided" do
|
|
15
15
|
query = ThinkingSphinx::Search::Query.new 'pancakes'
|
|
16
16
|
|
|
17
|
-
query.to_s.
|
|
17
|
+
expect(query.to_s).to eq('pancakes')
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "pairs fields and keywords for given conditions" do
|
|
21
21
|
query = ThinkingSphinx::Search::Query.new '', :title => 'pancakes'
|
|
22
22
|
|
|
23
|
-
query.to_s.
|
|
23
|
+
expect(query.to_s).to eq('@title pancakes')
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "combines both keywords and conditions" do
|
|
27
27
|
query = ThinkingSphinx::Search::Query.new 'tasty', :title => 'pancakes'
|
|
28
28
|
|
|
29
|
-
query.to_s.
|
|
29
|
+
expect(query.to_s).to eq('tasty @title pancakes')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "automatically stars keywords if requested" do
|
|
33
|
-
ThinkingSphinx::Query.
|
|
33
|
+
expect(ThinkingSphinx::Query).to receive(:wildcard).with('cake', true).
|
|
34
34
|
and_return('*cake*')
|
|
35
35
|
|
|
36
36
|
ThinkingSphinx::Search::Query.new('cake', {}, true).to_s
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "automatically stars condition keywords if requested" do
|
|
40
|
-
ThinkingSphinx::Query.
|
|
40
|
+
expect(ThinkingSphinx::Query).to receive(:wildcard).with('pan', true).
|
|
41
41
|
and_return('*pan*')
|
|
42
42
|
|
|
43
43
|
ThinkingSphinx::Search::Query.new('', {:title => 'pan'}, true).to_s
|
|
@@ -47,32 +47,32 @@ describe ThinkingSphinx::Search::Query do
|
|
|
47
47
|
query = ThinkingSphinx::Search::Query.new '',
|
|
48
48
|
{:sphinx_internal_class_name => 'article'}, true
|
|
49
49
|
|
|
50
|
-
query.to_s.
|
|
50
|
+
expect(query.to_s).to eq('@sphinx_internal_class_name article')
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "handles null values by removing them from the conditions hash" do
|
|
54
54
|
query = ThinkingSphinx::Search::Query.new '', :title => nil
|
|
55
55
|
|
|
56
|
-
query.to_s.
|
|
56
|
+
expect(query.to_s).to eq('')
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "handles empty string values by removing them from the conditions hash" do
|
|
60
60
|
query = ThinkingSphinx::Search::Query.new '', :title => ''
|
|
61
61
|
|
|
62
|
-
query.to_s.
|
|
62
|
+
expect(query.to_s).to eq('')
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "handles nil queries" do
|
|
66
66
|
query = ThinkingSphinx::Search::Query.new nil, {}
|
|
67
67
|
|
|
68
|
-
query.to_s.
|
|
68
|
+
expect(query.to_s).to eq('')
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "allows mixing of blank and non-blank conditions" do
|
|
72
72
|
query = ThinkingSphinx::Search::Query.new 'tasty', :title => 'pancakes',
|
|
73
73
|
:ingredients => nil
|
|
74
74
|
|
|
75
|
-
query.to_s.
|
|
75
|
+
expect(query.to_s).to eq('tasty @title pancakes')
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -34,26 +34,26 @@ describe ThinkingSphinx::Search do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
before :each do
|
|
37
|
-
ThinkingSphinx::Search::Context.
|
|
37
|
+
allow(ThinkingSphinx::Search::Context).to receive_messages :new => context
|
|
38
38
|
|
|
39
39
|
stub_const 'ThinkingSphinx::Middlewares::DEFAULT', stack
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
describe '#current_page' do
|
|
43
43
|
it "should return 1 by default" do
|
|
44
|
-
search.current_page.
|
|
44
|
+
expect(search.current_page).to eq(1)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "should handle string page values" do
|
|
48
|
-
ThinkingSphinx::Search.new(:page => '2').current_page.
|
|
48
|
+
expect(ThinkingSphinx::Search.new(:page => '2').current_page).to eq(2)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it "should handle empty string page values" do
|
|
52
|
-
ThinkingSphinx::Search.new(:page => '').current_page.
|
|
52
|
+
expect(ThinkingSphinx::Search.new(:page => '').current_page).to eq(1)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it "should return the requested page" do
|
|
56
|
-
ThinkingSphinx::Search.new(:page => 10).current_page.
|
|
56
|
+
expect(ThinkingSphinx::Search.new(:page => 10).current_page).to eq(10)
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -61,25 +61,25 @@ describe ThinkingSphinx::Search do
|
|
|
61
61
|
it "returns false if there is anything in the data set" do
|
|
62
62
|
context[:results] << double
|
|
63
63
|
|
|
64
|
-
search.
|
|
64
|
+
expect(search).not_to be_empty
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "returns true if the data set is empty" do
|
|
68
68
|
context[:results].clear
|
|
69
69
|
|
|
70
|
-
search.
|
|
70
|
+
expect(search).to be_empty
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
describe '#initialize' do
|
|
75
75
|
it "lazily loads by default" do
|
|
76
|
-
stack.
|
|
76
|
+
expect(stack).not_to receive(:call)
|
|
77
77
|
|
|
78
78
|
ThinkingSphinx::Search.new
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "should automatically populate when :populate is set to true" do
|
|
82
|
-
stack.
|
|
82
|
+
expect(stack).to receive(:call).and_return(true)
|
|
83
83
|
|
|
84
84
|
ThinkingSphinx::Search.new(:populate => true)
|
|
85
85
|
end
|
|
@@ -87,74 +87,74 @@ describe ThinkingSphinx::Search do
|
|
|
87
87
|
|
|
88
88
|
describe '#offset' do
|
|
89
89
|
it "should default to 0" do
|
|
90
|
-
search.offset.
|
|
90
|
+
expect(search.offset).to eq(0)
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
it "should increase by the per_page value for each page in" do
|
|
94
|
-
ThinkingSphinx::Search.new(:per_page => 25, :page => 2).offset.
|
|
95
|
-
|
|
94
|
+
expect(ThinkingSphinx::Search.new(:per_page => 25, :page => 2).offset).
|
|
95
|
+
to eq(25)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "should prioritise explicit :offset over calculated if given" do
|
|
99
|
-
ThinkingSphinx::Search.new(:offset => 5).offset.
|
|
99
|
+
expect(ThinkingSphinx::Search.new(:offset => 5).offset).to eq(5)
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
describe '#page' do
|
|
104
104
|
it "sets the current page" do
|
|
105
105
|
search.page(3)
|
|
106
|
-
search.current_page.
|
|
106
|
+
expect(search.current_page).to eq(3)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "returns the search object" do
|
|
110
|
-
search.page(2).
|
|
110
|
+
expect(search.page(2)).to eq(search)
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
describe '#per' do
|
|
115
115
|
it "sets the current per_page value" do
|
|
116
116
|
search.per(29)
|
|
117
|
-
search.per_page.
|
|
117
|
+
expect(search.per_page).to eq(29)
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "returns the search object" do
|
|
121
|
-
search.per(29).
|
|
121
|
+
expect(search.per(29)).to eq(search)
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
describe '#per_page' do
|
|
126
126
|
it "defaults to 20" do
|
|
127
|
-
search.per_page.
|
|
127
|
+
expect(search.per_page).to eq(20)
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it "is set as part of the search options" do
|
|
131
|
-
ThinkingSphinx::Search.new(:per_page => 10).per_page.
|
|
131
|
+
expect(ThinkingSphinx::Search.new(:per_page => 10).per_page).to eq(10)
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
it "should prioritise :limit over :per_page if given" do
|
|
135
|
-
ThinkingSphinx::Search.new(:per_page => 30, :limit => 40).per_page.
|
|
136
|
-
|
|
135
|
+
expect(ThinkingSphinx::Search.new(:per_page => 30, :limit => 40).per_page).
|
|
136
|
+
to eq(40)
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "should allow for string arguments" do
|
|
140
|
-
ThinkingSphinx::Search.new(:per_page => '10').per_page.
|
|
140
|
+
expect(ThinkingSphinx::Search.new(:per_page => '10').per_page).to eq(10)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it "allows setting of the per_page value" do
|
|
144
144
|
search.per_page(24)
|
|
145
|
-
search.per_page.
|
|
145
|
+
expect(search.per_page).to eq(24)
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
describe '#populate' do
|
|
150
150
|
it "runs the middleware" do
|
|
151
|
-
stack.
|
|
151
|
+
expect(stack).to receive(:call).with([context]).and_return(true)
|
|
152
152
|
|
|
153
153
|
search.populate
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
it "does not retrieve results twice" do
|
|
157
|
-
stack.
|
|
157
|
+
expect(stack).to receive(:call).with([context]).once.and_return(true)
|
|
158
158
|
|
|
159
159
|
search.populate
|
|
160
160
|
search.populate
|
|
@@ -163,11 +163,11 @@ describe ThinkingSphinx::Search do
|
|
|
163
163
|
|
|
164
164
|
describe '#respond_to?' do
|
|
165
165
|
it "should respond to Array methods" do
|
|
166
|
-
search.respond_to?(:each).
|
|
166
|
+
expect(search.respond_to?(:each)).to be_truthy
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "should respond to Search methods" do
|
|
170
|
-
search.respond_to?(:per_page).
|
|
170
|
+
expect(search.respond_to?(:per_page)).to be_truthy
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
it "should return true for methods delegated to pagination mask by method_missing" do
|
|
@@ -196,7 +196,7 @@ describe ThinkingSphinx::Search do
|
|
|
196
196
|
|
|
197
197
|
context[:results] << glazed
|
|
198
198
|
|
|
199
|
-
search.to_a.first.__id__.
|
|
199
|
+
expect(search.to_a.first.__id__).to eq(unglazed.__id__)
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
|