sayso-thinking-sphinx 2.0.3.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +251 -0
  3. data/VERSION +1 -0
  4. data/features/abstract_inheritance.feature +10 -0
  5. data/features/alternate_primary_key.feature +27 -0
  6. data/features/attribute_transformation.feature +22 -0
  7. data/features/attribute_updates.feature +77 -0
  8. data/features/deleting_instances.feature +67 -0
  9. data/features/direct_attributes.feature +11 -0
  10. data/features/excerpts.feature +21 -0
  11. data/features/extensible_delta_indexing.feature +9 -0
  12. data/features/facets.feature +88 -0
  13. data/features/facets_across_model.feature +29 -0
  14. data/features/field_sorting.feature +18 -0
  15. data/features/handling_edits.feature +94 -0
  16. data/features/retry_stale_indexes.feature +24 -0
  17. data/features/searching_across_models.feature +20 -0
  18. data/features/searching_by_index.feature +40 -0
  19. data/features/searching_by_model.feature +168 -0
  20. data/features/searching_with_find_arguments.feature +56 -0
  21. data/features/sphinx_detection.feature +25 -0
  22. data/features/sphinx_scopes.feature +68 -0
  23. data/features/step_definitions/alpha_steps.rb +16 -0
  24. data/features/step_definitions/beta_steps.rb +7 -0
  25. data/features/step_definitions/common_steps.rb +197 -0
  26. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  27. data/features/step_definitions/facet_steps.rb +96 -0
  28. data/features/step_definitions/find_arguments_steps.rb +36 -0
  29. data/features/step_definitions/gamma_steps.rb +15 -0
  30. data/features/step_definitions/scope_steps.rb +19 -0
  31. data/features/step_definitions/search_steps.rb +94 -0
  32. data/features/step_definitions/sphinx_steps.rb +35 -0
  33. data/features/sti_searching.feature +19 -0
  34. data/features/support/env.rb +27 -0
  35. data/features/support/lib/generic_delta_handler.rb +8 -0
  36. data/features/thinking_sphinx/database.example.yml +3 -0
  37. data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -0
  38. data/features/thinking_sphinx/db/fixtures/authors.rb +1 -0
  39. data/features/thinking_sphinx/db/fixtures/betas.rb +11 -0
  40. data/features/thinking_sphinx/db/fixtures/boxes.rb +9 -0
  41. data/features/thinking_sphinx/db/fixtures/categories.rb +1 -0
  42. data/features/thinking_sphinx/db/fixtures/cats.rb +3 -0
  43. data/features/thinking_sphinx/db/fixtures/comments.rb +24 -0
  44. data/features/thinking_sphinx/db/fixtures/developers.rb +31 -0
  45. data/features/thinking_sphinx/db/fixtures/dogs.rb +3 -0
  46. data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +10 -0
  47. data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
  48. data/features/thinking_sphinx/db/fixtures/gammas.rb +10 -0
  49. data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
  50. data/features/thinking_sphinx/db/fixtures/people.rb +1001 -0
  51. data/features/thinking_sphinx/db/fixtures/posts.rb +6 -0
  52. data/features/thinking_sphinx/db/fixtures/robots.rb +14 -0
  53. data/features/thinking_sphinx/db/fixtures/tags.rb +27 -0
  54. data/features/thinking_sphinx/db/migrations/create_alphas.rb +8 -0
  55. data/features/thinking_sphinx/db/migrations/create_animals.rb +5 -0
  56. data/features/thinking_sphinx/db/migrations/create_authors.rb +3 -0
  57. data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +6 -0
  58. data/features/thinking_sphinx/db/migrations/create_betas.rb +5 -0
  59. data/features/thinking_sphinx/db/migrations/create_boxes.rb +5 -0
  60. data/features/thinking_sphinx/db/migrations/create_categories.rb +3 -0
  61. data/features/thinking_sphinx/db/migrations/create_comments.rb +10 -0
  62. data/features/thinking_sphinx/db/migrations/create_developers.rb +7 -0
  63. data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +5 -0
  64. data/features/thinking_sphinx/db/migrations/create_gammas.rb +3 -0
  65. data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
  66. data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
  67. data/features/thinking_sphinx/db/migrations/create_people.rb +13 -0
  68. data/features/thinking_sphinx/db/migrations/create_posts.rb +5 -0
  69. data/features/thinking_sphinx/db/migrations/create_robots.rb +4 -0
  70. data/features/thinking_sphinx/db/migrations/create_taggings.rb +5 -0
  71. data/features/thinking_sphinx/db/migrations/create_tags.rb +4 -0
  72. data/features/thinking_sphinx/models/alpha.rb +23 -0
  73. data/features/thinking_sphinx/models/andrew.rb +17 -0
  74. data/features/thinking_sphinx/models/animal.rb +5 -0
  75. data/features/thinking_sphinx/models/author.rb +3 -0
  76. data/features/thinking_sphinx/models/beta.rb +13 -0
  77. data/features/thinking_sphinx/models/box.rb +8 -0
  78. data/features/thinking_sphinx/models/cat.rb +3 -0
  79. data/features/thinking_sphinx/models/category.rb +4 -0
  80. data/features/thinking_sphinx/models/comment.rb +10 -0
  81. data/features/thinking_sphinx/models/developer.rb +20 -0
  82. data/features/thinking_sphinx/models/dog.rb +3 -0
  83. data/features/thinking_sphinx/models/extensible_beta.rb +9 -0
  84. data/features/thinking_sphinx/models/fox.rb +5 -0
  85. data/features/thinking_sphinx/models/gamma.rb +5 -0
  86. data/features/thinking_sphinx/models/genre.rb +3 -0
  87. data/features/thinking_sphinx/models/medium.rb +5 -0
  88. data/features/thinking_sphinx/models/music.rb +8 -0
  89. data/features/thinking_sphinx/models/person.rb +24 -0
  90. data/features/thinking_sphinx/models/post.rb +21 -0
  91. data/features/thinking_sphinx/models/robot.rb +12 -0
  92. data/features/thinking_sphinx/models/tag.rb +3 -0
  93. data/features/thinking_sphinx/models/tagging.rb +4 -0
  94. data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
  95. data/lib/cucumber/thinking_sphinx/internal_world.rb +127 -0
  96. data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
  97. data/lib/thinking-sphinx.rb +1 -0
  98. data/lib/thinking_sphinx.rb +301 -0
  99. data/lib/thinking_sphinx/action_controller.rb +31 -0
  100. data/lib/thinking_sphinx/active_record.rb +352 -0
  101. data/lib/thinking_sphinx/active_record/attribute_updates.rb +52 -0
  102. data/lib/thinking_sphinx/active_record/delta.rb +92 -0
  103. data/lib/thinking_sphinx/active_record/has_many_association.rb +36 -0
  104. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +21 -0
  105. data/lib/thinking_sphinx/active_record/log_subscriber.rb +61 -0
  106. data/lib/thinking_sphinx/active_record/scopes.rb +93 -0
  107. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +87 -0
  108. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +58 -0
  109. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +153 -0
  110. data/lib/thinking_sphinx/association.rb +169 -0
  111. data/lib/thinking_sphinx/attribute.rb +389 -0
  112. data/lib/thinking_sphinx/auto_version.rb +38 -0
  113. data/lib/thinking_sphinx/bundled_search.rb +44 -0
  114. data/lib/thinking_sphinx/class_facet.rb +16 -0
  115. data/lib/thinking_sphinx/configuration.rb +355 -0
  116. data/lib/thinking_sphinx/context.rb +76 -0
  117. data/lib/thinking_sphinx/core/string.rb +15 -0
  118. data/lib/thinking_sphinx/deltas.rb +28 -0
  119. data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
  120. data/lib/thinking_sphinx/deploy/capistrano.rb +101 -0
  121. data/lib/thinking_sphinx/excerpter.rb +23 -0
  122. data/lib/thinking_sphinx/facet.rb +127 -0
  123. data/lib/thinking_sphinx/facet_search.rb +166 -0
  124. data/lib/thinking_sphinx/field.rb +82 -0
  125. data/lib/thinking_sphinx/index.rb +157 -0
  126. data/lib/thinking_sphinx/index/builder.rb +312 -0
  127. data/lib/thinking_sphinx/index/faux_column.rb +118 -0
  128. data/lib/thinking_sphinx/join.rb +37 -0
  129. data/lib/thinking_sphinx/property.rb +185 -0
  130. data/lib/thinking_sphinx/railtie.rb +46 -0
  131. data/lib/thinking_sphinx/search.rb +950 -0
  132. data/lib/thinking_sphinx/search_methods.rb +439 -0
  133. data/lib/thinking_sphinx/source.rb +163 -0
  134. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  135. data/lib/thinking_sphinx/source/sql.rb +148 -0
  136. data/lib/thinking_sphinx/tasks.rb +139 -0
  137. data/lib/thinking_sphinx/test.rb +55 -0
  138. data/spec/thinking_sphinx/active_record/delta_spec.rb +128 -0
  139. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +72 -0
  140. data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
  141. data/spec/thinking_sphinx/active_record_spec.rb +576 -0
  142. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +145 -0
  143. data/spec/thinking_sphinx/association_spec.rb +216 -0
  144. data/spec/thinking_sphinx/attribute_spec.rb +560 -0
  145. data/spec/thinking_sphinx/auto_version_spec.rb +63 -0
  146. data/spec/thinking_sphinx/configuration_spec.rb +288 -0
  147. data/spec/thinking_sphinx/context_spec.rb +128 -0
  148. data/spec/thinking_sphinx/core/array_spec.rb +9 -0
  149. data/spec/thinking_sphinx/core/string_spec.rb +9 -0
  150. data/spec/thinking_sphinx/excerpter_spec.rb +49 -0
  151. data/spec/thinking_sphinx/facet_search_spec.rb +170 -0
  152. data/spec/thinking_sphinx/facet_spec.rb +359 -0
  153. data/spec/thinking_sphinx/field_spec.rb +127 -0
  154. data/spec/thinking_sphinx/index/builder_spec.rb +508 -0
  155. data/spec/thinking_sphinx/index/faux_column_spec.rb +36 -0
  156. data/spec/thinking_sphinx/index_spec.rb +183 -0
  157. data/spec/thinking_sphinx/search_methods_spec.rb +156 -0
  158. data/spec/thinking_sphinx/search_spec.rb +1387 -0
  159. data/spec/thinking_sphinx/source_spec.rb +253 -0
  160. data/spec/thinking_sphinx/test_spec.rb +20 -0
  161. data/spec/thinking_sphinx_spec.rb +203 -0
  162. data/tasks/distribution.rb +33 -0
  163. data/tasks/testing.rb +80 -0
  164. metadata +509 -0
@@ -0,0 +1,253 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx::Source do
4
+ before :each do
5
+ @index = ThinkingSphinx::Index.new(Person)
6
+ @source = ThinkingSphinx::Source.new(@index, :sql_range_step => 1000)
7
+ end
8
+
9
+ describe '#initialize' do
10
+ it "should store the current connection details" do
11
+ config = Person.connection.instance_variable_get(:@config)
12
+ @source.database_configuration.should == config
13
+ end
14
+ end
15
+
16
+ it "should generate the name from the model" do
17
+ @source.name.should == "person"
18
+ end
19
+
20
+ it "should handle namespaced models for name generation" do
21
+ index = ThinkingSphinx::Index.new(Admin::Person)
22
+ source = ThinkingSphinx::Source.new(index)
23
+ source.name.should == "admin_person"
24
+ end
25
+
26
+ describe "#to_riddle_for_core" do
27
+ before :each do
28
+ config = ThinkingSphinx::Configuration.instance
29
+ config.source_options[:sql_ranged_throttle] = 100
30
+
31
+ ThinkingSphinx::Field.new(
32
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
33
+ )
34
+ ThinkingSphinx::Field.new(
35
+ @source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
36
+ )
37
+
38
+ ThinkingSphinx::Attribute.new(
39
+ @source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
40
+ )
41
+ ThinkingSphinx::Attribute.new(
42
+ @source, ThinkingSphinx::Index::FauxColumn.new(:birthday)
43
+ )
44
+ ThinkingSphinx::Attribute.new(
45
+ @source, ThinkingSphinx::Index::FauxColumn.new(:tags, :id), :as => :tag_ids
46
+ )
47
+ ThinkingSphinx::Attribute.new(
48
+ @source, ThinkingSphinx::Index::FauxColumn.new(:contacts, :id),
49
+ :as => :contact_ids, :source => :query
50
+ )
51
+ ThinkingSphinx::Attribute.new(
52
+ @source, ThinkingSphinx::Index::FauxColumn.new(:source, :id),
53
+ :as => :source_id, :type => :integer
54
+ )
55
+
56
+ ThinkingSphinx::Join.new(
57
+ @source, ThinkingSphinx::Index::FauxColumn.new(:links)
58
+ )
59
+
60
+ @source.conditions << "`birthday` <= NOW()"
61
+ @source.groupings << "`first_name`"
62
+
63
+ @index.local_options[:group_concat_max_len] = 1024
64
+
65
+ @riddle = @source.to_riddle_for_core(1, 0)
66
+ end
67
+
68
+ it "should generate a Riddle Source object" do
69
+ @riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
70
+ end
71
+
72
+ it "should use the index and name its own name" do
73
+ @riddle.name.should == "person_core_0"
74
+ end
75
+
76
+ it "should use the model's database connection to determine type" do
77
+ @riddle.type.should == "mysql"
78
+ end
79
+
80
+ it "should match the model's database settings" do
81
+ config = Person.connection.instance_variable_get(:@config)
82
+ @riddle.sql_db.should == config[:database]
83
+ @riddle.sql_user.should == config[:username]
84
+ @riddle.sql_pass.should == config[:password].to_s
85
+ @riddle.sql_host.should == config[:host]
86
+ @riddle.sql_port.should == config[:port]
87
+ @riddle.sql_sock.should == config[:socket]
88
+ end
89
+
90
+ it "should use a default username of root if nothing else is provided" do
91
+ Person.connection.stub!(:instance_variable_get => {
92
+ :user => nil,
93
+ :username => nil
94
+ })
95
+ @source = ThinkingSphinx::Source.new(@index)
96
+
97
+ riddle = @source.to_riddle_for_core(1, 0)
98
+ riddle.sql_user.should == 'root'
99
+ end
100
+
101
+ it "should assign attributes" do
102
+ # 3 internal attributes plus the one requested
103
+ @riddle.sql_attr_uint.length.should == 4
104
+ @riddle.sql_attr_uint.last.should == :internal_id
105
+
106
+ @riddle.sql_attr_timestamp.length.should == 1
107
+ @riddle.sql_attr_timestamp.first.should == :birthday
108
+ end
109
+
110
+ it "should not include an attribute definition for polymorphic references without data" do
111
+ @riddle.sql_attr_uint.select { |uint|
112
+ uint == :source_id
113
+ }.should be_empty
114
+ end
115
+
116
+ it "should set Sphinx Source options" do
117
+ @riddle.sql_range_step.should == 1000
118
+ @riddle.sql_ranged_throttle.should == 100
119
+ end
120
+
121
+ describe "#sql_query" do
122
+ before :each do
123
+ @query = @riddle.sql_query
124
+ end
125
+
126
+ it "should select data from the model table" do
127
+ @query.should match(/FROM\s+`people`/)
128
+ end
129
+
130
+ it "should select each of the fields" do
131
+ @query.should match(/`first_name`.+FROM/)
132
+ @query.should match(/`last_name`.+FROM/)
133
+ end
134
+
135
+ it "should select each of the attributes" do
136
+ @query.should match(/`id` AS `internal_id`.+FROM/)
137
+ @query.should match(/`birthday`.+FROM/)
138
+ @query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
139
+ end
140
+
141
+ it "should not match the sourced MVA attribute" do
142
+ @query.should_not match(/contact_ids/)
143
+ end
144
+
145
+ it "should include joins for required associations" do
146
+ @query.should match(/LEFT OUTER JOIN `tags`/)
147
+ end
148
+
149
+ it "should not include joins for the sourced MVA attribute" do
150
+ @query.should_not match(/LEFT OUTER JOIN `contacts`/)
151
+ end
152
+
153
+ it "should include explicitly requested joins" do
154
+ @query.should match(/LEFT OUTER JOIN `links`/)
155
+ end
156
+
157
+ it "should include any defined conditions" do
158
+ @query.should match(/WHERE.+`birthday` <= NOW()/)
159
+ end
160
+
161
+ it "should include any defined groupings" do
162
+ @query.should match(/GROUP BY.+`first_name`/)
163
+ end
164
+ end
165
+
166
+ describe "#sql_query_range" do
167
+ before :each do
168
+ @query = @riddle.sql_query_range
169
+ end
170
+
171
+ it "should select data from the model table" do
172
+ @query.should match(/FROM `people`/)
173
+ end
174
+
175
+ it "should select the minimum and the maximum ids" do
176
+ @query.should match(/SELECT.+MIN.+MAX.+FROM/)
177
+ end
178
+ end
179
+
180
+ describe "#sql_query_info" do
181
+ before :each do
182
+ @query = @riddle.sql_query_info
183
+ end
184
+
185
+ it "should select all fields from the model table" do
186
+ @query.should match(/SELECT \* FROM `people`/)
187
+ end
188
+
189
+ it "should filter the primary key with the offset" do
190
+ model_count = ThinkingSphinx.context.indexed_models.size
191
+ @query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
192
+ end
193
+ end
194
+
195
+ describe "#sql_query_pre" do
196
+ before :each do
197
+ @queries = @riddle.sql_query_pre
198
+ end
199
+
200
+ it "should default to just the UTF8 statement" do
201
+ @queries.detect { |query|
202
+ query == "SET NAMES utf8"
203
+ }.should_not be_nil
204
+ end
205
+
206
+ it "should set the group_concat_max_len session value for MySQL if requested" do
207
+ @queries.detect { |query|
208
+ query == "SET SESSION group_concat_max_len = 1024"
209
+ }.should_not be_nil
210
+ end
211
+ end
212
+ end
213
+
214
+ describe "#to_riddle_for_core with range disabled" do
215
+ before :each do
216
+ ThinkingSphinx::Field.new(
217
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
218
+ )
219
+ end
220
+
221
+ describe "set per-index" do
222
+ before :each do
223
+ @index.local_options[:disable_range] = true
224
+ @riddle = @source.to_riddle_for_core(1, 0)
225
+ end
226
+
227
+ it "should not have the range in the sql_query" do
228
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
229
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
230
+ end
231
+
232
+ it "should not have a sql_query_range" do
233
+ @riddle.sql_query_range.should be_nil
234
+ end
235
+ end
236
+
237
+ describe "set globally" do
238
+ before :each do
239
+ ThinkingSphinx::Configuration.instance.index_options[:disable_range] = true
240
+ @riddle = @source.to_riddle_for_core(1, 0)
241
+ end
242
+
243
+ it "should not have the range in the sql_query" do
244
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
245
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
246
+ end
247
+
248
+ it "should not have a sql_query_range" do
249
+ @riddle.sql_query_range.should be_nil
250
+ end
251
+ end
252
+ end
253
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require "#{File.dirname(__FILE__)}/../../lib/thinking_sphinx/test"
3
+
4
+ describe ThinkingSphinx::Test do
5
+ describe ".run" do
6
+ before :each do
7
+ ThinkingSphinx::Test.stub!(:start)
8
+ end
9
+
10
+ it "should call stop when an exception is raised by passed block" do
11
+ ThinkingSphinx::Test.should_receive(:stop)
12
+
13
+ begin
14
+ ThinkingSphinx::Test.run { raise FakeError }
15
+ rescue => FakeError
16
+ # we raised it manually ourselves!
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx do
4
+ describe '.context' do
5
+ it "should return a Context instance" do
6
+ ThinkingSphinx.context.should be_a(ThinkingSphinx::Context)
7
+ end
8
+
9
+ it "should remember changes to the Context instance" do
10
+ models = ThinkingSphinx.context.indexed_models
11
+
12
+ ThinkingSphinx.context.indexed_models.replace([:model])
13
+ ThinkingSphinx.context.indexed_models.should == [:model]
14
+
15
+ ThinkingSphinx.context.indexed_models.replace(models)
16
+ end
17
+ end
18
+
19
+ describe '.reset_context!' do
20
+ it "should remove the existing Context instance" do
21
+ existing = ThinkingSphinx.context
22
+
23
+ ThinkingSphinx.reset_context!
24
+ ThinkingSphinx.context.should_not == existing
25
+
26
+ ThinkingSphinx.reset_context! existing
27
+ end
28
+ end
29
+
30
+ describe '.define_indexes?' do
31
+ it "should define indexes by default" do
32
+ ThinkingSphinx.define_indexes?.should be_true
33
+ end
34
+ end
35
+
36
+ describe '.define_indexes=' do
37
+ it "should disable index definition" do
38
+ ThinkingSphinx.define_indexes = false
39
+ ThinkingSphinx.define_indexes?.should be_false
40
+ end
41
+
42
+ it "should enable index definition" do
43
+ ThinkingSphinx.define_indexes = false
44
+ ThinkingSphinx.define_indexes?.should be_false
45
+ ThinkingSphinx.define_indexes = true
46
+ ThinkingSphinx.define_indexes?.should be_true
47
+ end
48
+ end
49
+
50
+ describe '.deltas_enabled?' do
51
+ it "should index deltas by default" do
52
+ ThinkingSphinx.deltas_enabled?.should be_true
53
+ end
54
+ end
55
+
56
+ describe '.deltas_enabled=' do
57
+ it "should disable delta indexing" do
58
+ ThinkingSphinx.deltas_enabled = false
59
+ ThinkingSphinx.deltas_enabled?.should be_false
60
+ end
61
+
62
+ it "should enable delta indexing" do
63
+ ThinkingSphinx.deltas_enabled = false
64
+ ThinkingSphinx.deltas_enabled?.should be_false
65
+ ThinkingSphinx.deltas_enabled = true
66
+ ThinkingSphinx.deltas_enabled?.should be_true
67
+ end
68
+ end
69
+
70
+ describe '.updates_enabled?' do
71
+ it "should update indexes by default" do
72
+ ThinkingSphinx.updates_enabled = nil
73
+ ThinkingSphinx.updates_enabled?.should be_true
74
+ end
75
+ end
76
+
77
+ describe '.updates_enabled=' do
78
+ it "should disable index updating" do
79
+ ThinkingSphinx.updates_enabled = false
80
+ ThinkingSphinx.updates_enabled?.should be_false
81
+ end
82
+
83
+ it "should enable index updating" do
84
+ ThinkingSphinx.updates_enabled = false
85
+ ThinkingSphinx.updates_enabled?.should be_false
86
+ ThinkingSphinx.updates_enabled = true
87
+ ThinkingSphinx.updates_enabled?.should be_true
88
+ end
89
+ end
90
+
91
+ describe '.sphinx_running?' do
92
+ it "should always say Sphinx is running if flagged as being on a remote machine" do
93
+ ThinkingSphinx.remote_sphinx = true
94
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
95
+
96
+ ThinkingSphinx.sphinx_running?.should be_true
97
+ end
98
+
99
+ it "should actually pay attention to Sphinx if not on a remote machine" do
100
+ ThinkingSphinx.remote_sphinx = false
101
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
102
+ ThinkingSphinx.sphinx_running?.should be_false
103
+
104
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
105
+ ThinkingSphinx.sphinx_running?.should be_true
106
+ end
107
+ end
108
+
109
+ describe '.version' do
110
+ it "should return the version from the stored YAML file" do
111
+ version = Jeweler::VersionHelper.new(
112
+ File.join(File.dirname(__FILE__), '..')
113
+ ).to_s
114
+
115
+ ThinkingSphinx.version.should == version
116
+ end
117
+ end
118
+
119
+ describe "use_group_by_shortcut? method" do
120
+ before :each do
121
+ adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
122
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
123
+ pending "No MySQL"
124
+ return
125
+ end
126
+
127
+ @connection = stub('adapter',
128
+ :select_all => true,
129
+ :class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
130
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
131
+ )
132
+ ::ActiveRecord::Base.stub!(
133
+ :connection => @connection
134
+ )
135
+
136
+ ThinkingSphinx.reset_use_group_by_shortcut
137
+ end
138
+
139
+ it "should return true if no ONLY_FULL_GROUP_BY" do
140
+ @connection.stub!(
141
+ :select_all => {:a => "OTHER SETTINGS"}
142
+ )
143
+
144
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
145
+ end
146
+
147
+ it "should return true if NULL value" do
148
+ @connection.stub!(
149
+ :select_all => {:a => nil}
150
+ )
151
+
152
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
153
+ end
154
+
155
+ it "should return false if ONLY_FULL_GROUP_BY is set" do
156
+ @connection.stub!(
157
+ :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
158
+ )
159
+
160
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
161
+ end
162
+
163
+ it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
164
+ @connection.stub!(
165
+ :select_all => {
166
+ :a => "OTHER SETTINGS",
167
+ :b => "ONLY_FULL_GROUP_BY"
168
+ }
169
+ )
170
+
171
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
172
+ end
173
+
174
+ describe "if not using MySQL" do
175
+ before :each do
176
+ adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
177
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
178
+ pending "No PostgreSQL"
179
+ return
180
+ end
181
+
182
+ @connection = stub(adapter).as_null_object
183
+ @connection.stub!(
184
+ :select_all => true,
185
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
186
+ )
187
+ ::ActiveRecord::Base.stub!(
188
+ :connection => @connection
189
+ )
190
+ end
191
+
192
+ it "should return false" do
193
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
194
+ end
195
+
196
+ it "should not call select_all" do
197
+ @connection.should_not_receive(:select_all)
198
+
199
+ ThinkingSphinx.use_group_by_shortcut?
200
+ end
201
+ end
202
+ end
203
+ end