freelancing-god-thinking-sphinx 1.1.20 → 1.1.21
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thinking_sphinx.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +2 -0
- data/lib/thinking_sphinx/facet.rb +1 -1
- data/lib/thinking_sphinx/search/facets.rb +2 -1
- data/rails/init.rb +14 -0
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +5 -5
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +4 -4
- data/spec/unit/thinking_sphinx/active_record_spec.rb +26 -31
- data/spec/unit/thinking_sphinx/association_spec.rb +4 -5
- data/spec/unit/thinking_sphinx/attribute_spec.rb +8 -8
- data/spec/unit/thinking_sphinx/collection_spec.rb +7 -6
- data/spec/unit/thinking_sphinx/configuration_spec.rb +58 -2
- data/spec/unit/thinking_sphinx/facet_spec.rb +24 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +8 -8
- data/spec/unit/thinking_sphinx/rails_additions_spec.rb +13 -5
- data/spec/unit/thinking_sphinx/search_spec.rb +22 -5
- data/spec/unit/thinking_sphinx_spec.rb +6 -4
- data/tasks/distribution.rb +1 -0
- metadata +3 -2
data/lib/thinking_sphinx.rb
CHANGED
@@ -92,7 +92,7 @@ module ThinkingSphinx
|
|
92
92
|
|
93
93
|
def translate(object, attribute_value)
|
94
94
|
column.__stack.each { |method|
|
95
|
-
object = object.send(method)
|
95
|
+
return nil unless object = object.send(method)
|
96
96
|
}
|
97
97
|
if object.is_a?(Array)
|
98
98
|
object.collect { |item| item.send(column.__name) }
|
data/rails/init.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'thinking_sphinx'
|
2
|
+
require 'action_controller/dispatcher'
|
3
|
+
|
4
|
+
ActionController::Dispatcher.to_prepare :thinking_sphinx do
|
5
|
+
# Force internationalisation to be loaded.
|
6
|
+
if Rails::VERSION::STRING.to_f > 2.2
|
7
|
+
I18n.backend.reload!
|
8
|
+
I18n.backend.available_locales
|
9
|
+
elsif Rails::VERSION::STRING.to_f > 2.1
|
10
|
+
I18n.backend.load_translations(*I18n.load_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
ThinkingSphinx::Configuration.instance.load_models
|
14
|
+
end
|
@@ -80,7 +80,8 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
|
|
80
80
|
:sphinx_document_id => 1
|
81
81
|
)
|
82
82
|
|
83
|
-
@client = Riddle::Client.
|
83
|
+
@client = Riddle::Client.new
|
84
|
+
@client.stub!(:update => true)
|
84
85
|
Riddle::Client.stub_method(:new => @client)
|
85
86
|
end
|
86
87
|
|
@@ -120,17 +121,16 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
|
|
120
121
|
end
|
121
122
|
|
122
123
|
it "shouldn't update the deleted attribute if not in the index" do
|
123
|
-
@
|
124
|
+
@client.should_not_receive(:update)
|
124
125
|
|
125
|
-
@
|
126
|
+
@person.send(:index_delta)
|
126
127
|
end
|
127
128
|
|
128
129
|
it "should update the deleted attribute if in the core index" do
|
129
130
|
@person.stub_method(:in_both_indexes? => true)
|
131
|
+
@client.should_receive(:update)
|
130
132
|
|
131
133
|
@person.send(:index_delta)
|
132
|
-
|
133
|
-
@client.should have_received(:update)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -2,19 +2,19 @@ require 'spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe "ThinkingSphinx::ActiveRecord::Search" do
|
4
4
|
it "should add search_for_ids to ActiveRecord::Base" do
|
5
|
-
ActiveRecord::Base.
|
5
|
+
ActiveRecord::Base.should respond_to("search_for_ids")
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should add search_for_ids to ActiveRecord::Base" do
|
9
|
-
ActiveRecord::Base.
|
9
|
+
ActiveRecord::Base.should respond_to("search")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should add search_count to ActiveRecord::Base" do
|
13
|
-
ActiveRecord::Base.
|
13
|
+
ActiveRecord::Base.should respond_to("search_count")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should add search_for_id to ActiveRecord::Base" do
|
17
|
-
ActiveRecord::Base.
|
17
|
+
ActiveRecord::Base.should respond_to("search_for_id")
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "search_for_ids method" do
|
@@ -3,7 +3,7 @@ require 'spec/spec_helper'
|
|
3
3
|
describe "ThinkingSphinx::ActiveRecord" do
|
4
4
|
describe "define_index method" do
|
5
5
|
before :each do
|
6
|
-
module TestModule
|
6
|
+
module ::TestModule
|
7
7
|
class TestModel < ActiveRecord::Base; end
|
8
8
|
end
|
9
9
|
|
@@ -185,7 +185,8 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
185
185
|
:address => "an address",
|
186
186
|
:port => 123
|
187
187
|
)
|
188
|
-
@client = Riddle::Client.
|
188
|
+
@client = Riddle::Client.new
|
189
|
+
@client.stub!(:update => true)
|
189
190
|
@person = Person.find(:first)
|
190
191
|
|
191
192
|
Riddle::Client.stub_method(:new => @client)
|
@@ -202,87 +203,82 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
202
203
|
end
|
203
204
|
|
204
205
|
it "should update the core index's deleted flag if in core index" do
|
205
|
-
@
|
206
|
-
|
207
|
-
@client.should have_received(:update).with(
|
206
|
+
@client.should_receive(:update).with(
|
208
207
|
"person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
209
208
|
)
|
209
|
+
|
210
|
+
@person.toggle_deleted
|
210
211
|
end
|
211
212
|
|
212
213
|
it "shouldn't update the core index's deleted flag if the record isn't in it" do
|
213
214
|
@person.stub_method(:in_core_index? => false)
|
214
|
-
|
215
|
-
@person.toggle_deleted
|
216
|
-
|
217
|
-
@client.should_not have_received(:update).with(
|
215
|
+
@client.should_not_receive(:update).with(
|
218
216
|
"person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
219
217
|
)
|
218
|
+
|
219
|
+
@person.toggle_deleted
|
220
220
|
end
|
221
221
|
|
222
222
|
it "shouldn't attempt to update the deleted flag if sphinx isn't running" do
|
223
223
|
ThinkingSphinx.stub_method(:sphinx_running? => false)
|
224
|
+
@client.should_not_receive(:update)
|
224
225
|
|
225
226
|
@person.toggle_deleted
|
226
227
|
|
227
228
|
@person.should_not have_received(:in_core_index?)
|
228
|
-
@client.should_not have_received(:update)
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should update the delta index's deleted flag if delta indexes are enabled and the instance's delta is true" do
|
232
232
|
ThinkingSphinx.stub_method(:deltas_enabled? => true)
|
233
233
|
Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
|
234
234
|
@person.delta = true
|
235
|
-
|
236
|
-
@person.toggle_deleted
|
237
|
-
|
238
|
-
@client.should have_received(:update).with(
|
235
|
+
@client.should_receive(:update).with(
|
239
236
|
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
240
237
|
)
|
238
|
+
|
239
|
+
@person.toggle_deleted
|
241
240
|
end
|
242
241
|
|
243
242
|
it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is false" do
|
244
243
|
ThinkingSphinx.stub_method(:deltas_enabled? => true)
|
245
244
|
Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
|
246
245
|
@person.delta = false
|
247
|
-
|
248
|
-
@person.toggle_deleted
|
249
|
-
|
250
|
-
@client.should_not have_received(:update).with(
|
246
|
+
@client.should_not_receive(:update).with(
|
251
247
|
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
252
248
|
)
|
249
|
+
|
250
|
+
@person.toggle_deleted
|
253
251
|
end
|
254
252
|
|
255
253
|
it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is equivalent to false" do
|
256
254
|
ThinkingSphinx.stub_method(:deltas_enabled? => true)
|
257
255
|
Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
|
258
256
|
@person.delta = 0
|
259
|
-
|
260
|
-
@person.toggle_deleted
|
261
|
-
|
262
|
-
@client.should_not have_received(:update).with(
|
257
|
+
@client.should_not_receive(:update).with(
|
263
258
|
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
264
259
|
)
|
260
|
+
|
261
|
+
@person.toggle_deleted
|
265
262
|
end
|
266
263
|
|
267
264
|
it "shouldn't update the delta index if delta indexes are disabled" do
|
268
265
|
ThinkingSphinx.stub_method(:deltas_enabled? => true)
|
269
|
-
@
|
270
|
-
|
271
|
-
@client.should_not have_received(:update).with(
|
266
|
+
@client.should_not_receive(:update).with(
|
272
267
|
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
273
268
|
)
|
269
|
+
|
270
|
+
@person.toggle_deleted
|
274
271
|
end
|
275
272
|
|
276
273
|
it "should not update the delta index if delta indexing is disabled" do
|
277
274
|
ThinkingSphinx.stub_method(:deltas_enabled? => false)
|
278
275
|
Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
|
279
276
|
@person.delta = true
|
280
|
-
|
281
|
-
@person.toggle_deleted
|
282
|
-
|
283
|
-
@client.should_not have_received(:update).with(
|
277
|
+
@client.should_not_receive(:update).with(
|
284
278
|
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
|
285
279
|
)
|
280
|
+
|
281
|
+
@person.toggle_deleted
|
286
282
|
end
|
287
283
|
|
288
284
|
it "should not update either index if updates are disabled" do
|
@@ -292,10 +288,9 @@ describe "ThinkingSphinx::ActiveRecord" do
|
|
292
288
|
)
|
293
289
|
Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
|
294
290
|
@person.delta = true
|
291
|
+
@client.should_not_receive(:update)
|
295
292
|
|
296
293
|
@person.toggle_deleted
|
297
|
-
|
298
|
-
@client.should_not have_received(:update)
|
299
294
|
end
|
300
295
|
end
|
301
296
|
|
@@ -79,7 +79,8 @@ describe ThinkingSphinx::Association do
|
|
79
79
|
before :each do
|
80
80
|
@parent_join = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_instance
|
81
81
|
@join = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_instance
|
82
|
-
@parent = ThinkingSphinx::Association.
|
82
|
+
@parent = ThinkingSphinx::Association.new(nil, nil)
|
83
|
+
@parent.stub!(:join_to => true, :join => nil)
|
83
84
|
@base_join = Object.stub_instance(:joins => [:a, :b, :c])
|
84
85
|
|
85
86
|
::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_method(:new => @join)
|
@@ -87,19 +88,17 @@ describe ThinkingSphinx::Association do
|
|
87
88
|
|
88
89
|
it "should call the parent's join_to if parent has no join" do
|
89
90
|
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
91
|
+
@parent.should_receive(:join_to).with(@base_join)
|
90
92
|
|
91
93
|
@assoc.join_to(@base_join)
|
92
|
-
|
93
|
-
@parent.should have_received(:join_to).with(@base_join)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should not call the parent's join_to if it already has a join" do
|
97
97
|
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
98
98
|
@parent.stub_method(:join => @parent_join)
|
99
|
+
@parent.should_not_receive(:join_to)
|
99
100
|
|
100
101
|
@assoc.join_to(@base_join)
|
101
|
-
|
102
|
-
@parent.should_not have_received(:join_to)
|
103
102
|
end
|
104
103
|
|
105
104
|
it "should define the join association with a JoinAssociation instance" do
|
@@ -53,15 +53,15 @@ describe ThinkingSphinx::Attribute do
|
|
53
53
|
@attribute.columns.each { |col| @attribute.associations[col] = [] }
|
54
54
|
@attribute.model = Person
|
55
55
|
|
56
|
-
@first_join = Object.
|
57
|
-
@
|
56
|
+
@first_join = Object.new
|
57
|
+
@first_join.stub!(:aliased_table_name => "tabular")
|
58
|
+
@second_join = Object.new
|
59
|
+
@second_join.stub!(:aliased_table_name => "data")
|
58
60
|
|
59
|
-
@first_assoc = ThinkingSphinx::Association.
|
60
|
-
|
61
|
-
|
62
|
-
@second_assoc
|
63
|
-
:join => @second_join, :has_column? => true
|
64
|
-
)
|
61
|
+
@first_assoc = ThinkingSphinx::Association.new nil, nil
|
62
|
+
@first_assoc.stub!(:join => @first_join, :has_column? => true)
|
63
|
+
@second_assoc = ThinkingSphinx::Association.new nil, nil
|
64
|
+
@second_assoc.stub!(:join => @second_join, :has_column? => true)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should return the column name if the column is a string" do
|
@@ -2,12 +2,13 @@ require 'spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Collection do
|
4
4
|
it "should behave like WillPaginate::Collection" do
|
5
|
-
ThinkingSphinx::Collection.instance_methods.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
instance_methods = ThinkingSphinx::Collection.instance_methods.collect { |m| m.to_s }
|
6
|
+
instance_methods.should include("previous_page")
|
7
|
+
instance_methods.should include("next_page")
|
8
|
+
instance_methods.should include("current_page")
|
9
|
+
instance_methods.should include("total_pages")
|
10
|
+
instance_methods.should include("total_entries")
|
11
|
+
instance_methods.should include("offset")
|
11
12
|
|
12
13
|
ThinkingSphinx::Collection.ancestors.should include(Array)
|
13
14
|
end
|
@@ -10,11 +10,11 @@ describe ThinkingSphinx::Configuration do
|
|
10
10
|
|
11
11
|
it "should use the Merb environment value if set" do
|
12
12
|
unless defined?(Merb)
|
13
|
-
module Merb; end
|
13
|
+
module ::Merb; end
|
14
14
|
end
|
15
15
|
|
16
16
|
ThinkingSphinx::Configuration.stub_method(:defined? => true)
|
17
|
-
Merb.
|
17
|
+
Merb.stub!(:environment => "merb_production")
|
18
18
|
ThinkingSphinx::Configuration.environment.should == "merb_production"
|
19
19
|
|
20
20
|
Object.send(:remove_const, :Merb)
|
@@ -121,6 +121,62 @@ describe ThinkingSphinx::Configuration do
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
describe "#load_models" do
|
125
|
+
before :each do
|
126
|
+
@config = ThinkingSphinx::Configuration.instance
|
127
|
+
@config.model_directories = ['']
|
128
|
+
|
129
|
+
@file_name = 'a.rb'
|
130
|
+
@model_name_lower = 'a'
|
131
|
+
@class_name = 'A'
|
132
|
+
|
133
|
+
@file_name.stub!(:gsub).and_return(@model_name_lower)
|
134
|
+
@model_name_lower.stub!(:camelize).and_return(@class_name)
|
135
|
+
Dir.stub(:[]).and_return([@file_name])
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should load the files by guessing the file name" do
|
139
|
+
@class_name.should_receive(:constantize).and_return(true)
|
140
|
+
|
141
|
+
@config.load_models
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should not raise errors if the model name is nil" do
|
145
|
+
@file_name.stub!(:gsub).and_return(nil)
|
146
|
+
|
147
|
+
lambda {
|
148
|
+
@config.load_models
|
149
|
+
}.should_not raise_error
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not raise errors if the file name does not represent a class name" do
|
153
|
+
@class_name.should_receive(:constantize).and_raise(NameError)
|
154
|
+
|
155
|
+
lambda {
|
156
|
+
@config.load_models
|
157
|
+
}.should_not raise_error
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should retry if the first pass fails and contains a directory" do
|
161
|
+
@model_name_lower.stub!(:gsub!).and_return(true, nil)
|
162
|
+
@class_name.stub(:constantize).and_raise(LoadError)
|
163
|
+
@model_name_lower.should_receive(:camelize).twice
|
164
|
+
|
165
|
+
lambda {
|
166
|
+
@config.load_models
|
167
|
+
}.should_not raise_error
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should catch database errors with a warning" do
|
171
|
+
@class_name.should_receive(:constantize).and_raise(Mysql::Error)
|
172
|
+
@config.should_receive(:puts).with('Warning: Error loading a.rb')
|
173
|
+
|
174
|
+
lambda {
|
175
|
+
@config.load_models
|
176
|
+
}.should_not raise_error
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
124
180
|
it "should insert set index options into the configuration file" do
|
125
181
|
config = ThinkingSphinx::Configuration.instance
|
126
182
|
ThinkingSphinx::Configuration::IndexOptions.each do |option|
|
@@ -275,4 +275,28 @@ describe ThinkingSphinx::Facet do
|
|
275
275
|
ThinkingSphinx::Facet.new(attribute).type.should == :anything
|
276
276
|
end
|
277
277
|
end
|
278
|
+
|
279
|
+
describe "#value" do
|
280
|
+
before :each do
|
281
|
+
@index = ThinkingSphinx::Index.new(Friendship)
|
282
|
+
@source = ThinkingSphinx::Source.new(@index)
|
283
|
+
@field = ThinkingSphinx::Field.new(
|
284
|
+
@source, ThinkingSphinx::Index::FauxColumn.new(:person, :first_name)
|
285
|
+
)
|
286
|
+
@facet = ThinkingSphinx::Facet.new(@field)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should return association values" do
|
290
|
+
person = Person.find(:first)
|
291
|
+
friendship = Friendship.new(:person => person)
|
292
|
+
|
293
|
+
@facet.value(friendship, 1).should == person.first_name
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should return nil if the association is nil" do
|
297
|
+
friendship = Friendship.new(:person => nil)
|
298
|
+
|
299
|
+
@facet.value(friendship, 1).should be_nil
|
300
|
+
end
|
301
|
+
end
|
278
302
|
end
|
@@ -85,15 +85,15 @@ describe ThinkingSphinx::Field do
|
|
85
85
|
@field.columns.each { |col| @field.associations[col] = [] }
|
86
86
|
@field.model = Person
|
87
87
|
|
88
|
-
@first_join = Object.
|
89
|
-
@
|
88
|
+
@first_join = Object.new
|
89
|
+
@first_join.stub!(:aliased_table_name => "tabular")
|
90
|
+
@second_join = Object.new
|
91
|
+
@second_join.stub!(:aliased_table_name => "data")
|
90
92
|
|
91
|
-
@first_assoc = ThinkingSphinx::Association.
|
92
|
-
|
93
|
-
|
94
|
-
@second_assoc
|
95
|
-
:join => @second_join, :has_column? => true
|
96
|
-
)
|
93
|
+
@first_assoc = ThinkingSphinx::Association.new nil, nil
|
94
|
+
@first_assoc.stub!(:join => @first_join, :has_column? => true)
|
95
|
+
@second_assoc = ThinkingSphinx::Association.new nil, nil
|
96
|
+
@second_assoc.stub!(:join => @second_join, :has_column? => true)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should return the column name if the column is a string" do
|
@@ -20,12 +20,16 @@ describe ThinkingSphinx::HashExcept do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "extends Hash" do
|
23
|
+
before :each do
|
24
|
+
@instance_methods = Hash.instance_methods.collect { |m| m.to_s }
|
25
|
+
end
|
26
|
+
|
23
27
|
it 'with except' do
|
24
|
-
|
28
|
+
@instance_methods.include?('except').should be_true
|
25
29
|
end
|
26
30
|
|
27
31
|
it 'with except!' do
|
28
|
-
|
32
|
+
@instance_methods.include?('except!').should be_true
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -45,7 +49,7 @@ describe ThinkingSphinx::ArrayExtractOptions do
|
|
45
49
|
|
46
50
|
describe "extends Array" do
|
47
51
|
it 'with extract_options!' do
|
48
|
-
Array.instance_methods.include?('extract_options!').should be_true
|
52
|
+
Array.instance_methods.collect { |m| m.to_s }.include?('extract_options!').should be_true
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
@@ -61,7 +65,9 @@ describe ThinkingSphinx::AbstractQuotedTableName do
|
|
61
65
|
|
62
66
|
describe "extends ActiveRecord::ConnectionAdapters::AbstractAdapter" do
|
63
67
|
it 'with quote_table_name' do
|
64
|
-
ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.
|
68
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.collect { |m|
|
69
|
+
m.to_s
|
70
|
+
}.include?('quote_table_name').should be_true
|
65
71
|
end
|
66
72
|
end
|
67
73
|
end
|
@@ -77,7 +83,9 @@ describe ThinkingSphinx::MysqlQuotedTableName do
|
|
77
83
|
describe "extends ActiveRecord::ConnectionAdapters::MysqlAdapter" do
|
78
84
|
it 'with quote_table_name' do
|
79
85
|
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
|
80
|
-
ActiveRecord::ConnectionAdapters.const_get(adapter).instance_methods.
|
86
|
+
ActiveRecord::ConnectionAdapters.const_get(adapter).instance_methods.collect { |m|
|
87
|
+
m.to_s
|
88
|
+
}.include?("quote_table_name").should be_true
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
@@ -5,7 +5,8 @@ describe ThinkingSphinx::Search do
|
|
5
5
|
describe "search method" do
|
6
6
|
describe ":star option" do
|
7
7
|
before :each do
|
8
|
-
@client = Riddle::Client.
|
8
|
+
@client = Riddle::Client.new
|
9
|
+
@client.stub!(
|
9
10
|
:filters => [],
|
10
11
|
:filters= => true,
|
11
12
|
:id_range= => true,
|
@@ -26,25 +27,29 @@ describe ThinkingSphinx::Search do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should not apply by default" do
|
30
|
+
@client.should_receive(:query).with("foo bar",'*','')
|
31
|
+
|
29
32
|
ThinkingSphinx::Search.search "foo bar"
|
30
|
-
@client.should have_received(:query).with("foo bar",'*','')
|
31
33
|
end
|
32
34
|
|
33
35
|
it "should apply when passed, and handle full extended syntax" do
|
34
36
|
input = %{a b* c (d | e) 123 5&6 (f_f g) !h "i j" "k l"~10 "m n"/3 @o p -(q|r)}
|
35
37
|
expected = %{*a* b* *c* (*d* | *e*) *123* *5*&*6* (*f_f* *g*) !*h* "i j" "k l"~10 "m n"/3 @o *p* -(*q*|*r*)}
|
38
|
+
@client.should_receive(:query).with(expected,'*','')
|
39
|
+
|
36
40
|
ThinkingSphinx::Search.search input, :star => true
|
37
|
-
@client.should have_received(:query).with(expected,'*','')
|
38
41
|
end
|
39
42
|
|
40
43
|
it "should default to /\w+/ as token" do
|
44
|
+
@client.should_receive(:query).with("*foo*@*bar*.*com*",'*','')
|
45
|
+
|
41
46
|
ThinkingSphinx::Search.search "foo@bar.com", :star => true
|
42
|
-
@client.should have_received(:query).with("*foo*@*bar*.*com*",'*','')
|
43
47
|
end
|
44
48
|
|
45
49
|
it "should honour custom token" do
|
50
|
+
@client.should_receive(:query).with("*foo@bar.com* -*foo-bar*",'*','')
|
51
|
+
|
46
52
|
ThinkingSphinx::Search.search "foo@bar.com -foo-bar", :star => /[\w@.-]+/u
|
47
|
-
@client.should have_received(:query).with("*foo@bar.com* -*foo-bar*",'*','')
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
@@ -182,6 +187,18 @@ describe ThinkingSphinx::Search do
|
|
182
187
|
)
|
183
188
|
end
|
184
189
|
|
190
|
+
it "should not use an explicit :page" do
|
191
|
+
ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
|
192
|
+
ThinkingSphinx::Search.should_receive(:search) do |options|
|
193
|
+
options[:page].should == 1
|
194
|
+
end
|
195
|
+
|
196
|
+
ThinkingSphinx::Search.facets(
|
197
|
+
:all_attributes => true,
|
198
|
+
:page => 3
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
185
202
|
describe "conflicting facets" do
|
186
203
|
before :each do
|
187
204
|
@index = ThinkingSphinx::Index::Builder.generate(Alpha) do
|
@@ -105,12 +105,14 @@ describe ThinkingSphinx do
|
|
105
105
|
|
106
106
|
describe "if not using MySQL" do
|
107
107
|
before :each do
|
108
|
-
adapter = defined?(JRUBY_VERSION) ?
|
108
|
+
adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
|
109
109
|
unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
|
110
110
|
pending "No PostgreSQL"
|
111
111
|
return
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
|
+
@connection = stub(adapter).as_null_object
|
115
|
+
@connection.stub!(
|
114
116
|
:select_all => true,
|
115
117
|
:config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
|
116
118
|
)
|
@@ -124,9 +126,9 @@ describe ThinkingSphinx do
|
|
124
126
|
end
|
125
127
|
|
126
128
|
it "should not call select_all" do
|
127
|
-
|
129
|
+
@connection.should_not_receive(:select_all)
|
128
130
|
|
129
|
-
|
131
|
+
ThinkingSphinx.use_group_by_shortcut?
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
data/tasks/distribution.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freelancing-god-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,6 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- rails/init.rb
|
25
26
|
- lib/thinking_sphinx/active_record/attribute_updates.rb
|
26
27
|
- lib/thinking_sphinx/active_record/delta.rb
|
27
28
|
- lib/thinking_sphinx/active_record/has_many_association.rb
|