thinking-sphinx 1.5.0 → 2.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +15 -48
- data/VERSION +1 -0
- data/features/attribute_transformation.feature +7 -7
- data/features/attribute_updates.feature +16 -18
- data/features/deleting_instances.feature +13 -16
- data/features/excerpts.feature +0 -8
- data/features/facets.feature +19 -25
- data/features/handling_edits.feature +20 -25
- data/features/searching_across_models.feature +1 -1
- data/features/searching_by_index.feature +5 -6
- data/features/searching_by_model.feature +29 -29
- data/features/sphinx_scopes.feature +0 -26
- data/features/step_definitions/common_steps.rb +6 -18
- data/features/step_definitions/scope_steps.rb +0 -4
- data/features/step_definitions/search_steps.rb +4 -9
- data/features/support/env.rb +10 -3
- data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -8
- data/features/thinking_sphinx/db/fixtures/cats.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/dogs.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/foxes.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/people.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/posts.rb +1 -5
- data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -1
- data/features/thinking_sphinx/models/alpha.rb +0 -1
- data/features/thinking_sphinx/models/beta.rb +0 -5
- data/features/thinking_sphinx/models/developer.rb +1 -6
- data/features/thinking_sphinx/models/music.rb +1 -3
- data/features/thinking_sphinx/models/person.rb +1 -2
- data/features/thinking_sphinx/models/post.rb +0 -1
- data/lib/cucumber/thinking_sphinx/external_world.rb +4 -8
- data/lib/cucumber/thinking_sphinx/internal_world.rb +27 -36
- data/lib/thinking_sphinx.rb +60 -132
- data/lib/thinking_sphinx/active_record.rb +98 -124
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +13 -17
- data/lib/thinking_sphinx/active_record/delta.rb +15 -21
- data/lib/thinking_sphinx/active_record/has_many_association.rb +23 -16
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -18
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +15 -63
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -4
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +24 -65
- data/lib/thinking_sphinx/association.rb +11 -36
- data/lib/thinking_sphinx/attribute.rb +85 -92
- data/lib/thinking_sphinx/auto_version.rb +3 -21
- data/lib/thinking_sphinx/class_facet.rb +3 -8
- data/lib/thinking_sphinx/configuration.rb +58 -114
- data/lib/thinking_sphinx/context.rb +20 -22
- data/lib/thinking_sphinx/core/array.rb +13 -0
- data/lib/thinking_sphinx/deltas.rb +0 -2
- data/lib/thinking_sphinx/deltas/default_delta.rb +22 -18
- data/lib/thinking_sphinx/deploy/capistrano.rb +31 -30
- data/lib/thinking_sphinx/excerpter.rb +1 -2
- data/lib/thinking_sphinx/facet.rb +35 -45
- data/lib/thinking_sphinx/facet_search.rb +24 -58
- data/lib/thinking_sphinx/field.rb +0 -18
- data/lib/thinking_sphinx/index.rb +36 -38
- data/lib/thinking_sphinx/index/builder.rb +59 -74
- data/lib/thinking_sphinx/property.rb +45 -66
- data/lib/thinking_sphinx/railtie.rb +35 -0
- data/lib/thinking_sphinx/search.rb +250 -506
- data/lib/thinking_sphinx/source.rb +31 -50
- data/lib/thinking_sphinx/source/internal_properties.rb +3 -8
- data/lib/thinking_sphinx/source/sql.rb +31 -71
- data/lib/thinking_sphinx/tasks.rb +27 -48
- data/spec/thinking_sphinx/active_record/delta_spec.rb +41 -36
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -96
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record_spec.rb +169 -140
- data/spec/thinking_sphinx/association_spec.rb +2 -20
- data/spec/thinking_sphinx/attribute_spec.rb +97 -101
- data/spec/thinking_sphinx/auto_version_spec.rb +11 -75
- data/spec/thinking_sphinx/configuration_spec.rb +62 -63
- data/spec/thinking_sphinx/context_spec.rb +66 -66
- data/spec/thinking_sphinx/facet_search_spec.rb +99 -99
- data/spec/thinking_sphinx/facet_spec.rb +4 -30
- data/spec/thinking_sphinx/field_spec.rb +3 -17
- data/spec/thinking_sphinx/index/builder_spec.rb +132 -169
- data/spec/thinking_sphinx/index_spec.rb +39 -45
- data/spec/thinking_sphinx/search_methods_spec.rb +33 -37
- data/spec/thinking_sphinx/search_spec.rb +269 -491
- data/spec/thinking_sphinx/source_spec.rb +48 -62
- data/spec/thinking_sphinx_spec.rb +49 -49
- data/tasks/distribution.rb +46 -0
- data/tasks/testing.rb +74 -0
- metadata +123 -199
- data/features/field_sorting.feature +0 -18
- data/features/thinking_sphinx/db/.gitignore +0 -1
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
- data/features/thinking_sphinx/models/andrew.rb +0 -17
- data/lib/thinking-sphinx.rb +0 -1
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
- data/lib/thinking_sphinx/bundled_search.rb +0 -40
- data/lib/thinking_sphinx/connection.rb +0 -71
- data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
- data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
- data/lib/thinking_sphinx/rails_additions.rb +0 -181
- data/spec/fixtures/data.sql +0 -32
- data/spec/fixtures/database.yml.default +0 -3
- data/spec/fixtures/models.rb +0 -161
- data/spec/fixtures/structure.sql +0 -146
- data/spec/spec_helper.rb +0 -54
- data/spec/sphinx_helper.rb +0 -67
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
- data/spec/thinking_sphinx/connection_spec.rb +0 -77
- data/spec/thinking_sphinx/rails_additions_spec.rb +0 -203
|
@@ -5,36 +5,36 @@ describe ThinkingSphinx::Source do
|
|
|
5
5
|
@index = ThinkingSphinx::Index.new(Person)
|
|
6
6
|
@source = ThinkingSphinx::Source.new(@index, :sql_range_step => 1000)
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
describe '#initialize' do
|
|
10
10
|
it "should store the current connection details" do
|
|
11
11
|
config = Person.connection.instance_variable_get(:@config)
|
|
12
12
|
@source.database_configuration.should == config
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
it "should generate the name from the model" do
|
|
17
17
|
@source.name.should == "person"
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
it "should handle namespaced models for name generation" do
|
|
21
21
|
index = ThinkingSphinx::Index.new(Admin::Person)
|
|
22
22
|
source = ThinkingSphinx::Source.new(index)
|
|
23
23
|
source.name.should == "admin_person"
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
describe "#to_riddle_for_core" do
|
|
27
27
|
before :each do
|
|
28
28
|
config = ThinkingSphinx::Configuration.instance
|
|
29
29
|
config.source_options[:sql_ranged_throttle] = 100
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
ThinkingSphinx::Field.new(
|
|
32
32
|
@source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
|
|
33
33
|
)
|
|
34
34
|
ThinkingSphinx::Field.new(
|
|
35
35
|
@source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
|
|
36
36
|
)
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
ThinkingSphinx::Attribute.new(
|
|
39
39
|
@source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
|
|
40
40
|
)
|
|
@@ -48,35 +48,31 @@ describe ThinkingSphinx::Source do
|
|
|
48
48
|
@source, ThinkingSphinx::Index::FauxColumn.new(:contacts, :id),
|
|
49
49
|
:as => :contact_ids, :source => :query
|
|
50
50
|
)
|
|
51
|
-
|
|
52
|
-
@source, ThinkingSphinx::Index::FauxColumn.new(:source, :id),
|
|
53
|
-
:as => :source_id, :type => :integer
|
|
54
|
-
)
|
|
55
|
-
|
|
51
|
+
|
|
56
52
|
ThinkingSphinx::Join.new(
|
|
57
53
|
@source, ThinkingSphinx::Index::FauxColumn.new(:links)
|
|
58
54
|
)
|
|
59
|
-
|
|
55
|
+
|
|
60
56
|
@source.conditions << "`birthday` <= NOW()"
|
|
61
57
|
@source.groupings << "`first_name`"
|
|
62
|
-
|
|
58
|
+
|
|
63
59
|
@index.local_options[:group_concat_max_len] = 1024
|
|
64
|
-
|
|
60
|
+
|
|
65
61
|
@riddle = @source.to_riddle_for_core(1, 0)
|
|
66
62
|
end
|
|
67
|
-
|
|
63
|
+
|
|
68
64
|
it "should generate a Riddle Source object" do
|
|
69
65
|
@riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
|
|
70
66
|
end
|
|
71
|
-
|
|
67
|
+
|
|
72
68
|
it "should use the index and name its own name" do
|
|
73
69
|
@riddle.name.should == "person_core_0"
|
|
74
70
|
end
|
|
75
|
-
|
|
71
|
+
|
|
76
72
|
it "should use the model's database connection to determine type" do
|
|
77
73
|
@riddle.type.should == "mysql"
|
|
78
74
|
end
|
|
79
|
-
|
|
75
|
+
|
|
80
76
|
it "should match the model's database settings" do
|
|
81
77
|
config = Person.connection.instance_variable_get(:@config)
|
|
82
78
|
@riddle.sql_db.should == config[:database]
|
|
@@ -85,128 +81,118 @@ describe ThinkingSphinx::Source do
|
|
|
85
81
|
@riddle.sql_host.should == config[:host]
|
|
86
82
|
@riddle.sql_port.should == config[:port]
|
|
87
83
|
@riddle.sql_sock.should == config[:socket]
|
|
88
|
-
|
|
89
|
-
@riddle.mysql_ssl_ca.should == config[:sslca]
|
|
90
|
-
@riddle.mysql_ssl_cert.should == config[:sslcert]
|
|
91
|
-
@riddle.mysql_ssl_key.should == config[:sslkey]
|
|
92
84
|
end
|
|
93
|
-
|
|
94
|
-
it "should use a
|
|
85
|
+
|
|
86
|
+
it "should use a default username of root if nothing else is provided" do
|
|
95
87
|
Person.connection.stub!(:instance_variable_get => {
|
|
96
88
|
:user => nil,
|
|
97
89
|
:username => nil
|
|
98
90
|
})
|
|
99
91
|
@source = ThinkingSphinx::Source.new(@index)
|
|
100
|
-
|
|
92
|
+
|
|
101
93
|
riddle = @source.to_riddle_for_core(1, 0)
|
|
102
|
-
riddle.sql_user.should ==
|
|
94
|
+
riddle.sql_user.should == 'root'
|
|
103
95
|
end
|
|
104
|
-
|
|
96
|
+
|
|
105
97
|
it "should assign attributes" do
|
|
106
98
|
# 3 internal attributes plus the one requested
|
|
107
99
|
@riddle.sql_attr_uint.length.should == 4
|
|
108
100
|
@riddle.sql_attr_uint.last.should == :internal_id
|
|
109
|
-
|
|
101
|
+
|
|
110
102
|
@riddle.sql_attr_timestamp.length.should == 1
|
|
111
103
|
@riddle.sql_attr_timestamp.first.should == :birthday
|
|
112
104
|
end
|
|
113
|
-
|
|
114
|
-
it "should not include an attribute definition for polymorphic references without data" do
|
|
115
|
-
@riddle.sql_attr_uint.select { |uint|
|
|
116
|
-
uint == :source_id
|
|
117
|
-
}.should be_empty
|
|
118
|
-
end
|
|
119
|
-
|
|
105
|
+
|
|
120
106
|
it "should set Sphinx Source options" do
|
|
121
107
|
@riddle.sql_range_step.should == 1000
|
|
122
108
|
@riddle.sql_ranged_throttle.should == 100
|
|
123
109
|
end
|
|
124
|
-
|
|
110
|
+
|
|
125
111
|
describe "#sql_query" do
|
|
126
112
|
before :each do
|
|
127
113
|
@query = @riddle.sql_query
|
|
128
114
|
end
|
|
129
|
-
|
|
115
|
+
|
|
130
116
|
it "should select data from the model table" do
|
|
131
|
-
@query.should match(/FROM
|
|
117
|
+
@query.should match(/FROM\s+`people`/)
|
|
132
118
|
end
|
|
133
|
-
|
|
119
|
+
|
|
134
120
|
it "should select each of the fields" do
|
|
135
121
|
@query.should match(/`first_name`.+FROM/)
|
|
136
122
|
@query.should match(/`last_name`.+FROM/)
|
|
137
123
|
end
|
|
138
|
-
|
|
124
|
+
|
|
139
125
|
it "should select each of the attributes" do
|
|
140
126
|
@query.should match(/`id` AS `internal_id`.+FROM/)
|
|
141
127
|
@query.should match(/`birthday`.+FROM/)
|
|
142
128
|
@query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
|
|
143
129
|
end
|
|
144
|
-
|
|
130
|
+
|
|
145
131
|
it "should not match the sourced MVA attribute" do
|
|
146
132
|
@query.should_not match(/contact_ids/)
|
|
147
133
|
end
|
|
148
|
-
|
|
134
|
+
|
|
149
135
|
it "should include joins for required associations" do
|
|
150
136
|
@query.should match(/LEFT OUTER JOIN `tags`/)
|
|
151
137
|
end
|
|
152
|
-
|
|
138
|
+
|
|
153
139
|
it "should not include joins for the sourced MVA attribute" do
|
|
154
140
|
@query.should_not match(/LEFT OUTER JOIN `contacts`/)
|
|
155
141
|
end
|
|
156
|
-
|
|
142
|
+
|
|
157
143
|
it "should include explicitly requested joins" do
|
|
158
144
|
@query.should match(/LEFT OUTER JOIN `links`/)
|
|
159
145
|
end
|
|
160
|
-
|
|
146
|
+
|
|
161
147
|
it "should include any defined conditions" do
|
|
162
148
|
@query.should match(/WHERE.+`birthday` <= NOW()/)
|
|
163
149
|
end
|
|
164
|
-
|
|
150
|
+
|
|
165
151
|
it "should include any defined groupings" do
|
|
166
152
|
@query.should match(/GROUP BY.+`first_name`/)
|
|
167
153
|
end
|
|
168
154
|
end
|
|
169
|
-
|
|
155
|
+
|
|
170
156
|
describe "#sql_query_range" do
|
|
171
157
|
before :each do
|
|
172
158
|
@query = @riddle.sql_query_range
|
|
173
159
|
end
|
|
174
|
-
|
|
160
|
+
|
|
175
161
|
it "should select data from the model table" do
|
|
176
162
|
@query.should match(/FROM `people`/)
|
|
177
163
|
end
|
|
178
|
-
|
|
164
|
+
|
|
179
165
|
it "should select the minimum and the maximum ids" do
|
|
180
166
|
@query.should match(/SELECT.+MIN.+MAX.+FROM/)
|
|
181
167
|
end
|
|
182
168
|
end
|
|
183
|
-
|
|
169
|
+
|
|
184
170
|
describe "#sql_query_info" do
|
|
185
171
|
before :each do
|
|
186
172
|
@query = @riddle.sql_query_info
|
|
187
173
|
end
|
|
188
|
-
|
|
174
|
+
|
|
189
175
|
it "should select all fields from the model table" do
|
|
190
176
|
@query.should match(/SELECT \* FROM `people`/)
|
|
191
177
|
end
|
|
192
|
-
|
|
178
|
+
|
|
193
179
|
it "should filter the primary key with the offset" do
|
|
194
180
|
model_count = ThinkingSphinx.context.indexed_models.size
|
|
195
181
|
@query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
|
|
196
182
|
end
|
|
197
183
|
end
|
|
198
|
-
|
|
184
|
+
|
|
199
185
|
describe "#sql_query_pre" do
|
|
200
186
|
before :each do
|
|
201
187
|
@queries = @riddle.sql_query_pre
|
|
202
188
|
end
|
|
203
|
-
|
|
189
|
+
|
|
204
190
|
it "should default to just the UTF8 statement" do
|
|
205
191
|
@queries.detect { |query|
|
|
206
192
|
query == "SET NAMES utf8"
|
|
207
193
|
}.should_not be_nil
|
|
208
194
|
end
|
|
209
|
-
|
|
195
|
+
|
|
210
196
|
it "should set the group_concat_max_len session value for MySQL if requested" do
|
|
211
197
|
@queries.detect { |query|
|
|
212
198
|
query == "SET SESSION group_concat_max_len = 1024"
|
|
@@ -214,41 +200,41 @@ describe ThinkingSphinx::Source do
|
|
|
214
200
|
end
|
|
215
201
|
end
|
|
216
202
|
end
|
|
217
|
-
|
|
203
|
+
|
|
218
204
|
describe "#to_riddle_for_core with range disabled" do
|
|
219
205
|
before :each do
|
|
220
206
|
ThinkingSphinx::Field.new(
|
|
221
207
|
@source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
|
|
222
208
|
)
|
|
223
209
|
end
|
|
224
|
-
|
|
210
|
+
|
|
225
211
|
describe "set per-index" do
|
|
226
212
|
before :each do
|
|
227
213
|
@index.local_options[:disable_range] = true
|
|
228
214
|
@riddle = @source.to_riddle_for_core(1, 0)
|
|
229
215
|
end
|
|
230
|
-
|
|
216
|
+
|
|
231
217
|
it "should not have the range in the sql_query" do
|
|
232
218
|
@riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
|
|
233
219
|
@riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
|
|
234
220
|
end
|
|
235
|
-
|
|
221
|
+
|
|
236
222
|
it "should not have a sql_query_range" do
|
|
237
223
|
@riddle.sql_query_range.should be_nil
|
|
238
224
|
end
|
|
239
225
|
end
|
|
240
|
-
|
|
226
|
+
|
|
241
227
|
describe "set globally" do
|
|
242
228
|
before :each do
|
|
243
229
|
ThinkingSphinx::Configuration.instance.index_options[:disable_range] = true
|
|
244
230
|
@riddle = @source.to_riddle_for_core(1, 0)
|
|
245
231
|
end
|
|
246
|
-
|
|
232
|
+
|
|
247
233
|
it "should not have the range in the sql_query" do
|
|
248
234
|
@riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
|
|
249
235
|
@riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
|
|
250
236
|
end
|
|
251
|
-
|
|
237
|
+
|
|
252
238
|
it "should not have a sql_query_range" do
|
|
253
239
|
@riddle.sql_query_range.should be_nil
|
|
254
240
|
end
|
|
@@ -5,40 +5,40 @@ describe ThinkingSphinx do
|
|
|
5
5
|
it "should return a Context instance" do
|
|
6
6
|
ThinkingSphinx.context.should be_a(ThinkingSphinx::Context)
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should remember changes to the Context instance" do
|
|
10
|
-
models = ThinkingSphinx.context.indexed_models
|
|
11
|
-
|
|
10
|
+
models = ThinkingSphinx.context.indexed_models
|
|
11
|
+
|
|
12
12
|
ThinkingSphinx.context.indexed_models.replace([:model])
|
|
13
13
|
ThinkingSphinx.context.indexed_models.should == [:model]
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
ThinkingSphinx.context.indexed_models.replace(models)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
describe '.reset_context!' do
|
|
20
20
|
it "should remove the existing Context instance" do
|
|
21
21
|
existing = ThinkingSphinx.context
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
ThinkingSphinx.reset_context!
|
|
24
24
|
ThinkingSphinx.context.should_not == existing
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
Thread.current[:thinking_sphinx_context] = existing
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
describe '.define_indexes?' do
|
|
31
31
|
it "should define indexes by default" do
|
|
32
32
|
ThinkingSphinx.define_indexes?.should be_true
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
describe '.define_indexes=' do
|
|
37
37
|
it "should disable index definition" do
|
|
38
38
|
ThinkingSphinx.define_indexes = false
|
|
39
39
|
ThinkingSphinx.define_indexes?.should be_false
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
it "should enable index definition" do
|
|
43
43
|
ThinkingSphinx.define_indexes = false
|
|
44
44
|
ThinkingSphinx.define_indexes?.should be_false
|
|
@@ -46,19 +46,20 @@ describe ThinkingSphinx do
|
|
|
46
46
|
ThinkingSphinx.define_indexes?.should be_true
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
describe '.deltas_enabled?' do
|
|
51
51
|
it "should index deltas by default" do
|
|
52
|
+
ThinkingSphinx.deltas_enabled = nil
|
|
52
53
|
ThinkingSphinx.deltas_enabled?.should be_true
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
describe '.deltas_enabled=' do
|
|
57
58
|
it "should disable delta indexing" do
|
|
58
59
|
ThinkingSphinx.deltas_enabled = false
|
|
59
60
|
ThinkingSphinx.deltas_enabled?.should be_false
|
|
60
61
|
end
|
|
61
|
-
|
|
62
|
+
|
|
62
63
|
it "should enable delta indexing" do
|
|
63
64
|
ThinkingSphinx.deltas_enabled = false
|
|
64
65
|
ThinkingSphinx.deltas_enabled?.should be_false
|
|
@@ -66,22 +67,20 @@ describe ThinkingSphinx do
|
|
|
66
67
|
ThinkingSphinx.deltas_enabled?.should be_true
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
describe '.updates_enabled?' do
|
|
71
72
|
it "should update indexes by default" do
|
|
72
|
-
ThinkingSphinx::Configuration.stub! :environment => 'development'
|
|
73
|
-
|
|
74
73
|
ThinkingSphinx.updates_enabled = nil
|
|
75
74
|
ThinkingSphinx.updates_enabled?.should be_true
|
|
76
75
|
end
|
|
77
76
|
end
|
|
78
|
-
|
|
77
|
+
|
|
79
78
|
describe '.updates_enabled=' do
|
|
80
79
|
it "should disable index updating" do
|
|
81
80
|
ThinkingSphinx.updates_enabled = false
|
|
82
81
|
ThinkingSphinx.updates_enabled?.should be_false
|
|
83
82
|
end
|
|
84
|
-
|
|
83
|
+
|
|
85
84
|
it "should enable index updating" do
|
|
86
85
|
ThinkingSphinx.updates_enabled = false
|
|
87
86
|
ThinkingSphinx.updates_enabled?.should be_false
|
|
@@ -89,25 +88,35 @@ describe ThinkingSphinx do
|
|
|
89
88
|
ThinkingSphinx.updates_enabled?.should be_true
|
|
90
89
|
end
|
|
91
90
|
end
|
|
92
|
-
|
|
91
|
+
|
|
93
92
|
describe '.sphinx_running?' do
|
|
94
93
|
it "should always say Sphinx is running if flagged as being on a remote machine" do
|
|
95
94
|
ThinkingSphinx.remote_sphinx = true
|
|
96
95
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
|
97
|
-
|
|
96
|
+
|
|
98
97
|
ThinkingSphinx.sphinx_running?.should be_true
|
|
99
98
|
end
|
|
100
|
-
|
|
99
|
+
|
|
101
100
|
it "should actually pay attention to Sphinx if not on a remote machine" do
|
|
102
101
|
ThinkingSphinx.remote_sphinx = false
|
|
103
102
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
|
104
103
|
ThinkingSphinx.sphinx_running?.should be_false
|
|
105
|
-
|
|
104
|
+
|
|
106
105
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
|
|
107
106
|
ThinkingSphinx.sphinx_running?.should be_true
|
|
108
107
|
end
|
|
109
108
|
end
|
|
110
|
-
|
|
109
|
+
|
|
110
|
+
describe '.version' do
|
|
111
|
+
it "should return the version from the stored YAML file" do
|
|
112
|
+
version = Jeweler::VersionHelper.new(
|
|
113
|
+
File.join(File.dirname(__FILE__), '..')
|
|
114
|
+
).to_s
|
|
115
|
+
|
|
116
|
+
ThinkingSphinx.version.should == version
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
111
120
|
describe "use_group_by_shortcut? method" do
|
|
112
121
|
before :each do
|
|
113
122
|
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
|
|
@@ -115,7 +124,7 @@ describe ThinkingSphinx do
|
|
|
115
124
|
pending "No MySQL"
|
|
116
125
|
return
|
|
117
126
|
end
|
|
118
|
-
|
|
127
|
+
|
|
119
128
|
@connection = stub('adapter',
|
|
120
129
|
:select_all => true,
|
|
121
130
|
:class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
|
|
@@ -124,43 +133,34 @@ describe ThinkingSphinx do
|
|
|
124
133
|
::ActiveRecord::Base.stub!(
|
|
125
134
|
:connection => @connection
|
|
126
135
|
)
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
|
|
137
|
+
Thread.current[:thinking_sphinx_use_group_by_shortcut] = nil
|
|
129
138
|
end
|
|
130
|
-
|
|
139
|
+
|
|
131
140
|
it "should return true if no ONLY_FULL_GROUP_BY" do
|
|
132
141
|
@connection.stub!(
|
|
133
142
|
:select_all => {:a => "OTHER SETTINGS"}
|
|
134
143
|
)
|
|
135
|
-
|
|
144
|
+
|
|
136
145
|
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
|
137
146
|
end
|
|
138
|
-
|
|
147
|
+
|
|
139
148
|
it "should return true if NULL value" do
|
|
140
149
|
@connection.stub!(
|
|
141
150
|
:select_all => {:a => nil}
|
|
142
151
|
)
|
|
143
|
-
|
|
152
|
+
|
|
144
153
|
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
|
145
154
|
end
|
|
146
|
-
|
|
147
|
-
it "should return true if using mysql2 gem" do
|
|
148
|
-
@connection.stub!(
|
|
149
|
-
:class => ActiveRecord::ConnectionAdapters::Mysql2Adapter,
|
|
150
|
-
:select_all => {:a => ""}
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
|
154
|
-
end unless RUBY_PLATFORM == 'java'
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
it "should return false if ONLY_FULL_GROUP_BY is set" do
|
|
157
157
|
@connection.stub!(
|
|
158
158
|
:select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
|
|
159
159
|
)
|
|
160
|
-
|
|
160
|
+
|
|
161
161
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
|
162
162
|
end
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
|
|
165
165
|
@connection.stub!(
|
|
166
166
|
:select_all => {
|
|
@@ -168,10 +168,10 @@ describe ThinkingSphinx do
|
|
|
168
168
|
:b => "ONLY_FULL_GROUP_BY"
|
|
169
169
|
}
|
|
170
170
|
)
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
|
173
173
|
end
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
describe "if not using MySQL" do
|
|
176
176
|
before :each do
|
|
177
177
|
adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
|
|
@@ -179,7 +179,7 @@ describe ThinkingSphinx do
|
|
|
179
179
|
pending "No PostgreSQL"
|
|
180
180
|
return
|
|
181
181
|
end
|
|
182
|
-
|
|
182
|
+
|
|
183
183
|
@connection = stub(adapter).as_null_object
|
|
184
184
|
@connection.stub!(
|
|
185
185
|
:select_all => true,
|
|
@@ -189,14 +189,14 @@ describe ThinkingSphinx do
|
|
|
189
189
|
:connection => @connection
|
|
190
190
|
)
|
|
191
191
|
end
|
|
192
|
-
|
|
192
|
+
|
|
193
193
|
it "should return false" do
|
|
194
194
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
|
195
195
|
end
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
it "should not call select_all" do
|
|
198
198
|
@connection.should_not_receive(:select_all)
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
ThinkingSphinx.use_group_by_shortcut?
|
|
201
201
|
end
|
|
202
202
|
end
|