summaryrefslogtreecommitdiff
path: root/vendor/plugins/thinking-sphinx/spec/unit
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-04-28 00:15:53 +0200
committerhukl <contact@smyck.org>2009-05-01 17:14:02 +0200
commit4bd16f053847f2efe347ebda9136ef2233ee0d2c (patch)
treef4c11f89455de991c8d87726d5757b752e7129e2 /vendor/plugins/thinking-sphinx/spec/unit
parentd3a9b46ba5c863a0ff377dcffae9a494fe476e02 (diff)
added thinking_sphinx plugin for fulltext search on nodes and heads
Diffstat (limited to 'vendor/plugins/thinking-sphinx/spec/unit')
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/delta_spec.rb136
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb53
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/search_spec.rb107
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record_spec.rb316
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/association_spec.rb247
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/attribute_spec.rb227
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/collection_spec.rb14
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/configuration_spec.rb136
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/core/string_spec.rb9
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/field_spec.rb145
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/builder_spec.rb5
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/faux_column_spec.rb30
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index_spec.rb144
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/rails_additions_spec.rb183
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/search_spec.rb59
-rw-r--r--vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb133
16 files changed, 1944 insertions, 0 deletions
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/delta_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/delta_spec.rb
new file mode 100644
index 0000000..b29065f
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/delta_spec.rb
@@ -0,0 +1,136 @@
1require 'spec/spec_helper'
2
3describe "ThinkingSphinx::ActiveRecord::Delta" do
4 it "should call the toggle_delta method after a save" do
5 @beta = Beta.new(:name => 'beta')
6 @beta.stub_method(:toggle_delta => true)
7
8 @beta.save
9
10 @beta.should have_received(:toggle_delta)
11 end
12
13 it "should call the toggle_delta method after a save!" do
14 @beta = Beta.new(:name => 'beta')
15 @beta.stub_method(:toggle_delta => true)
16
17 @beta.save!
18
19 @beta.should have_received(:toggle_delta)
20 end
21
22 describe "suspended_delta method" do
23 before :each do
24 ThinkingSphinx.stub_method(:deltas_enabled? => true)
25 Person.sphinx_indexes.first.delta_object.stub_method(:` => "")
26 end
27
28 it "should execute the argument block with deltas disabled" do
29 ThinkingSphinx.should_receive(:deltas_enabled=).once.with(false)
30 ThinkingSphinx.should_receive(:deltas_enabled=).once.with(true)
31 lambda { Person.suspended_delta { raise 'i was called' } }.should(
32 raise_error(Exception)
33 )
34 end
35
36 it "should restore deltas_enabled to its original setting" do
37 ThinkingSphinx.stub_method(:deltas_enabled? => false)
38 ThinkingSphinx.should_receive(:deltas_enabled=).twice.with(false)
39 Person.suspended_delta { 'no-op' }
40 end
41
42 it "should restore deltas_enabled to its original setting even if there was an exception" do
43 ThinkingSphinx.stub_method(:deltas_enabled? => false)
44 ThinkingSphinx.should_receive(:deltas_enabled=).twice.with(false)
45 lambda { Person.suspended_delta { raise 'bad error' } }.should(
46 raise_error(Exception)
47 )
48 end
49
50 it "should reindex by default after the code block is run" do
51 Person.should_receive(:index_delta)
52 Person.suspended_delta { 'no-op' }
53 end
54
55 it "should not reindex after the code block if false is passed in" do
56 Person.should_not_receive(:index_delta)
57 Person.suspended_delta(false) { 'no-op' }
58 end
59 end
60
61 describe "toggle_delta method" do
62 it "should set the delta value to true" do
63 @person = Person.new
64
65 @person.delta.should be_false
66 @person.send(:toggle_delta)
67 @person.delta.should be_true
68 end
69 end
70
71 describe "index_delta method" do
72 before :each do
73 ThinkingSphinx::Configuration.stub_method(:environment => "spec")
74 ThinkingSphinx.stub_method(:deltas_enabled? => true, :sphinx_running? => true)
75 Person.delta_object.stub_methods(:` => "", :toggled => true)
76
77 @person = Person.new
78 @person.stub_method(
79 :in_both_indexes? => false,
80 :sphinx_document_id => 1
81 )
82
83 @client = Riddle::Client.stub_instance(:update => true)
84 Riddle::Client.stub_method(:new => @client)
85 end
86
87 it "shouldn't index if delta indexing is disabled" do
88 ThinkingSphinx.stub_method(:deltas_enabled? => false)
89
90 @person.send(:index_delta)
91
92 Person.sphinx_indexes.first.delta_object.should_not have_received(:`)
93 @client.should_not have_received(:update)
94 end
95
96 it "shouldn't index if index updating is disabled" do
97 ThinkingSphinx.stub_method(:updates_enabled? => false)
98
99 @person.send(:index_delta)
100
101 Person.sphinx_indexes.first.delta_object.should_not have_received(:`)
102 end
103
104 it "shouldn't index if the environment is 'test'" do
105 ThinkingSphinx.unstub_method(:deltas_enabled?)
106 ThinkingSphinx.deltas_enabled = nil
107 ThinkingSphinx::Configuration.stub_method(:environment => "test")
108
109 @person.send(:index_delta)
110
111 Person.sphinx_indexes.first.delta_object.should_not have_received(:`)
112 end
113
114 it "should call indexer for the delta index" do
115 @person.send(:index_delta)
116
117 Person.sphinx_indexes.first.delta_object.should have_received(:`).with(
118 "#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config #{ThinkingSphinx::Configuration.instance.config_file} --rotate person_delta"
119 )
120 end
121
122 it "shouldn't update the deleted attribute if not in the index" do
123 @person.send(:index_delta)
124
125 @client.should_not have_received(:update)
126 end
127
128 it "should update the deleted attribute if in the core index" do
129 @person.stub_method(:in_both_indexes? => true)
130
131 @person.send(:index_delta)
132
133 @client.should have_received(:update)
134 end
135 end
136end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
new file mode 100644
index 0000000..b37ac9f
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
@@ -0,0 +1,53 @@
1require 'spec/spec_helper'
2
3describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
4 describe "search method" do
5 before :each do
6 Friendship.stub_method(:search => true)
7
8 @person = Person.find(:first)
9 @index = Friendship.sphinx_indexes.first
10 end
11
12 it "should raise an error if the required attribute doesn't exist" do
13 @index.stub_method(:attributes => [])
14
15 lambda { @person.friendships.search "test" }.should raise_error(RuntimeError)
16
17 @index.unstub_method(:attributes)
18 end
19
20 it "should add a filter for the attribute into a normal search call" do
21 @person.friendships.search "test"
22
23 Friendship.should have_received(:search).with(
24 "test", :with => {:person_id => @person.id}
25 )
26 end
27 end
28
29 describe "search method for has_many :through" do
30 before :each do
31 Person.stub_method(:search => true)
32
33 @person = Person.find(:first)
34 @index = Person.sphinx_indexes.first
35 end
36
37 it "should raise an error if the required attribute doesn't exist" do
38 @index.stub_method(:attributes => [])
39
40 lambda { @person.friends.search "test" }.should raise_error(RuntimeError)
41
42 @index.unstub_method(:attributes)
43 end
44
45 it "should add a filter for the attribute into a normal search call" do
46 @person.friends.search "test"
47
48 Person.should have_received(:search).with(
49 "test", :with => {:friendly_ids => @person.id}
50 )
51 end
52 end
53end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/search_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/search_spec.rb
new file mode 100644
index 0000000..49c59e1
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record/search_spec.rb
@@ -0,0 +1,107 @@
1require 'spec/spec_helper'
2
3describe "ThinkingSphinx::ActiveRecord::Search" do
4 it "should add search_for_ids to ActiveRecord::Base" do
5 ActiveRecord::Base.methods.should include("search_for_ids")
6 end
7
8 it "should add search_for_ids to ActiveRecord::Base" do
9 ActiveRecord::Base.methods.should include("search")
10 end
11
12 it "should add search_count to ActiveRecord::Base" do
13 ActiveRecord::Base.methods.should include("search_count")
14 end
15
16 it "should add search_for_id to ActiveRecord::Base" do
17 ActiveRecord::Base.methods.should include("search_for_id")
18 end
19
20 describe "search_for_ids method" do
21 before :each do
22 ThinkingSphinx::Search.stub_method(:search_for_ids => true)
23 end
24
25 it "should call ThinkingSphinx::Search#search_for_ids with the class option set" do
26 Person.search_for_ids("search")
27
28 ThinkingSphinx::Search.should have_received(:search_for_ids).with(
29 "search", :class => Person
30 )
31 end
32
33 it "should override the class option" do
34 Person.search_for_ids("search", :class => Friendship)
35
36 ThinkingSphinx::Search.should have_received(:search_for_ids).with(
37 "search", :class => Person
38 )
39 end
40 end
41
42 describe "search method" do
43 before :each do
44 ThinkingSphinx::Search.stub_method(:search => true)
45 end
46
47 it "should call ThinkingSphinx::Search#search with the class option set" do
48 Person.search("search")
49
50 ThinkingSphinx::Search.should have_received(:search).with(
51 "search", :class => Person
52 )
53 end
54
55 it "should override the class option" do
56 Person.search("search", :class => Friendship)
57
58 ThinkingSphinx::Search.should have_received(:search).with(
59 "search", :class => Person
60 )
61 end
62 end
63
64 describe "search_for_id method" do
65 before :each do
66 ThinkingSphinx::Search.stub_method(:search_for_id => true)
67 end
68
69 it "should call ThinkingSphinx::Search#search with the class option set" do
70 Person.search_for_id(10)
71
72 ThinkingSphinx::Search.should have_received(:search_for_id).with(
73 10, :class => Person
74 )
75 end
76
77 it "should override the class option" do
78 Person.search_for_id(10, :class => Friendship)
79
80 ThinkingSphinx::Search.should have_received(:search_for_id).with(
81 10, :class => Person
82 )
83 end
84 end
85
86 describe "search_count method" do
87 before :each do
88 ThinkingSphinx::Search.stub_method(:count => true)
89 end
90
91 it "should call ThinkingSphinx::Search#search with the class option set" do
92 Person.search_count("search")
93
94 ThinkingSphinx::Search.should have_received(:count).with(
95 "search", :class => Person
96 )
97 end
98
99 it "should override the class option" do
100 Person.search_count("search", :class => Friendship)
101
102 ThinkingSphinx::Search.should have_received(:count).with(
103 "search", :class => Person
104 )
105 end
106 end
107end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record_spec.rb
new file mode 100644
index 0000000..053d8c1
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/active_record_spec.rb
@@ -0,0 +1,316 @@
1require 'spec/spec_helper'
2
3describe "ThinkingSphinx::ActiveRecord" do
4 describe "define_index method" do
5 before :each do
6 module TestModule
7 class TestModel < ActiveRecord::Base; end
8 end
9
10 TestModule::TestModel.stub_methods(
11 :before_save => true,
12 :after_commit => true,
13 :after_destroy => true
14 )
15
16 @index = ThinkingSphinx::Index.stub_instance(:delta? => false)
17 ThinkingSphinx::Index.stub_method(:new => @index)
18 end
19
20 after :each do
21 # Remove the class so we can redefine it
22 TestModule.send(:remove_const, :TestModel)
23
24 ThinkingSphinx.indexed_models.delete "TestModule::TestModel"
25 end
26
27 it "should return nil and do nothing if indexes are disabled" do
28 ThinkingSphinx.stub_method(:define_indexes? => false)
29
30 TestModule::TestModel.define_index {}.should be_nil
31 ThinkingSphinx::Index.should_not have_received(:new)
32
33 ThinkingSphinx.unstub_method(:define_indexes?)
34 end
35
36 it "should add a new index to the model" do
37 TestModule::TestModel.define_index do; end
38
39 TestModule::TestModel.sphinx_indexes.length.should == 1
40 end
41
42 it "should add to ThinkingSphinx.indexed_models if the model doesn't already exist in the array" do
43 TestModule::TestModel.define_index do; end
44
45 ThinkingSphinx.indexed_models.should include("TestModule::TestModel")
46 end
47
48 it "shouldn't add to ThinkingSphinx.indexed_models if the model already exists in the array" do
49 TestModule::TestModel.define_index do; end
50
51 ThinkingSphinx.indexed_models.select { |model|
52 model == "TestModule::TestModel"
53 }.length.should == 1
54
55 TestModule::TestModel.define_index do; end
56
57 ThinkingSphinx.indexed_models.select { |model|
58 model == "TestModule::TestModel"
59 }.length.should == 1
60 end
61
62 it "should add before_save and after_commit hooks to the model if delta indexing is enabled" do
63 @index.stub_method(:delta? => true)
64
65 TestModule::TestModel.define_index do; end
66
67 TestModule::TestModel.should have_received(:before_save)
68 TestModule::TestModel.should have_received(:after_commit)
69 end
70
71 it "should not add before_save and after_commit hooks to the model if delta indexing is disabled" do
72 TestModule::TestModel.define_index do; end
73
74 TestModule::TestModel.should_not have_received(:before_save)
75 TestModule::TestModel.should_not have_received(:after_commit)
76 end
77
78 it "should add an after_destroy hook with delta indexing enabled" do
79 @index.stub_method(:delta? => true)
80
81 TestModule::TestModel.define_index do; end
82
83 TestModule::TestModel.should have_received(:after_destroy).with(:toggle_deleted)
84 end
85
86 it "should add an after_destroy hook with delta indexing disabled" do
87 TestModule::TestModel.define_index do; end
88
89 TestModule::TestModel.should have_received(:after_destroy).with(:toggle_deleted)
90 end
91
92 it "should return the new index" do
93 TestModule::TestModel.define_index.should == @index
94 end
95 end
96
97 describe "index methods" do
98 before(:all) do
99 @person = Person.find(:first)
100 end
101
102 describe "in_both_indexes?" do
103 it "should return true if in core and delta indexes" do
104 @person.should_receive(:in_core_index?).and_return(true)
105 @person.should_receive(:in_delta_index?).and_return(true)
106 @person.in_both_indexes?.should be_true
107 end
108
109 it "should return false if in one index and not the other" do
110 @person.should_receive(:in_core_index?).and_return(true)
111 @person.should_receive(:in_delta_index?).and_return(false)
112 @person.in_both_indexes?.should be_false
113 end
114 end
115
116 describe "in_core_index?" do
117 it "should call in_index? with core" do
118 @person.should_receive(:in_index?).with('core')
119 @person.in_core_index?
120 end
121 end
122
123 describe "in_delta_index?" do
124 it "should call in_index? with delta" do
125 @person.should_receive(:in_index?).with('delta')
126 @person.in_delta_index?
127 end
128 end
129
130 describe "in_index?" do
131 it "should return true if in the specified index" do
132 @person.should_receive(:sphinx_document_id).and_return(1)
133 @person.should_receive(:sphinx_index_name).and_return('person_core')
134 Person.should_receive(:search_for_id).with(1, 'person_core').and_return(true)
135
136 @person.in_index?('core').should be_true
137 end
138 end
139 end
140
141 describe "source_of_sphinx_index method" do
142 it "should return self if model defines an index" do
143 Person.source_of_sphinx_index.should == Person
144 end
145
146 it "should return the parent if model inherits an index" do
147 Parent.source_of_sphinx_index.should == Person
148 end
149 end
150
151 describe "to_crc32 method" do
152 it "should return an integer" do
153 Person.to_crc32.should be_a_kind_of(Integer)
154 end
155 end
156
157 describe "to_crc32s method" do
158 it "should return an array" do
159 Person.to_crc32s.should be_a_kind_of(Array)
160 end
161 end
162
163 describe "toggle_deleted method" do
164 before :each do
165 ThinkingSphinx.stub_method(:sphinx_running? => true)
166
167 @configuration = ThinkingSphinx::Configuration.instance
168 @configuration.stub_methods(
169 :address => "an address",
170 :port => 123
171 )
172 @client = Riddle::Client.stub_instance(:update => true)
173 @person = Person.find(:first)
174
175 Riddle::Client.stub_method(:new => @client)
176 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => false) }
177 @person.stub_method(:in_core_index? => true)
178 end
179
180 it "should create a client using the Configuration's address and port" do
181 @person.toggle_deleted
182
183 Riddle::Client.should have_received(:new).with(
184 @configuration.address, @configuration.port
185 )
186 end
187
188 it "should update the core index's deleted flag if in core index" do
189 @person.toggle_deleted
190
191 @client.should have_received(:update).with(
192 "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
193 )
194 end
195
196 it "shouldn't update the core index's deleted flag if the record isn't in it" do
197 @person.stub_method(:in_core_index? => false)
198
199 @person.toggle_deleted
200
201 @client.should_not have_received(:update).with(
202 "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
203 )
204 end
205
206 it "shouldn't attempt to update the deleted flag if sphinx isn't running" do
207 ThinkingSphinx.stub_method(:sphinx_running? => false)
208
209 @person.toggle_deleted
210
211 @person.should_not have_received(:in_core_index?)
212 @client.should_not have_received(:update)
213 end
214
215 it "should update the delta index's deleted flag if delta indexes are enabled and the instance's delta is true" do
216 ThinkingSphinx.stub_method(:deltas_enabled? => true)
217 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
218 @person.delta = true
219
220 @person.toggle_deleted
221
222 @client.should have_received(:update).with(
223 "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
224 )
225 end
226
227 it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is false" do
228 ThinkingSphinx.stub_method(:deltas_enabled? => true)
229 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
230 @person.delta = false
231
232 @person.toggle_deleted
233
234 @client.should_not have_received(:update).with(
235 "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
236 )
237 end
238
239 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
240 ThinkingSphinx.stub_method(:deltas_enabled? => true)
241 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
242 @person.delta = 0
243
244 @person.toggle_deleted
245
246 @client.should_not have_received(:update).with(
247 "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
248 )
249 end
250
251 it "shouldn't update the delta index if delta indexes are disabled" do
252 ThinkingSphinx.stub_method(:deltas_enabled? => true)
253 @person.toggle_deleted
254
255 @client.should_not have_received(:update).with(
256 "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
257 )
258 end
259
260 it "should not update the delta index if delta indexing is disabled" do
261 ThinkingSphinx.stub_method(:deltas_enabled? => false)
262 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
263 @person.delta = true
264
265 @person.toggle_deleted
266
267 @client.should_not have_received(:update).with(
268 "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
269 )
270 end
271
272 it "should not update either index if updates are disabled" do
273 ThinkingSphinx.stub_methods(
274 :updates_enabled? => false,
275 :deltas_enabled => true
276 )
277 Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
278 @person.delta = true
279
280 @person.toggle_deleted
281
282 @client.should_not have_received(:update)
283 end
284 end
285
286 describe "sphinx_indexes in the inheritance chain (STI)" do
287 it "should hand defined indexes on a class down to its child classes" do
288 Child.sphinx_indexes.should include(*Person.sphinx_indexes)
289 end
290
291 it "should allow associations to other STI models" do
292 Child.sphinx_indexes.last.link!
293 sql = Child.sphinx_indexes.last.to_riddle_for_core(0, 0).sql_query
294 sql.gsub!('$start', '0').gsub!('$end', '100')
295 lambda { Child.connection.execute(sql) }.should_not raise_error(ActiveRecord::StatementInvalid)
296 end
297 end
298
299 it "should return the sphinx document id as expected" do
300 person = Person.find(:first)
301 model_count = ThinkingSphinx.indexed_models.length
302 offset = ThinkingSphinx.indexed_models.index("Person")
303
304 (person.id * model_count + offset).should == person.sphinx_document_id
305
306 alpha = Alpha.find(:first)
307 offset = ThinkingSphinx.indexed_models.index("Alpha")
308
309 (alpha.id * model_count + offset).should == alpha.sphinx_document_id
310
311 beta = Beta.find(:first)
312 offset = ThinkingSphinx.indexed_models.index("Beta")
313
314 (beta.id * model_count + offset).should == beta.sphinx_document_id
315 end
316end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/association_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/association_spec.rb
new file mode 100644
index 0000000..4b92a8b
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/association_spec.rb
@@ -0,0 +1,247 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Association do
4 describe "class-level children method" do
5 before :each do
6 @normal_reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
7 :options => {:polymorphic => false}
8 )
9 @normal_association = ThinkingSphinx::Association.stub_instance
10 @poly_reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
11 :options => {:polymorphic => true},
12 :macro => :has_many,
13 :name => "polly",
14 :active_record => "AR"
15 )
16 @non_poly_reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance
17
18 Person.stub_method(:reflect_on_association => @normal_reflection)
19 ThinkingSphinx::Association.stub_methods(
20 :new => @normal_association,
21 :polymorphic_classes => [Person, Person],
22 :casted_options => {:casted => :options}
23 )
24 ::ActiveRecord::Reflection::AssociationReflection.stub_method(
25 :new => @non_poly_reflection
26 )
27 end
28
29 it "should return an empty array if no association exists" do
30 Person.stub_method(:reflect_on_association => nil)
31
32 ThinkingSphinx::Association.children(Person, :assoc).should == []
33 end
34
35 it "should return a single association instance in an array if assocation isn't polymorphic" do
36 ThinkingSphinx::Association.children(Person, :assoc).should == [@normal_association]
37 end
38
39 it "should return multiple association instances for polymorphic associations" do
40 Person.stub_method(:reflect_on_association => @poly_reflection)
41
42 ThinkingSphinx::Association.children(Person, :assoc).should ==
43 [@normal_association, @normal_association]
44 end
45
46 it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
47 Person.stub_method(:reflect_on_association => @poly_reflection)
48
49 ThinkingSphinx::Association.children(Person, :assoc)
50
51 ThinkingSphinx::Association.should have_received(:casted_options).with(
52 Person, @poly_reflection
53 ).twice
54
55 ::ActiveRecord::Reflection::AssociationReflection.should have_received(:new).with(
56 :has_many, :polly_Person, {:casted => :options}, "AR"
57 ).twice
58
59 ThinkingSphinx::Association.should have_received(:new).with(
60 nil, @non_poly_reflection
61 ).twice
62 end
63 end
64
65 describe "instance-level children method" do
66 it "should return the children associations for the given association" do
67 @reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
68 :klass => :klass
69 )
70 @association = ThinkingSphinx::Association.new(nil, @reflection)
71 ThinkingSphinx::Association.stub_method(:children => :result)
72
73 @association.children(:assoc).should == :result
74 ThinkingSphinx::Association.should have_received(:children).with(:klass, :assoc, @association)
75 end
76 end
77
78 describe "join_to method" do
79 before :each do
80 @parent_join = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_instance
81 @join = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_instance
82 @parent = ThinkingSphinx::Association.stub_instance(:join_to => true, :join => nil)
83 @base_join = Object.stub_instance(:joins => [:a, :b, :c])
84
85 ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_method(:new => @join)
86 end
87
88 it "should call the parent's join_to if parent has no join" do
89 @assoc = ThinkingSphinx::Association.new(@parent, :ref)
90
91 @assoc.join_to(@base_join)
92
93 @parent.should have_received(:join_to).with(@base_join)
94 end
95
96 it "should not call the parent's join_to if it already has a join" do
97 @assoc = ThinkingSphinx::Association.new(@parent, :ref)
98 @parent.stub_method(:join => @parent_join)
99
100 @assoc.join_to(@base_join)
101
102 @parent.should_not have_received(:join_to)
103 end
104
105 it "should define the join association with a JoinAssociation instance" do
106 @assoc = ThinkingSphinx::Association.new(@parent, :ref)
107
108 @assoc.join_to(@base_join).should == @join
109 @assoc.join.should == @join
110 end
111 end
112
113 describe "to_sql method" do
114 before :each do
115 @reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
116 :klass => Person
117 )
118 @association = ThinkingSphinx::Association.new(nil, @reflection)
119 @parent = Object.stub_instance(:aliased_table_name => "ALIAS TABLE NAME")
120 @join = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub_instance(
121 :association_join => "full association join SQL",
122 :parent => @parent
123 )
124 @association.join = @join
125 end
126
127 it "should return the join's association join value" do
128 @association.to_sql.should == "full association join SQL"
129 end
130
131 it "should replace ::ts_join_alias:: with the aliased table name" do
132 @join.stub_method(:association_join => "text with ::ts_join_alias:: gone")
133
134 @association.to_sql.should == "text with `ALIAS TABLE NAME` gone"
135 end
136 end
137
138 describe "is_many? method" do
139 before :each do
140 @parent = ThinkingSphinx::Association.stub_instance(
141 :is_many? => :parent_is_many
142 )
143 @reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
144 :macro => :has_many
145 )
146 end
147
148 it "should return true if association is either a has_many or a habtm" do
149 association = ThinkingSphinx::Association.new(@parent, @reflection)
150 association.is_many?.should be_true
151
152 @reflection.stub_method(:macro => :has_and_belongs_to_many)
153 association.is_many?.should be_true
154 end
155
156 it "should return the parent value if not a has many or habtm and there is a parent" do
157 association = ThinkingSphinx::Association.new(@parent, @reflection)
158 @reflection.stub_method(:macro => :belongs_to)
159 association.is_many?.should == :parent_is_many
160 end
161
162 it "should return false if no parent and not a has many or habtm" do
163 association = ThinkingSphinx::Association.new(nil, @reflection)
164 @reflection.stub_method(:macro => :belongs_to)
165 association.is_many?.should be_false
166 end
167 end
168
169 describe "ancestors method" do
170 it "should return an array of associations - including all parents" do
171 parent = ThinkingSphinx::Association.stub_instance(:ancestors => [:all, :ancestors])
172 association = ThinkingSphinx::Association.new(parent, @reflection)
173 association.ancestors.should == [:all, :ancestors, association]
174 end
175 end
176
177 describe "polymorphic_classes method" do
178 it "should return all the polymorphic result types as classes" do
179 Person.connection.stub_method(:select_all => [
180 {"person_type" => "Person"},
181 {"person_type" => "Friendship"}
182 ])
183 ref = Object.stub_instance(
184 :active_record => Person,
185 :options => {:foreign_type => "person_type"}
186 )
187
188 ThinkingSphinx::Association.send(:polymorphic_classes, ref).should == [Person, Friendship]
189 end
190 end
191
192 describe "casted_options method" do
193 before :each do
194 @options = {
195 :foreign_key => "thing_id",
196 :foreign_type => "thing_type",
197 :polymorphic => true
198 }
199 @reflection = ::ActiveRecord::Reflection::AssociationReflection.stub_instance(
200 :options => @options
201 )
202 end
203
204 it "should return a new options set for a specific class" do
205 ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
206 :polymorphic => nil,
207 :class_name => "Person",
208 :foreign_key => "thing_id",
209 :foreign_type => "thing_type",
210 :conditions => "::ts_join_alias::.`thing_type` = 'Person'"
211 }
212 end
213
214 it "should append to existing Array of conditions" do
215 @options[:conditions] = ["first condition"]
216 ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
217 :polymorphic => nil,
218 :class_name => "Person",
219 :foreign_key => "thing_id",
220 :foreign_type => "thing_type",
221 :conditions => ["first condition", "::ts_join_alias::.`thing_type` = 'Person'"]
222 }
223 end
224
225 it "should merge to an existing Hash of conditions" do
226 @options[:conditions] = {"field" => "value"}
227 ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
228 :polymorphic => nil,
229 :class_name => "Person",
230 :foreign_key => "thing_id",
231 :foreign_type => "thing_type",
232 :conditions => {"field" => "value", "thing_type" => "Person"}
233 }
234 end
235
236 it "should append to an existing String of conditions" do
237 @options[:conditions] = "first condition"
238 ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
239 :polymorphic => nil,
240 :class_name => "Person",
241 :foreign_key => "thing_id",
242 :foreign_type => "thing_type",
243 :conditions => "first condition AND ::ts_join_alias::.`thing_type` = 'Person'"
244 }
245 end
246 end
247end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/attribute_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/attribute_spec.rb
new file mode 100644
index 0000000..bbe1ae9
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/attribute_spec.rb
@@ -0,0 +1,227 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Attribute do
4 describe '#initialize' do
5 it 'raises if no columns are provided so that configuration errors are easier to track down' do
6 lambda {
7 ThinkingSphinx::Attribute.new([])
8 }.should raise_error(RuntimeError)
9 end
10
11 it 'raises if an element of the columns param is an integer - as happens when you use id instead of :id - so that configuration errors are easier to track down' do
12 lambda {
13 ThinkingSphinx::Attribute.new([1234])
14 }.should raise_error(RuntimeError)
15 end
16 end
17
18 describe "unique_name method" do
19 before :each do
20 @attribute = ThinkingSphinx::Attribute.new [
21 Object.stub_instance(:__stack => [], :__name => "col_name")
22 ]
23 end
24
25 it "should use the alias if there is one" do
26 @attribute.alias = "alias"
27 @attribute.unique_name.should == "alias"
28 end
29
30 it "should use the alias if there's multiple columns" do
31 @attribute.columns << Object.stub_instance(:__stack => [], :__name => "col_name")
32 @attribute.unique_name.should be_nil
33
34 @attribute.alias = "alias"
35 @attribute.unique_name.should == "alias"
36 end
37
38 it "should use the column name if there's no alias and just one column" do
39 @attribute.unique_name.should == "col_name"
40 end
41 end
42
43 describe "column_with_prefix method" do
44 before :each do
45 @attribute = ThinkingSphinx::Attribute.new [
46 ThinkingSphinx::Index::FauxColumn.new(:col_name)
47 ]
48 @attribute.columns.each { |col| @attribute.associations[col] = [] }
49 @attribute.model = Person
50
51 @first_join = Object.stub_instance(:aliased_table_name => "tabular")
52 @second_join = Object.stub_instance(:aliased_table_name => "data")
53
54 @first_assoc = ThinkingSphinx::Association.stub_instance(
55 :join => @first_join, :has_column? => true
56 )
57 @second_assoc = ThinkingSphinx::Association.stub_instance(
58 :join => @second_join, :has_column? => true
59 )
60 end
61
62 it "should return the column name if the column is a string" do
63 @attribute.columns = [ThinkingSphinx::Index::FauxColumn.new("string")]
64 @attribute.send(:column_with_prefix, @attribute.columns.first).should == "string"
65 end
66
67 it "should return the column with model's table prefix if there's no associations for the column" do
68 @attribute.send(:column_with_prefix, @attribute.columns.first).should == "`people`.`col_name`"
69 end
70
71 it "should return the column with its join table prefix if an association exists" do
72 column = @attribute.columns.first
73 @attribute.associations[column] = [@first_assoc]
74 @attribute.send(:column_with_prefix, column).should == "`tabular`.`col_name`"
75 end
76
77 it "should return multiple columns concatenated if more than one association exists" do
78 column = @attribute.columns.first
79 @attribute.associations[column] = [@first_assoc, @second_assoc]
80 @attribute.send(:column_with_prefix, column).should == "`tabular`.`col_name`, `data`.`col_name`"
81 end
82 end
83
84 describe "is_many? method" do
85 before :each do
86 @assoc_a = Object.stub_instance(:is_many? => true)
87 @assoc_b = Object.stub_instance(:is_many? => true)
88 @assoc_c = Object.stub_instance(:is_many? => true)
89
90 @attribute = ThinkingSphinx::Attribute.new(
91 [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
92 )
93 @attribute.associations = {
94 :a => @assoc_a, :b => @assoc_b, :c => @assoc_c
95 }
96 end
97
98 it "should return true if all associations return true to is_many?" do
99 @attribute.send(:is_many?).should be_true
100 end
101
102 it "should return true if one association returns true to is_many?" do
103 @assoc_b.stub_method(:is_many? => false)
104 @assoc_c.stub_method(:is_many? => false)
105
106 @attribute.send(:is_many?).should be_true
107 end
108
109 it "should return false if all associations return false to is_many?" do
110 @assoc_a.stub_method(:is_many? => false)
111 @assoc_b.stub_method(:is_many? => false)
112 @assoc_c.stub_method(:is_many? => false)
113
114 @attribute.send(:is_many?).should be_false
115 end
116 end
117
118 describe "is_string? method" do
119 before :each do
120 @col_a = ThinkingSphinx::Index::FauxColumn.new("a")
121 @col_b = ThinkingSphinx::Index::FauxColumn.new("b")
122 @col_c = ThinkingSphinx::Index::FauxColumn.new("c")
123
124 @attribute = ThinkingSphinx::Attribute.new(
125 [@col_a, @col_b, @col_c]
126 )
127 end
128
129 it "should return true if all columns return true to is_string?" do
130 @attribute.send(:is_string?).should be_true
131 end
132
133 it "should return false if one column returns true to is_string?" do
134 @col_a.send(:instance_variable_set, :@name, :a)
135 @attribute.send(:is_string?).should be_false
136 end
137
138 it "should return false if all columns return false to is_string?" do
139 @col_a.send(:instance_variable_set, :@name, :a)
140 @col_b.send(:instance_variable_set, :@name, :b)
141 @col_c.send(:instance_variable_set, :@name, :c)
142 @attribute.send(:is_string?).should be_false
143 end
144 end
145
146 describe "type method" do
147 before :each do
148 @column = ThinkingSphinx::Index::FauxColumn.new(:col_name)
149 @attribute = ThinkingSphinx::Attribute.new([@column])
150 @attribute.model = Person
151 @attribute.stub_method(:is_many? => false)
152 end
153
154 it "should return :multi if is_many? is true" do
155 @attribute.stub_method(:is_many? => true)
156 @attribute.send(:type).should == :multi
157 end
158
159 it "should return :string if there's more than one association" do
160 @attribute.associations = {:a => [:assoc], :b => [:assoc]}
161 @attribute.send(:type).should == :string
162 end
163
164 it "should return the column type from the database if not :multi or more than one association" do
165 @column.send(:instance_variable_set, :@name, "birthday")
166 @attribute.send(:type).should == :datetime
167
168 @attribute.send(:instance_variable_set, :@type, nil)
169 @column.send(:instance_variable_set, :@name, "first_name")
170 @attribute.send(:type).should == :string
171
172 @attribute.send(:instance_variable_set, :@type, nil)
173 @column.send(:instance_variable_set, :@name, "id")
174 @attribute.send(:type).should == :integer
175 end
176 end
177
178 describe "all_ints? method" do
179 it "should return true if all columns are integers" do
180 attribute = ThinkingSphinx::Attribute.new(
181 [ ThinkingSphinx::Index::FauxColumn.new(:id),
182 ThinkingSphinx::Index::FauxColumn.new(:team_id) ]
183 )
184 attribute.model = Person
185 attribute.columns.each { |col| attribute.associations[col] = [] }
186
187 attribute.send(:all_ints?).should be_true
188 end
189
190 it "should return false if only some columns are integers" do
191 attribute = ThinkingSphinx::Attribute.new(
192 [ ThinkingSphinx::Index::FauxColumn.new(:id),
193 ThinkingSphinx::Index::FauxColumn.new(:first_name) ]
194 )
195 attribute.model = Person
196 attribute.columns.each { |col| attribute.associations[col] = [] }
197
198 attribute.send(:all_ints?).should be_false
199 end
200
201 it "should return false if no columns are integers" do
202 attribute = ThinkingSphinx::Attribute.new(
203 [ ThinkingSphinx::Index::FauxColumn.new(:first_name),
204 ThinkingSphinx::Index::FauxColumn.new(:last_name) ]
205 )
206 attribute.model = Person
207 attribute.columns.each { |col| attribute.associations[col] = [] }
208
209 attribute.send(:all_ints?).should be_false
210 end
211 end
212
213 describe "with custom queries" do
214 before :each do
215 index = CricketTeam.sphinx_indexes.first
216 @statement = index.to_riddle_for_core(0, 0).sql_attr_multi.first
217 end
218
219 it "should track the query type accordingly" do
220 @statement.should match(/uint tags from query/)
221 end
222
223 it "should include the SQL statement" do
224 @statement.should match(/SELECT cricket_team_id, id FROM tags/)
225 end
226 end
227end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/collection_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/collection_spec.rb
new file mode 100644
index 0000000..b13c769
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/collection_spec.rb
@@ -0,0 +1,14 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Collection do
4 it "should behave like WillPaginate::Collection" do
5 ThinkingSphinx::Collection.instance_methods.should include("previous_page")
6 ThinkingSphinx::Collection.instance_methods.should include("next_page")
7 ThinkingSphinx::Collection.instance_methods.should include("current_page")
8 ThinkingSphinx::Collection.instance_methods.should include("total_pages")
9 ThinkingSphinx::Collection.instance_methods.should include("total_entries")
10 ThinkingSphinx::Collection.instance_methods.should include("offset")
11
12 ThinkingSphinx::Collection.ancestors.should include(Array)
13 end
14end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/configuration_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/configuration_spec.rb
new file mode 100644
index 0000000..12e2775
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/configuration_spec.rb
@@ -0,0 +1,136 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Configuration do
4 describe "environment class method" do
5 before :each do
6 ThinkingSphinx::Configuration.send(:class_variable_set, :@@environment, nil)
7
8 ENV["RAILS_ENV"] = nil
9 end
10
11 it "should use the Merb environment value if set" do
12 unless defined?(Merb)
13 module Merb; end
14 end
15
16 ThinkingSphinx::Configuration.stub_method(:defined? => true)
17 Merb.stub_method(:environment => "merb_production")
18 ThinkingSphinx::Configuration.environment.should == "merb_production"
19
20 Object.send(:remove_const, :Merb)
21 end
22
23 it "should use the Rails environment value if set" do
24 ENV["RAILS_ENV"] = "rails_production"
25 ThinkingSphinx::Configuration.environment.should == "rails_production"
26 end
27
28 it "should default to development" do
29 ThinkingSphinx::Configuration.environment.should == "development"
30 end
31 end
32
33 describe "parse_config method" do
34 before :each do
35 @settings = {
36 "development" => {
37 "config_file" => "tmp/config/development.sphinx.conf",
38 "searchd_log_file" => "searchd_log_file.log",
39 "query_log_file" => "query_log_file.log",
40 "pid_file" => "pid_file.pid",
41 "searchd_file_path" => "searchd/file/path",
42 "address" => "127.0.0.1",
43 "port" => 3333,
44 "min_prefix_len" => 2,
45 "min_infix_len" => 3,
46 "mem_limit" => "128M",
47 "max_matches" => 1001,
48 "morphology" => "stem_ru",
49 "charset_type" => "latin1",
50 "charset_table" => "table",
51 "ignore_chars" => "e"
52 }
53 }
54
55 open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
56 f.write YAML.dump(@settings)
57 end
58 end
59
60 it "should use the accessors to set the configuration values" do
61 config = ThinkingSphinx::Configuration.instance
62 config.send(:parse_config)
63
64 %w(config_file searchd_log_file query_log_file pid_file searchd_file_path
65 address port).each do |key|
66 config.send(key).should == @settings["development"][key]
67 end
68 end
69
70 after :each do
71 FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
72 end
73 end
74
75 describe "initialisation" do
76 it "should have a default bin_path of nothing" do
77 ThinkingSphinx::Configuration.instance.bin_path.should == ""
78 end
79
80 it "should append a / to bin_path if one is supplied" do
81 @settings = {
82 "development" => {
83 "bin_path" => "path/to/somewhere"
84 }
85 }
86
87 open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
88 f.write YAML.dump(@settings)
89 end
90
91 ThinkingSphinx::Configuration.instance.send(:parse_config)
92 ThinkingSphinx::Configuration.instance.bin_path.should match(/\/$/)
93 end
94 end
95
96 it "should insert set index options into the configuration file" do
97 config = ThinkingSphinx::Configuration.instance
98 ThinkingSphinx::Configuration::IndexOptions.each do |option|
99 config.index_options[option.to_sym] = "something"
100 config.build
101
102 file = open(config.config_file) { |f| f.read }
103 file.should match(/#{option}\s+= something/)
104
105 config.index_options[option.to_sym] = nil
106 end
107 end
108
109 it "should insert set source options into the configuration file" do
110 config = ThinkingSphinx::Configuration.instance
111 ThinkingSphinx::Configuration::SourceOptions.each do |option|
112 config.source_options[option.to_sym] = "something"
113 config.build
114
115 file = open(config.config_file) { |f| f.read }
116 file.should match(/#{option}\s+= something/)
117
118 config.source_options[option.to_sym] = nil
119 end
120 end
121
122 it "should set any explicit prefixed or infixed fields" do
123 file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
124 f.read
125 }
126 file.should match(/prefix_fields\s+= city/)
127 file.should match(/infix_fields\s+= state/)
128 end
129
130 it "should not have prefix fields in indexes where nothing is set" do
131 file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
132 f.read
133 }
134 file.should_not match(/index alpha_core\s+\{\s+[^\}]*prefix_fields\s+=[^\}]*\}/m)
135 end
136end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/core/string_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/core/string_spec.rb
new file mode 100644
index 0000000..26f813c
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/core/string_spec.rb
@@ -0,0 +1,9 @@
1require 'spec/spec_helper'
2
3describe String do
4 describe "to_crc32 instance method" do
5 it "should return an integer" do
6 'to_crc32'.to_crc32.should be_a_kind_of(Integer)
7 end
8 end
9end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/field_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/field_spec.rb
new file mode 100644
index 0000000..770f749
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/field_spec.rb
@@ -0,0 +1,145 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Field do
4 describe '#initialize' do
5 it 'raises if no columns are provided so that configuration errors are easier to track down' do
6 lambda {
7 ThinkingSphinx::Field.new([])
8 }.should raise_error(RuntimeError)
9 end
10
11 it 'raises if an element of the columns param is an integer - as happens when you use id instead of :id - so that configuration errors are easier to track down' do
12 lambda {
13 ThinkingSphinx::Field.new([1234])
14 }.should raise_error(RuntimeError)
15 end
16 end
17
18 describe "unique_name method" do
19 before :each do
20 @field = ThinkingSphinx::Field.new [
21 Object.stub_instance(:__stack => [], :__name => "col_name")
22 ]
23 end
24
25 it "should use the alias if there is one" do
26 @field.alias = "alias"
27 @field.unique_name.should == "alias"
28 end
29
30 it "should use the alias if there's multiple columns" do
31 @field.columns << Object.stub_instance(:__stack => [], :__name => "col_name")
32 @field.unique_name.should be_nil
33
34 @field.alias = "alias"
35 @field.unique_name.should == "alias"
36 end
37
38 it "should use the column name if there's no alias and just one column" do
39 @field.unique_name.should == "col_name"
40 end
41 end
42
43 describe "prefixes method" do
44 it "should default to false" do
45 @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])])
46 @field.prefixes.should be_false
47 end
48
49 it "should be true if the corresponding option is set" do
50 @field = ThinkingSphinx::Field.new(
51 [Object.stub_instance(:__stack => [])], :prefixes => true
52 )
53 @field.prefixes.should be_true
54 end
55 end
56
57 describe "infixes method" do
58 it "should default to false" do
59 @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])])
60 @field.infixes.should be_false
61 end
62
63 it "should be true if the corresponding option is set" do
64 @field = ThinkingSphinx::Field.new(
65 [Object.stub_instance(:__stack => [])], :infixes => true
66 )
67 @field.infixes.should be_true
68 end
69 end
70
71 describe "column_with_prefix method" do
72 before :each do
73 @field = ThinkingSphinx::Field.new [
74 ThinkingSphinx::Index::FauxColumn.new(:col_name)
75 ]
76 @field.columns.each { |col| @field.associations[col] = [] }
77 @field.model = Person
78
79 @first_join = Object.stub_instance(:aliased_table_name => "tabular")
80 @second_join = Object.stub_instance(:aliased_table_name => "data")
81
82 @first_assoc = ThinkingSphinx::Association.stub_instance(
83 :join => @first_join, :has_column? => true
84 )
85 @second_assoc = ThinkingSphinx::Association.stub_instance(
86 :join => @second_join, :has_column? => true
87 )
88 end
89
90 it "should return the column name if the column is a string" do
91 @field.columns = [ThinkingSphinx::Index::FauxColumn.new("string")]
92 @field.send(:column_with_prefix, @field.columns.first).should == "string"
93 end
94
95 it "should return the column with model's table prefix if there's no associations for the column" do
96 @field.send(:column_with_prefix, @field.columns.first).should == "`people`.`col_name`"
97 end
98
99 it "should return the column with its join table prefix if an association exists" do
100 column = @field.columns.first
101 @field.associations[column] = [@first_assoc]
102 @field.send(:column_with_prefix, column).should == "`tabular`.`col_name`"
103 end
104
105 it "should return multiple columns concatenated if more than one association exists" do
106 column = @field.columns.first
107 @field.associations[column] = [@first_assoc, @second_assoc]
108 @field.send(:column_with_prefix, column).should == "`tabular`.`col_name`, `data`.`col_name`"
109 end
110 end
111
112 describe "is_many? method" do
113 before :each do
114 @assoc_a = Object.stub_instance(:is_many? => true)
115 @assoc_b = Object.stub_instance(:is_many? => true)
116 @assoc_c = Object.stub_instance(:is_many? => true)
117
118 @field = ThinkingSphinx::Field.new(
119 [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
120 )
121 @field.associations = {
122 :a => @assoc_a, :b => @assoc_b, :c => @assoc_c
123 }
124 end
125
126 it "should return true if all associations return true to is_many?" do
127 @field.send(:is_many?).should be_true
128 end
129
130 it "should return true if one association returns true to is_many?" do
131 @assoc_b.stub_method(:is_many? => false)
132 @assoc_c.stub_method(:is_many? => false)
133
134 @field.send(:is_many?).should be_true
135 end
136
137 it "should return false if all associations return false to is_many?" do
138 @assoc_a.stub_method(:is_many? => false)
139 @assoc_b.stub_method(:is_many? => false)
140 @assoc_c.stub_method(:is_many? => false)
141
142 @field.send(:is_many?).should be_false
143 end
144 end
145end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/builder_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/builder_spec.rb
new file mode 100644
index 0000000..6d1d25d
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/builder_spec.rb
@@ -0,0 +1,5 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Index::Builder do
4 #
5end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/faux_column_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/faux_column_spec.rb
new file mode 100644
index 0000000..ca76a34
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index/faux_column_spec.rb
@@ -0,0 +1,30 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Index::FauxColumn do
4 describe "coerce class method" do
5 before :each do
6 @column = ThinkingSphinx::Index::FauxColumn.stub_instance
7 ThinkingSphinx::Index::FauxColumn.stub_method(:new => @column)
8 end
9
10 it "should return a single faux column if passed a string" do
11 ThinkingSphinx::Index::FauxColumn.coerce("string").should == @column
12 end
13
14 it "should return a single faux column if passed a symbol" do
15 ThinkingSphinx::Index::FauxColumn.coerce(:string).should == @column
16 end
17
18 it "should return an array of faux columns if passed an array of strings" do
19 ThinkingSphinx::Index::FauxColumn.coerce(["one", "two"]).should == [
20 @column, @column
21 ]
22 end
23
24 it "should return an array of faux columns if passed an array of symbols" do
25 ThinkingSphinx::Index::FauxColumn.coerce([:one, :two]).should == [
26 @column, @column
27 ]
28 end
29 end
30end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index_spec.rb
new file mode 100644
index 0000000..fe1cba0
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/index_spec.rb
@@ -0,0 +1,144 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::Index do
4 describe "generated sql_query" do
5 it "should include explicit groupings if requested" do
6 @index = ThinkingSphinx::Index.new(Person)
7
8 @index.groupings << "custom_sql"
9 @index.to_riddle_for_core(0, 0).sql_query.should match(/GROUP BY.+custom_sql/)
10 end
11 end
12
13 describe "prefix_fields method" do
14 before :each do
15 @index = ThinkingSphinx::Index.new(Person)
16
17 @field_a = ThinkingSphinx::Field.stub_instance(:prefixes => true)
18 @field_b = ThinkingSphinx::Field.stub_instance(:prefixes => false)
19 @field_c = ThinkingSphinx::Field.stub_instance(:prefixes => true)
20
21 @index.fields = [@field_a, @field_b, @field_c]
22 end
23
24 it "should return fields that are flagged as prefixed" do
25 @index.prefix_fields.should include(@field_a)
26 @index.prefix_fields.should include(@field_c)
27 end
28
29 it "should not return fields that aren't flagged as prefixed" do
30 @index.prefix_fields.should_not include(@field_b)
31 end
32 end
33
34 describe "infix_fields method" do
35 before :each do
36 @index = ThinkingSphinx::Index.new(Person)
37
38 @field_a = ThinkingSphinx::Field.stub_instance(:infixes => true)
39 @field_b = ThinkingSphinx::Field.stub_instance(:infixes => false)
40 @field_c = ThinkingSphinx::Field.stub_instance(:infixes => true)
41
42 @index.fields = [@field_a, @field_b, @field_c]
43 end
44
45 it "should return fields that are flagged as infixed" do
46 @index.infix_fields.should include(@field_a)
47 @index.infix_fields.should include(@field_c)
48 end
49
50 it "should not return fields that aren't flagged as infixed" do
51 @index.infix_fields.should_not include(@field_b)
52 end
53 end
54
55 describe "multi-value attribute as ranged-query with has-many association" do
56 before :each do
57 @index = ThinkingSphinx::Index.new(Person) do
58 has tags(:id), :as => :tag_ids, :source => :ranged_query
59 end
60 @index.link!
61
62 @sql = @index.to_riddle_for_core(0, 0).sql_query
63 end
64
65 it "should not include attribute in select-clause sql_query" do
66 @sql.should_not match(/tag_ids/)
67 @sql.should_not match(/GROUP_CONCAT\(`tags`.`id`/)
68 end
69
70 it "should not join with association table" do
71 @sql.should_not match(/LEFT OUTER JOIN `tags`/)
72 end
73
74 it "should include sql_attr_multi as ranged-query" do
75 attribute = @index.send(:attributes).first
76 attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
77
78 declaration, query, range_query = attribute.send(:config_value).split('; ')
79 declaration.should == "uint tag_ids from ranged-query"
80 query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
81 range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
82 end
83 end
84
85 describe "multi-value attribute as ranged-query with has-many-through association" do
86 before :each do
87 @index = ThinkingSphinx::Index.new(Person) do
88 has football_teams(:id), :as => :football_teams_ids, :source => :ranged_query
89 end
90 @index.link!
91
92 @sql = @index.to_riddle_for_core(0, 0).sql_query
93 end
94
95 it "should not include attribute in select-clause sql_query" do
96 @sql.should_not match(/football_teams_ids/)
97 @sql.should_not match(/GROUP_CONCAT\(`tags`.`football_team_id`/)
98 end
99
100 it "should not join with association table" do
101 @sql.should_not match(/LEFT OUTER JOIN `tags`/)
102 end
103
104 it "should include sql_attr_multi as ranged-query" do
105 attribute = @index.send(:attributes).first
106 attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
107
108 declaration, query, range_query = attribute.send(:config_value).split('; ')
109 declaration.should == "uint football_teams_ids from ranged-query"
110 query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_teams_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
111 range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
112 end
113 end
114
115 describe "multi-value attribute as ranged-query with has-many-through association and foreign_key" do
116 before :each do
117 @index = ThinkingSphinx::Index.new(Person) do
118 has friends(:id), :as => :friend_ids, :source => :ranged_query
119 end
120 @index.link!
121
122 @sql = @index.to_riddle_for_core(0, 0).sql_query
123 end
124
125 it "should not include attribute in select-clause sql_query" do
126 @sql.should_not match(/friend_ids/)
127 @sql.should_not match(/GROUP_CONCAT\(`friendships`.`friend_id`/)
128 end
129
130 it "should not join with association table" do
131 @sql.should_not match(/LEFT OUTER JOIN `friendships`/)
132 end
133
134 it "should include sql_attr_multi as ranged-query" do
135 attribute = @index.send(:attributes).first
136 attribute.send(:type_to_config).to_s.should == "sql_attr_multi"
137
138 declaration, query, range_query = attribute.send(:config_value).split('; ')
139 declaration.should == "uint friend_ids from ranged-query"
140 query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
141 range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
142 end
143 end
144end \ No newline at end of file
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/rails_additions_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/rails_additions_spec.rb
new file mode 100644
index 0000000..6453812
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/rails_additions_spec.rb
@@ -0,0 +1,183 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx::HashExcept do
4 before(:each) do
5 @hash = { :number => 20, :letter => 'b', :shape => 'rectangle' }
6 end
7
8 describe "except method" do
9 it "returns a hash without the specified keys" do
10 new_hash = @hash.except(:number)
11 new_hash.should_not have_key(:number)
12 end
13 end
14
15 describe "except! method" do
16 it "modifies hash removing specified keys" do
17 @hash.except!(:number)
18 @hash.should_not have_key(:number)
19 end
20 end
21
22 describe "extends Hash" do
23 it 'with except' do
24 Hash.instance_methods.include?('except').should be_true
25 end
26
27 it 'with except!' do
28 Hash.instance_methods.include?('except!').should be_true
29 end
30 end
31end
32
33describe ThinkingSphinx::ArrayExtractOptions do
34 describe 'extract_options! method' do
35 it 'returns a hash' do
36 array = []
37 array.extract_options!.should be_kind_of(Hash)
38 end
39
40 it 'returns the last option if it is a hash' do
41 array = ['a', 'b', {:c => 'd'}]
42 array.extract_options!.should == {:c => 'd'}
43 end
44 end
45
46 describe "extends Array" do
47 it 'with extract_options!' do
48 Array.instance_methods.include?('extract_options!').should be_true
49 end
50 end
51end
52
53describe ThinkingSphinx::AbstractQuotedTableName do
54 describe 'quote_table_name method' do
55 it 'calls quote_column_name' do
56 adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql')
57 adapter.should_receive(:quote_column_name).with('messages')
58 adapter.quote_table_name('messages')
59 end
60 end
61
62 describe "extends ActiveRecord::ConnectionAdapters::AbstractAdapter" do
63 it 'with quote_table_name' do
64 ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.include?('quote_table_name').should be_true
65 end
66 end
67end
68
69describe ThinkingSphinx::MysqlQuotedTableName do
70 describe "quote_table_name method" do
71 it 'correctly quotes' do
72 adapter = ActiveRecord::Base.connection
73 adapter.quote_table_name('thinking_sphinx.messages').should == "`thinking_sphinx`.`messages`"
74 end
75 end
76
77 describe "extends ActiveRecord::ConnectionAdapters::MysqlAdapter" do
78 it 'with quote_table_name' do
79 adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
80 ActiveRecord::ConnectionAdapters.const_get(adapter).instance_methods.include?("quote_table_name").should be_true
81 end
82 end
83end
84
85describe ThinkingSphinx::ActiveRecordQuotedName do
86 describe "quoted_table_name method" do
87 it 'returns table name wrappd in quotes' do
88 Person.quoted_table_name.should == '`people`'
89 end
90 end
91
92 describe "extends ActiveRecord::Base" do
93 it 'with quoted_table_name' do
94 ActiveRecord::Base.respond_to?("quoted_table_name").should be_true
95 end
96 end
97end
98
99describe ThinkingSphinx::ActiveRecordStoreFullSTIClass do
100 describe "store_full_sti_class method" do
101 it 'returns false' do
102 Person.store_full_sti_class.should be_false
103 end
104 end
105
106 describe "extends ActiveRecord::Base" do
107 it 'with store_full_sti_class' do
108 ActiveRecord::Base.respond_to?(:store_full_sti_class).should be_true
109 end
110 end
111end
112
113class TestModel
114 @@squares = 89
115 @@circles = 43
116
117 def number_of_polygons
118 @@polygons
119 end
120end
121
122describe ThinkingSphinx::ClassAttributeMethods do
123 describe "cattr_reader method" do
124 it 'creates getters' do
125 TestModel.cattr_reader :herbivores
126 test_model = TestModel.new
127 test_model.respond_to?(:herbivores).should be_true
128 end
129
130 it 'sets the initial value to nil' do
131 TestModel.cattr_reader :carnivores
132 test_model = TestModel.new
133 test_model.carnivores.should be_nil
134 end
135
136 it 'does not override an existing definition' do
137 TestModel.cattr_reader :squares
138 test_model = TestModel.new
139 test_model.squares.should == 89
140 end
141 end
142
143 describe "cattr_writer method" do
144 it 'creates setters' do
145 TestModel.cattr_writer :herbivores
146 test_model = TestModel.new
147 test_model.respond_to?(:herbivores=).should be_true
148 end
149
150 it 'does not override an existing definition' do
151 TestModel.cattr_writer :polygons
152 test_model = TestModel.new
153 test_model.polygons = 100
154 test_model.number_of_polygons.should == 100
155 end
156 end
157
158 describe "cattr_accessor method" do
159 it 'calls cattr_reader' do
160 Class.should_receive(:cattr_reader).with('polygons')
161 Class.cattr_accessor('polygons')
162 end
163
164 it 'calls cattr_writer' do
165 Class.should_receive(:cattr_writer).with('polygons')
166 Class.cattr_accessor('polygons')
167 end
168 end
169
170 describe "extends Class" do
171 it 'with cattr_reader' do
172 Class.respond_to?('cattr_reader').should be_true
173 end
174
175 it 'with cattr_writer' do
176 Class.respond_to?('cattr_writer').should be_true
177 end
178
179 it 'with cattr_accessor' do
180 Class.respond_to?('cattr_accessor').should be_true
181 end
182 end
183end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/search_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/search_spec.rb
new file mode 100644
index 0000000..dd85138
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx/search_spec.rb
@@ -0,0 +1,59 @@
1require 'spec/spec_helper'
2require 'will_paginate/collection'
3
4describe ThinkingSphinx::Search do
5 describe "search method" do
6 before :each do
7 @client = Riddle::Client.stub_instance(
8 :filters => [],
9 :filters= => true,
10 :id_range= => true,
11 :sort_mode => :asc,
12 :limit => 5,
13 :offset= => 0,
14 :sort_mode= => true,
15 :query => {
16 :matches => [],
17 :total => 50
18 }
19 )
20
21 ThinkingSphinx::Search.stub_methods(
22 :client_from_options => @client,
23 :search_conditions => ["", []]
24 )
25 end
26
27 describe ":star option" do
28
29 it "should not apply by default" do
30 ThinkingSphinx::Search.search "foo bar"
31 @client.should have_received(:query).with("foo bar")
32 end
33
34 it "should apply when passed, and handle full extended syntax" do
35 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)}
36 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*)}
37 ThinkingSphinx::Search.search input, :star => true
38 @client.should have_received(:query).with(expected)
39 end
40
41 it "should default to /\w+/ as token" do
42 ThinkingSphinx::Search.search "foo@bar.com", :star => true
43 @client.should have_received(:query).with("*foo*@*bar*.*com*")
44 end
45
46 it "should honour custom token" do
47 ThinkingSphinx::Search.search "foo@bar.com -foo-bar", :star => /[\w@.-]+/u
48 @client.should have_received(:query).with("*foo@bar.com* -*foo-bar*")
49 end
50
51 end
52 end
53end
54
55describe ThinkingSphinx::Search, "playing nice with Search model" do
56 it "should not conflict with models called Search" do
57 lambda { Search.find(:all) }.should_not raise_error
58 end
59end
diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb
new file mode 100644
index 0000000..375e158
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb
@@ -0,0 +1,133 @@
1require 'spec/spec_helper'
2
3describe ThinkingSphinx do
4 it "should define indexes by default" do
5 ThinkingSphinx.define_indexes?.should be_true
6 end
7
8 it "should disable index definition" do
9 ThinkingSphinx.define_indexes = false
10 ThinkingSphinx.define_indexes?.should be_false
11 end
12
13 it "should enable index definition" do
14 ThinkingSphinx.define_indexes = false
15 ThinkingSphinx.define_indexes?.should be_false
16 ThinkingSphinx.define_indexes = true
17 ThinkingSphinx.define_indexes?.should be_true
18 end
19
20 it "should index deltas by default" do
21 ThinkingSphinx.deltas_enabled = nil
22 ThinkingSphinx.deltas_enabled?.should be_true
23 end
24
25 it "should disable delta indexing" do
26 ThinkingSphinx.deltas_enabled = false
27 ThinkingSphinx.deltas_enabled?.should be_false
28 end
29
30 it "should enable delta indexing" do
31 ThinkingSphinx.deltas_enabled = false
32 ThinkingSphinx.deltas_enabled?.should be_false
33 ThinkingSphinx.deltas_enabled = true
34 ThinkingSphinx.deltas_enabled?.should be_true
35 end
36
37 it "should update indexes by default" do
38 ThinkingSphinx.updates_enabled = nil
39 ThinkingSphinx.updates_enabled?.should be_true
40 end
41
42 it "should disable index updating" do
43 ThinkingSphinx.updates_enabled = false
44 ThinkingSphinx.updates_enabled?.should be_false
45 end
46
47 it "should enable index updating" do
48 ThinkingSphinx.updates_enabled = false
49 ThinkingSphinx.updates_enabled?.should be_false
50 ThinkingSphinx.updates_enabled = true
51 ThinkingSphinx.updates_enabled?.should be_true
52 end
53
54 describe "use_group_by_shortcut? method" do
55 before :each do
56 adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
57 unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
58 pending "No MySQL"
59 return
60 end
61
62 @connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
63 :select_all => true,
64 :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
65 )
66 ::ActiveRecord::Base.stub_method(
67 :connection => @connection
68 )
69 end
70
71 it "should return true if no ONLY_FULL_GROUP_BY" do
72 @connection.stub_method(
73 :select_all => {:a => "OTHER SETTINGS"}
74 )
75
76 ThinkingSphinx.use_group_by_shortcut?.should be_true
77 end
78
79 it "should return true if NULL value" do
80 @connection.stub_method(
81 :select_all => {:a => nil}
82 )
83
84 ThinkingSphinx.use_group_by_shortcut?.should be_true
85 end
86
87 it "should return false if ONLY_FULL_GROUP_BY is set" do
88 @connection.stub_method(
89 :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
90 )
91
92 ThinkingSphinx.use_group_by_shortcut?.should be_false
93 end
94
95 it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
96 @connection.stub_method(
97 :select_all => {
98 :a => "OTHER SETTINGS",
99 :b => "ONLY_FULL_GROUP_BY"
100 }
101 )
102
103 ThinkingSphinx.use_group_by_shortcut?.should be_false
104 end
105
106 describe "if not using MySQL" do
107 before :each do
108 adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :PostgreSQLAdapter
109 unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
110 pending "No PostgreSQL"
111 return
112 end
113 @connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
114 :select_all => true,
115 :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
116 )
117 ::ActiveRecord::Base.stub_method(
118 :connection => @connection
119 )
120 end
121
122 it "should return false" do
123 ThinkingSphinx.use_group_by_shortcut?.should be_false
124 end
125
126 it "should not call select_all" do
127 ThinkingSphinx.use_group_by_shortcut?
128
129 @connection.should_not have_received(:select_all)
130 end
131 end
132 end
133end