thinking-sphinx 1.2.13 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. data/README.textile +37 -4
  2. data/VERSION +1 -0
  3. data/features/abstract_inheritance.feature +10 -0
  4. data/features/alternate_primary_key.feature +1 -1
  5. data/features/attribute_updates.feature +49 -5
  6. data/features/deleting_instances.feature +3 -0
  7. data/features/excerpts.feature +8 -0
  8. data/features/facets.feature +15 -1
  9. data/features/facets_across_model.feature +2 -2
  10. data/features/field_sorting.feature +18 -0
  11. data/features/handling_edits.feature +1 -1
  12. data/features/searching_across_models.feature +2 -2
  13. data/features/searching_by_index.feature +40 -0
  14. data/features/searching_by_model.feature +1 -8
  15. data/features/sphinx_scopes.feature +33 -0
  16. data/features/step_definitions/alpha_steps.rb +14 -1
  17. data/features/step_definitions/beta_steps.rb +1 -1
  18. data/features/step_definitions/common_steps.rb +21 -2
  19. data/features/step_definitions/facet_steps.rb +4 -0
  20. data/features/step_definitions/scope_steps.rb +8 -0
  21. data/features/step_definitions/search_steps.rb +5 -0
  22. data/features/step_definitions/sphinx_steps.rb +8 -4
  23. data/features/sti_searching.feature +5 -0
  24. data/features/support/env.rb +7 -6
  25. data/features/{support → thinking_sphinx}/db/fixtures/betas.rb +1 -0
  26. data/features/{support → thinking_sphinx}/db/fixtures/comments.rb +1 -1
  27. data/features/{support → thinking_sphinx}/db/fixtures/developers.rb +2 -0
  28. data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
  29. data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
  30. data/features/{support → thinking_sphinx}/db/fixtures/people.rb +1 -1
  31. data/features/{support → thinking_sphinx}/db/fixtures/tags.rb +1 -1
  32. data/features/{support → thinking_sphinx}/db/migrations/create_alphas.rb +1 -0
  33. data/features/{support → thinking_sphinx}/db/migrations/create_developers.rb +0 -2
  34. data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
  35. data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
  36. data/features/thinking_sphinx/models/alpha.rb +23 -0
  37. data/features/thinking_sphinx/models/andrew.rb +17 -0
  38. data/features/{support → thinking_sphinx}/models/beta.rb +1 -1
  39. data/features/{support → thinking_sphinx}/models/developer.rb +2 -2
  40. data/features/{support → thinking_sphinx}/models/extensible_beta.rb +1 -1
  41. data/features/thinking_sphinx/models/fox.rb +5 -0
  42. data/features/thinking_sphinx/models/genre.rb +3 -0
  43. data/features/thinking_sphinx/models/medium.rb +5 -0
  44. data/features/thinking_sphinx/models/music.rb +8 -0
  45. data/features/{support → thinking_sphinx}/models/person.rb +2 -1
  46. data/features/{support → thinking_sphinx}/models/post.rb +2 -1
  47. data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
  48. data/lib/cucumber/thinking_sphinx/internal_world.rb +13 -11
  49. data/lib/thinking_sphinx/active_record/attribute_updates.rb +17 -15
  50. data/lib/thinking_sphinx/active_record/delta.rb +0 -26
  51. data/lib/thinking_sphinx/active_record/has_many_association.rb +34 -11
  52. data/lib/thinking_sphinx/active_record/scopes.rb +46 -3
  53. data/lib/thinking_sphinx/active_record.rb +271 -193
  54. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +45 -9
  55. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +5 -1
  56. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +9 -1
  57. data/lib/thinking_sphinx/attribute.rb +67 -23
  58. data/lib/thinking_sphinx/auto_version.rb +24 -0
  59. data/lib/thinking_sphinx/bundled_search.rb +44 -0
  60. data/lib/thinking_sphinx/class_facet.rb +3 -2
  61. data/lib/thinking_sphinx/configuration.rb +78 -64
  62. data/lib/thinking_sphinx/context.rb +76 -0
  63. data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
  64. data/lib/thinking_sphinx/deltas.rb +0 -2
  65. data/lib/thinking_sphinx/deploy/capistrano.rb +1 -1
  66. data/lib/thinking_sphinx/excerpter.rb +1 -1
  67. data/lib/thinking_sphinx/facet.rb +6 -5
  68. data/lib/thinking_sphinx/facet_search.rb +54 -24
  69. data/lib/thinking_sphinx/field.rb +2 -4
  70. data/lib/thinking_sphinx/index/builder.rb +36 -20
  71. data/lib/thinking_sphinx/index/faux_column.rb +8 -0
  72. data/lib/thinking_sphinx/index.rb +77 -19
  73. data/lib/thinking_sphinx/join.rb +37 -0
  74. data/lib/thinking_sphinx/property.rb +9 -2
  75. data/lib/thinking_sphinx/rails_additions.rb +4 -4
  76. data/lib/thinking_sphinx/search.rb +212 -66
  77. data/lib/thinking_sphinx/search_methods.rb +22 -4
  78. data/lib/thinking_sphinx/source/internal_properties.rb +2 -2
  79. data/lib/thinking_sphinx/source/sql.rb +5 -3
  80. data/lib/thinking_sphinx/source.rb +21 -12
  81. data/lib/thinking_sphinx/tasks.rb +26 -58
  82. data/lib/thinking_sphinx/test.rb +55 -0
  83. data/lib/thinking_sphinx.rb +70 -38
  84. data/rails/init.rb +4 -2
  85. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +6 -8
  86. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +26 -3
  87. data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
  88. data/spec/thinking_sphinx/active_record_spec.rb +618 -0
  89. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +134 -0
  90. data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +1 -1
  91. data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +87 -46
  92. data/spec/thinking_sphinx/auto_version_spec.rb +47 -0
  93. data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +73 -63
  94. data/spec/thinking_sphinx/context_spec.rb +127 -0
  95. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +1 -1
  96. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +1 -1
  97. data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +1 -9
  98. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +76 -82
  99. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +5 -5
  100. data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +1 -42
  101. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +71 -31
  102. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +8 -2
  103. data/spec/thinking_sphinx/index_spec.rb +183 -0
  104. data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +5 -5
  105. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +5 -1
  106. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +183 -31
  107. data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +18 -2
  108. data/spec/thinking_sphinx/test_spec.rb +20 -0
  109. data/spec/thinking_sphinx_spec.rb +204 -0
  110. data/tasks/distribution.rb +7 -26
  111. data/tasks/testing.rb +32 -20
  112. metadata +488 -147
  113. data/VERSION.yml +0 -5
  114. data/features/datetime_deltas.feature +0 -66
  115. data/features/delayed_delta_indexing.feature +0 -37
  116. data/features/step_definitions/datetime_delta_steps.rb +0 -15
  117. data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
  118. data/features/support/database.yml +0 -5
  119. data/features/support/db/active_record.rb +0 -40
  120. data/features/support/db/database.yml +0 -5
  121. data/features/support/db/fixtures/delayed_betas.rb +0 -10
  122. data/features/support/db/fixtures/thetas.rb +0 -10
  123. data/features/support/db/migrations/create_delayed_betas.rb +0 -17
  124. data/features/support/db/migrations/create_thetas.rb +0 -5
  125. data/features/support/db/mysql.rb +0 -3
  126. data/features/support/db/postgresql.rb +0 -3
  127. data/features/support/models/alpha.rb +0 -10
  128. data/features/support/models/delayed_beta.rb +0 -7
  129. data/features/support/models/theta.rb +0 -7
  130. data/features/support/post_database.rb +0 -43
  131. data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
  132. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
  133. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
  134. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
  135. data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
  136. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
  137. data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
  138. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
  139. data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
  140. data/spec/lib/thinking_sphinx_spec.rb +0 -162
  141. data/vendor/after_commit/LICENSE +0 -20
  142. data/vendor/after_commit/README +0 -16
  143. data/vendor/after_commit/Rakefile +0 -22
  144. data/vendor/after_commit/init.rb +0 -8
  145. data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
  146. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
  147. data/vendor/after_commit/lib/after_commit.rb +0 -45
  148. data/vendor/after_commit/test/after_commit_test.rb +0 -53
  149. data/vendor/delayed_job/lib/delayed/job.rb +0 -251
  150. data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
  151. data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
  152. data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
  153. data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
  154. data/vendor/riddle/lib/riddle/client/message.rb +0 -66
  155. data/vendor/riddle/lib/riddle/client/response.rb +0 -84
  156. data/vendor/riddle/lib/riddle/client.rb +0 -635
  157. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
  158. data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
  159. data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
  160. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
  161. data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
  162. data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
  163. data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
  164. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
  165. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
  166. data/vendor/riddle/lib/riddle/configuration.rb +0 -33
  167. data/vendor/riddle/lib/riddle/controller.rb +0 -53
  168. data/vendor/riddle/lib/riddle.rb +0 -30
  169. data/features/{support → thinking_sphinx}/database.example.yml +0 -0
  170. data/features/{support → thinking_sphinx}/db/fixtures/alphas.rb +0 -0
  171. data/features/{support → thinking_sphinx}/db/fixtures/authors.rb +0 -0
  172. data/features/{support → thinking_sphinx}/db/fixtures/boxes.rb +0 -0
  173. data/features/{support → thinking_sphinx}/db/fixtures/categories.rb +0 -0
  174. data/features/{support → thinking_sphinx}/db/fixtures/cats.rb +0 -0
  175. data/features/{support → thinking_sphinx}/db/fixtures/dogs.rb +0 -0
  176. data/features/{support → thinking_sphinx}/db/fixtures/extensible_betas.rb +0 -0
  177. data/features/{support → thinking_sphinx}/db/fixtures/gammas.rb +0 -0
  178. data/features/{support → thinking_sphinx}/db/fixtures/posts.rb +0 -0
  179. data/features/{support → thinking_sphinx}/db/fixtures/robots.rb +0 -0
  180. data/features/{support → thinking_sphinx}/db/migrations/create_animals.rb +0 -0
  181. data/features/{support → thinking_sphinx}/db/migrations/create_authors.rb +0 -0
  182. data/features/{support → thinking_sphinx}/db/migrations/create_authors_posts.rb +0 -0
  183. data/features/{support → thinking_sphinx}/db/migrations/create_betas.rb +0 -0
  184. data/features/{support → thinking_sphinx}/db/migrations/create_boxes.rb +0 -0
  185. data/features/{support → thinking_sphinx}/db/migrations/create_categories.rb +0 -0
  186. data/features/{support → thinking_sphinx}/db/migrations/create_comments.rb +0 -0
  187. data/features/{support → thinking_sphinx}/db/migrations/create_extensible_betas.rb +0 -0
  188. data/features/{support → thinking_sphinx}/db/migrations/create_gammas.rb +0 -0
  189. data/features/{support → thinking_sphinx}/db/migrations/create_people.rb +0 -0
  190. data/features/{support → thinking_sphinx}/db/migrations/create_posts.rb +0 -0
  191. data/features/{support → thinking_sphinx}/db/migrations/create_robots.rb +0 -0
  192. data/features/{support → thinking_sphinx}/db/migrations/create_taggings.rb +0 -0
  193. data/features/{support → thinking_sphinx}/db/migrations/create_tags.rb +0 -0
  194. data/features/{support → thinking_sphinx}/models/animal.rb +0 -0
  195. data/features/{support → thinking_sphinx}/models/author.rb +0 -0
  196. data/features/{support → thinking_sphinx}/models/box.rb +0 -0
  197. data/features/{support → thinking_sphinx}/models/cat.rb +0 -0
  198. data/features/{support → thinking_sphinx}/models/category.rb +0 -0
  199. data/features/{support → thinking_sphinx}/models/comment.rb +3 -3
  200. /data/features/{support → thinking_sphinx}/models/dog.rb +0 -0
  201. /data/features/{support → thinking_sphinx}/models/gamma.rb +0 -0
  202. /data/features/{support → thinking_sphinx}/models/robot.rb +0 -0
  203. /data/features/{support → thinking_sphinx}/models/tag.rb +0 -0
  204. /data/features/{support → thinking_sphinx}/models/tagging.rb +0 -0
@@ -1,353 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::ActiveRecord do
4
- describe '.define_index' do
5
- before :each do
6
- module ::TestModule
7
- class TestModel < ActiveRecord::Base; end
8
- end
9
-
10
- TestModule::TestModel.stub!(
11
- :before_save => true,
12
- :after_commit => true,
13
- :after_destroy => true
14
- )
15
-
16
- @index = ThinkingSphinx::Index.new(TestModule::TestModel)
17
- @index.stub!(:delta? => false)
18
- ThinkingSphinx::Index::Builder.stub!(:generate => @index)
19
- end
20
-
21
- after :each do
22
- # Remove the class so we can redefine it
23
- TestModule.send(:remove_const, :TestModel)
24
-
25
- ThinkingSphinx.indexed_models.delete "TestModule::TestModel"
26
- end
27
-
28
- it "should do nothing if indexes are disabled" do
29
- ThinkingSphinx.define_indexes = false
30
- ThinkingSphinx::Index.should_not_receive(:new)
31
-
32
- TestModule::TestModel.define_index {}
33
-
34
- ThinkingSphinx.define_indexes = true
35
- end
36
-
37
- it "should add a new index to the model" do
38
- TestModule::TestModel.define_index {}
39
-
40
- TestModule::TestModel.sphinx_indexes.length.should == 1
41
- end
42
-
43
- it "should add to ThinkingSphinx.indexed_models if the model doesn't already exist in the array" do
44
- TestModule::TestModel.define_index do; end
45
-
46
- ThinkingSphinx.indexed_models.should include("TestModule::TestModel")
47
- end
48
-
49
- it "shouldn't add to ThinkingSphinx.indexed_models if the model already exists in the array" do
50
- TestModule::TestModel.define_index do; end
51
-
52
- ThinkingSphinx.indexed_models.select { |model|
53
- model == "TestModule::TestModel"
54
- }.length.should == 1
55
-
56
- TestModule::TestModel.define_index do; end
57
-
58
- ThinkingSphinx.indexed_models.select { |model|
59
- model == "TestModule::TestModel"
60
- }.length.should == 1
61
- end
62
-
63
- it "should add before_save and after_commit hooks to the model if delta indexing is enabled" do
64
- @index.stub!(:delta? => true)
65
- TestModule::TestModel.should_receive(:before_save).with(:toggle_delta)
66
- TestModule::TestModel.should_receive(:after_commit).with(:index_delta)
67
-
68
- TestModule::TestModel.define_index do; end
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.should_not_receive(:before_save).with(:toggle_delta)
73
- TestModule::TestModel.should_not_receive(:after_commit).with(:index_delta)
74
-
75
- TestModule::TestModel.define_index do; end
76
- end
77
-
78
- it "should add an after_destroy hook with delta indexing enabled" do
79
- @index.stub!(:delta? => true)
80
- TestModule::TestModel.should_receive(:after_destroy).with(:toggle_deleted)
81
-
82
- TestModule::TestModel.define_index do; end
83
- end
84
-
85
- it "should add an after_destroy hook with delta indexing disabled" do
86
- TestModule::TestModel.should_receive(:after_destroy).with(:toggle_deleted)
87
-
88
- TestModule::TestModel.define_index do; end
89
- end
90
-
91
- it "should return the new index" do
92
- TestModule::TestModel.define_index.should == @index
93
- end
94
-
95
- it "should die quietly if there is a database error" do
96
- ThinkingSphinx::Index::Builder.stub(:generate) { raise Mysql::Error }
97
-
98
- lambda {
99
- TestModule::TestModel.define_index
100
- }.should_not raise_error
101
- end
102
-
103
- it "should die noisily if there is a non-database error" do
104
- ThinkingSphinx::Index::Builder.stub(:generate) { raise StandardError }
105
-
106
- lambda {
107
- TestModule::TestModel.define_index
108
- }.should raise_error
109
- end
110
- end
111
-
112
- describe "index methods" do
113
- before(:all) do
114
- @person = Person.find(:first)
115
- end
116
-
117
- describe "in_both_indexes?" do
118
- it "should return true if in core and delta indexes" do
119
- @person.should_receive(:in_core_index?).and_return(true)
120
- @person.should_receive(:in_delta_index?).and_return(true)
121
- @person.in_both_indexes?.should be_true
122
- end
123
-
124
- it "should return false if in one index and not the other" do
125
- @person.should_receive(:in_core_index?).and_return(true)
126
- @person.should_receive(:in_delta_index?).and_return(false)
127
- @person.in_both_indexes?.should be_false
128
- end
129
- end
130
-
131
- describe "in_core_index?" do
132
- it "should call in_index? with core" do
133
- @person.should_receive(:in_index?).with('core')
134
- @person.in_core_index?
135
- end
136
- end
137
-
138
- describe "in_delta_index?" do
139
- it "should call in_index? with delta" do
140
- @person.should_receive(:in_index?).with('delta')
141
- @person.in_delta_index?
142
- end
143
- end
144
-
145
- describe "in_index?" do
146
- it "should return true if in the specified index" do
147
- @person.should_receive(:sphinx_document_id).and_return(1)
148
- @person.should_receive(:sphinx_index_name).and_return('person_core')
149
- Person.should_receive(:search_for_id).with(1, 'person_core').and_return(true)
150
-
151
- @person.in_index?('core').should be_true
152
- end
153
- end
154
- end
155
-
156
- describe '.source_of_sphinx_index' do
157
- it "should return self if model defines an index" do
158
- Person.source_of_sphinx_index.should == Person
159
- end
160
-
161
- it "should return the parent if model inherits an index" do
162
- Admin::Person.source_of_sphinx_index.should == Person
163
- end
164
- end
165
-
166
- describe '.to_crc32' do
167
- it "should return an integer" do
168
- Person.to_crc32.should be_a_kind_of(Integer)
169
- end
170
- end
171
-
172
- describe '.to_crc32s' do
173
- it "should return an array" do
174
- Person.to_crc32s.should be_a_kind_of(Array)
175
- end
176
- end
177
-
178
- describe "toggle_deleted method" do
179
- before :each do
180
- ThinkingSphinx.stub!(:sphinx_running? => true)
181
-
182
- @configuration = ThinkingSphinx::Configuration.instance
183
- @configuration.stub!(
184
- :address => "an address",
185
- :port => 123
186
- )
187
- @client = Riddle::Client.new
188
- @client.stub!(:update => true)
189
- @person = Person.find(:first)
190
-
191
- Riddle::Client.stub!(:new => @client)
192
- Person.sphinx_indexes.each { |index| index.stub!(:delta? => false) }
193
- @person.stub!(:in_core_index? => true)
194
- end
195
-
196
- it "should create a client using the Configuration's address and port" do
197
- Riddle::Client.should_receive(:new).with(
198
- @configuration.address, @configuration.port
199
- )
200
-
201
- @person.toggle_deleted
202
- end
203
-
204
- it "should update the core index's deleted flag if in core index" do
205
- @client.should_receive(:update).with(
206
- "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
207
- )
208
-
209
- @person.toggle_deleted
210
- end
211
-
212
- it "shouldn't update the core index's deleted flag if the record isn't in it" do
213
- @person.stub!(:in_core_index? => false)
214
- @client.should_not_receive(:update).with(
215
- "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
216
- )
217
-
218
- @person.toggle_deleted
219
- end
220
-
221
- it "shouldn't attempt to update the deleted flag if sphinx isn't running" do
222
- ThinkingSphinx.stub!(:sphinx_running? => false)
223
- @client.should_not_receive(:update)
224
- @person.should_not_receive(:in_core_index?)
225
-
226
- @person.toggle_deleted
227
- end
228
-
229
- it "should update the delta index's deleted flag if delta indexes are enabled and the instance's delta is true" do
230
- ThinkingSphinx.deltas_enabled = true
231
- Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
232
- @person.delta = true
233
- @client.should_receive(:update).with(
234
- "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
235
- )
236
-
237
- @person.toggle_deleted
238
- end
239
-
240
- it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is false" do
241
- ThinkingSphinx.deltas_enabled = true
242
- Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
243
- @person.delta = false
244
- @client.should_not_receive(:update).with(
245
- "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
246
- )
247
-
248
- @person.toggle_deleted
249
- end
250
-
251
- 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
252
- ThinkingSphinx.deltas_enabled = true
253
- Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
254
- @person.delta = 0
255
- @client.should_not_receive(:update).with(
256
- "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
257
- )
258
-
259
- @person.toggle_deleted
260
- end
261
-
262
- it "shouldn't update the delta index if delta indexes are disabled" do
263
- ThinkingSphinx.deltas_enabled = true
264
- @client.should_not_receive(:update).with(
265
- "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
266
- )
267
-
268
- @person.toggle_deleted
269
- end
270
-
271
- it "should not update either index if updates are disabled" do
272
- ThinkingSphinx.updates_enabled = false
273
- ThinkingSphinx.deltas_enabled = true
274
- Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
275
- @person.delta = true
276
- @client.should_not_receive(:update)
277
-
278
- @person.toggle_deleted
279
- end
280
- end
281
-
282
- describe "sphinx_indexes in the inheritance chain (STI)" do
283
- it "should hand defined indexes on a class down to its child classes" do
284
- Child.sphinx_indexes.should include(*Person.sphinx_indexes)
285
- end
286
-
287
- it "should allow associations to other STI models" do
288
- source = Child.sphinx_indexes.last.sources.first
289
- sql = source.to_riddle_for_core(0, 0).sql_query
290
- sql.gsub!('$start', '0').gsub!('$end', '100')
291
- lambda {
292
- Child.connection.execute(sql)
293
- }.should_not raise_error(ActiveRecord::StatementInvalid)
294
- end
295
- end
296
-
297
- it "should return the sphinx document id as expected" do
298
- person = Person.find(:first)
299
- model_count = ThinkingSphinx.indexed_models.length
300
- offset = ThinkingSphinx.indexed_models.index("Person")
301
-
302
- (person.id * model_count + offset).should == person.sphinx_document_id
303
-
304
- alpha = Alpha.find(:first)
305
- offset = ThinkingSphinx.indexed_models.index("Alpha")
306
-
307
- (alpha.id * model_count + offset).should == alpha.sphinx_document_id
308
-
309
- beta = Beta.find(:first)
310
- offset = ThinkingSphinx.indexed_models.index("Beta")
311
-
312
- (beta.id * model_count + offset).should == beta.sphinx_document_id
313
- end
314
-
315
- describe '#primary_key_for_sphinx' do
316
- before :each do
317
- @person = Person.find(:first)
318
- end
319
-
320
- after :each do
321
- Person.set_sphinx_primary_key nil
322
- end
323
-
324
- it "should return the id by default" do
325
- @person.primary_key_for_sphinx.should == @person.id
326
- end
327
-
328
- it "should use the sphinx primary key to determine the value" do
329
- Person.set_sphinx_primary_key :first_name
330
- @person.primary_key_for_sphinx.should == @person.first_name
331
- end
332
-
333
- it "should not use accessor methods but the attributes hash" do
334
- id = @person.id
335
- @person.stub!(:id => 'unique_hash')
336
- @person.primary_key_for_sphinx.should == id
337
- end
338
- end
339
-
340
- describe '.sphinx_index_names' do
341
- it "should return the core index" do
342
- Alpha.sphinx_index_names.should == ['alpha_core']
343
- end
344
-
345
- it "should return the delta index if enabled" do
346
- Beta.sphinx_index_names.should == ['beta_core', 'beta_delta']
347
- end
348
-
349
- it "should return the superclass with an index definition" do
350
- Parent.sphinx_index_names.should == ['person_core', 'person_delta']
351
- end
352
- end
353
- end
@@ -1,32 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::Deltas::Job do
4
- describe '.cancel_thinking_sphinx_jobs' do
5
- before :each do
6
- ThinkingSphinx::Deltas::Job.stub!(:delete_all => true)
7
- end
8
-
9
- it "should not delete any rows if the delayed_jobs table does not exist" do
10
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => [])
11
- ThinkingSphinx::Deltas::Job.should_not_receive(:delete_all)
12
-
13
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
14
- end
15
-
16
- it "should delete rows if the delayed_jobs table does exist" do
17
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
18
- ThinkingSphinx::Deltas::Job.should_receive(:delete_all)
19
-
20
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
21
- end
22
-
23
- it "should delete only Thinking Sphinx jobs" do
24
- ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
25
- ThinkingSphinx::Deltas::Job.should_receive(:delete_all) do |sql|
26
- sql.should match(/handler LIKE '--- !ruby\/object:ThinkingSphinx::Deltas::\%'/)
27
- end
28
-
29
- ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
30
- end
31
- end
32
- end
@@ -1,45 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::Index do
4
- describe "prefix_fields method" do
5
- before :each do
6
- @index = ThinkingSphinx::Index.new(Person)
7
-
8
- @field_a = stub('field', :prefixes => true)
9
- @field_b = stub('field', :prefixes => false)
10
- @field_c = stub('field', :prefixes => true)
11
-
12
- @index.stub!(:fields => [@field_a, @field_b, @field_c])
13
- end
14
-
15
- it "should return fields that are flagged as prefixed" do
16
- @index.prefix_fields.should include(@field_a)
17
- @index.prefix_fields.should include(@field_c)
18
- end
19
-
20
- it "should not return fields that aren't flagged as prefixed" do
21
- @index.prefix_fields.should_not include(@field_b)
22
- end
23
- end
24
-
25
- describe "infix_fields method" do
26
- before :each do
27
- @index = ThinkingSphinx::Index.new(Person)
28
-
29
- @field_a = stub('field', :infixes => true)
30
- @field_b = stub('field', :infixes => false)
31
- @field_c = stub('field', :infixes => true)
32
-
33
- @index.stub!(:fields => [@field_a, @field_b, @field_c])
34
- end
35
-
36
- it "should return fields that are flagged as infixed" do
37
- @index.infix_fields.should include(@field_a)
38
- @index.infix_fields.should include(@field_c)
39
- end
40
-
41
- it "should not return fields that aren't flagged as infixed" do
42
- @index.infix_fields.should_not include(@field_b)
43
- end
44
- end
45
- end
@@ -1,162 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe 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
- it "should always say Sphinx is running if flagged as being on a remote machine" do
55
- ThinkingSphinx.remote_sphinx = true
56
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
57
-
58
- ThinkingSphinx.sphinx_running?.should be_true
59
- end
60
-
61
- it "should actually pay attention to Sphinx if not on a remote machine" do
62
- ThinkingSphinx.remote_sphinx = false
63
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
64
- ThinkingSphinx.sphinx_running?.should be_false
65
-
66
- ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
67
- ThinkingSphinx.sphinx_running?.should be_true
68
- end
69
-
70
- describe '.version' do
71
- it "should return the version from the stored YAML file" do
72
- version = Jeweler::VersionHelper.new(
73
- File.join(File.dirname(__FILE__), '../..')
74
- ).to_s
75
-
76
- ThinkingSphinx.version.should == version
77
- end
78
- end
79
-
80
- describe "use_group_by_shortcut? method" do
81
- before :each do
82
- adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
83
- unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
84
- pending "No MySQL"
85
- return
86
- end
87
-
88
- @connection = stub('adapter',
89
- :select_all => true,
90
- :class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
91
- :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
92
- )
93
- ::ActiveRecord::Base.stub!(
94
- :connection => @connection
95
- )
96
- end
97
-
98
- it "should return true if no ONLY_FULL_GROUP_BY" do
99
- @connection.stub!(
100
- :select_all => {:a => "OTHER SETTINGS"}
101
- )
102
-
103
- ThinkingSphinx.use_group_by_shortcut?.should be_true
104
- end
105
-
106
- it "should return true if NULL value" do
107
- @connection.stub!(
108
- :select_all => {:a => nil}
109
- )
110
-
111
- ThinkingSphinx.use_group_by_shortcut?.should be_true
112
- end
113
-
114
- it "should return false if ONLY_FULL_GROUP_BY is set" do
115
- @connection.stub!(
116
- :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
117
- )
118
-
119
- ThinkingSphinx.use_group_by_shortcut?.should be_false
120
- end
121
-
122
- it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
123
- @connection.stub!(
124
- :select_all => {
125
- :a => "OTHER SETTINGS",
126
- :b => "ONLY_FULL_GROUP_BY"
127
- }
128
- )
129
-
130
- ThinkingSphinx.use_group_by_shortcut?.should be_false
131
- end
132
-
133
- describe "if not using MySQL" do
134
- before :each do
135
- adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
136
- unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
137
- pending "No PostgreSQL"
138
- return
139
- end
140
-
141
- @connection = stub(adapter).as_null_object
142
- @connection.stub!(
143
- :select_all => true,
144
- :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
145
- )
146
- ::ActiveRecord::Base.stub!(
147
- :connection => @connection
148
- )
149
- end
150
-
151
- it "should return false" do
152
- ThinkingSphinx.use_group_by_shortcut?.should be_false
153
- end
154
-
155
- it "should not call select_all" do
156
- @connection.should_not_receive(:select_all)
157
-
158
- ThinkingSphinx.use_group_by_shortcut?
159
- end
160
- end
161
- end
162
- end
@@ -1,20 +0,0 @@
1
- Copyright (c) 2008 Nick Muerdter
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,16 +0,0 @@
1
- after_commit
2
- ===========
3
-
4
- A Ruby on Rails plugin to add after_commit callbacks. The callbacks that are provided can be used
5
- to trigger events that run only after the entire transaction is complete. This is beneficial
6
- in situations where you are doing asynchronous processing and need committed objects.
7
-
8
- The following callbacks are provided:
9
-
10
- * (1) after_commit
11
- * (2) after_commit_on_create
12
- * (3) after_commit_on_update
13
- * (4) after_commit_on_destroy
14
-
15
- The after_commit callback is run for any object that has just been committed. You can obtain finer
16
- callback control by using the additional <tt>after_commit_on_*</tt> callbacks.
@@ -1,22 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the after_commit plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- desc 'Generate documentation for the after_commit plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'AfterCommit'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
@@ -1,8 +0,0 @@
1
- ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
2
-
3
- Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
4
- klass.send(:include, AfterCommit::ConnectionAdapters)
5
- end
6
- if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
7
- JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
8
- end