warp-thinking-sphinx 1.2.12 → 1.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README.textile +21 -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 +22 -5
  6. data/features/deleting_instances.feature +3 -0
  7. data/features/facets.feature +6 -0
  8. data/features/facets_across_model.feature +2 -2
  9. data/features/searching_across_models.feature +1 -1
  10. data/features/searching_by_index.feature +40 -0
  11. data/features/sphinx_scopes.feature +7 -0
  12. data/features/step_definitions/alpha_steps.rb +14 -1
  13. data/features/step_definitions/beta_steps.rb +1 -1
  14. data/features/step_definitions/common_steps.rb +12 -2
  15. data/features/step_definitions/facet_steps.rb +5 -1
  16. data/features/step_definitions/scope_steps.rb +4 -0
  17. data/features/step_definitions/sphinx_steps.rb +8 -4
  18. data/features/sti_searching.feature +5 -0
  19. data/features/support/{db/database.example.yml → database.example.yml} +0 -0
  20. data/features/support/db/fixtures/foxes.rb +3 -0
  21. data/features/support/db/fixtures/music.rb +4 -0
  22. data/features/support/db/fixtures/robots.rb +1 -1
  23. data/features/support/db/fixtures/tags.rb +1 -1
  24. data/features/support/db/migrations/create_alphas.rb +1 -0
  25. data/features/support/db/migrations/create_genres.rb +3 -0
  26. data/features/support/db/migrations/create_music.rb +6 -0
  27. data/features/support/db/migrations/create_robots.rb +1 -2
  28. data/features/support/env.rb +16 -1
  29. data/features/support/models/alpha.rb +12 -0
  30. data/features/support/models/comment.rb +3 -3
  31. data/features/support/models/fox.rb +5 -0
  32. data/features/support/models/genre.rb +3 -0
  33. data/features/support/models/medium.rb +5 -0
  34. data/features/support/models/music.rb +8 -0
  35. data/features/support/models/post.rb +2 -1
  36. data/features/support/models/robot.rb +4 -0
  37. data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
  38. data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
  39. data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
  40. data/lib/thinking_sphinx.rb +56 -37
  41. data/lib/thinking_sphinx/active_record.rb +257 -192
  42. data/lib/thinking_sphinx/active_record/attribute_updates.rb +10 -12
  43. data/lib/thinking_sphinx/active_record/delta.rb +0 -26
  44. data/lib/thinking_sphinx/active_record/scopes.rb +37 -1
  45. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +1 -1
  46. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +18 -11
  47. data/lib/thinking_sphinx/attribute.rb +19 -4
  48. data/lib/thinking_sphinx/auto_version.rb +22 -0
  49. data/lib/thinking_sphinx/configuration.rb +57 -59
  50. data/lib/thinking_sphinx/context.rb +74 -0
  51. data/lib/thinking_sphinx/deltas.rb +0 -2
  52. data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
  53. data/lib/thinking_sphinx/deploy/capistrano.rb +1 -1
  54. data/lib/thinking_sphinx/facet_search.rb +3 -1
  55. data/lib/thinking_sphinx/index.rb +77 -19
  56. data/lib/thinking_sphinx/index/builder.rb +2 -2
  57. data/lib/thinking_sphinx/search.rb +47 -9
  58. data/lib/thinking_sphinx/search_methods.rb +22 -4
  59. data/lib/thinking_sphinx/source.rb +9 -8
  60. data/lib/thinking_sphinx/source/sql.rb +5 -3
  61. data/lib/thinking_sphinx/tasks.rb +13 -57
  62. data/lib/thinking_sphinx/test.rb +52 -0
  63. data/rails/init.rb +4 -2
  64. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +4 -6
  65. data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +0 -0
  66. data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
  67. data/spec/thinking_sphinx/active_record_spec.rb +622 -0
  68. data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +0 -0
  69. data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +39 -0
  70. data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
  71. data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +27 -61
  72. data/spec/thinking_sphinx/context_spec.rb +119 -0
  73. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +0 -0
  74. data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +0 -0
  75. data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +0 -0
  76. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +0 -0
  77. data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +0 -0
  78. data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +0 -0
  79. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +24 -0
  80. data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +0 -0
  81. data/spec/thinking_sphinx/index_spec.rb +183 -0
  82. data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +0 -0
  83. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +0 -0
  84. data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +41 -0
  85. data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +1 -1
  86. data/spec/thinking_sphinx_spec.rb +204 -0
  87. data/tasks/distribution.rb +6 -20
  88. data/tasks/testing.rb +8 -19
  89. metadata +117 -142
  90. data/VERSION.yml +0 -4
  91. data/features/a.rb +0 -17
  92. data/features/datetime_deltas.feature +0 -66
  93. data/features/delayed_delta_indexing.feature +0 -37
  94. data/features/step_definitions/datetime_delta_steps.rb +0 -15
  95. data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
  96. data/features/support/db/active_record.rb +0 -40
  97. data/features/support/db/fixtures/delayed_betas.rb +0 -10
  98. data/features/support/db/fixtures/thetas.rb +0 -10
  99. data/features/support/db/migrations/create_delayed_betas.rb +0 -17
  100. data/features/support/db/migrations/create_thetas.rb +0 -5
  101. data/features/support/db/mysql.rb +0 -3
  102. data/features/support/db/postgresql.rb +0 -3
  103. data/features/support/models/delayed_beta.rb +0 -7
  104. data/features/support/models/theta.rb +0 -7
  105. data/features/support/post_database.rb +0 -43
  106. data/features/support/z.rb +0 -19
  107. data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
  108. data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
  109. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
  110. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
  111. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
  112. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
  113. data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
  114. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
  115. data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
  116. data/spec/lib/thinking_sphinx_spec.rb +0 -162
  117. data/vendor/after_commit/LICENSE +0 -20
  118. data/vendor/after_commit/README +0 -16
  119. data/vendor/after_commit/Rakefile +0 -22
  120. data/vendor/after_commit/init.rb +0 -8
  121. data/vendor/after_commit/lib/after_commit.rb +0 -45
  122. data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
  123. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
  124. data/vendor/after_commit/test/after_commit_test.rb +0 -53
  125. data/vendor/delayed_job/lib/delayed/job.rb +0 -251
  126. data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
  127. data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
  128. data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
  129. data/vendor/riddle/lib/riddle.rb +0 -30
  130. data/vendor/riddle/lib/riddle/client.rb +0 -635
  131. data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
  132. data/vendor/riddle/lib/riddle/client/message.rb +0 -66
  133. data/vendor/riddle/lib/riddle/client/response.rb +0 -84
  134. data/vendor/riddle/lib/riddle/configuration.rb +0 -33
  135. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
  136. data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
  137. data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
  138. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
  139. data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
  140. data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
  141. data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
  142. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
  143. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
  144. data/vendor/riddle/lib/riddle/controller.rb +0 -53
@@ -1,27 +0,0 @@
1
- module ThinkingSphinx
2
- module Deltas
3
- class FlagAsDeletedJob
4
- attr_accessor :index, :document_id
5
-
6
- def initialize(index, document_id)
7
- @index, @document_id = index, document_id
8
- end
9
-
10
- def perform
11
- return true unless ThinkingSphinx.updates_enabled?
12
-
13
- config = ThinkingSphinx::Configuration.instance
14
- client = Riddle::Client.new config.address, config.port
15
-
16
- client.update(
17
- @index,
18
- ['sphinx_deleted'],
19
- {@document_id => [1]}
20
- ) if ThinkingSphinx.sphinx_running? &&
21
- ThinkingSphinx::Search.search_for_id(@document_id, @index)
22
-
23
- true
24
- end
25
- end
26
- end
27
- end
@@ -1,26 +0,0 @@
1
- module ThinkingSphinx
2
- module Deltas
3
- class Job < Delayed::Job
4
- def self.enqueue(object, priority = 0)
5
- super unless duplicates_exist(object)
6
- end
7
-
8
- def self.cancel_thinking_sphinx_jobs
9
- if connection.tables.include?("delayed_jobs")
10
- delete_all("handler LIKE '--- !ruby/object:ThinkingSphinx::Deltas::%'")
11
- end
12
- end
13
-
14
- private
15
-
16
- def self.duplicates_exist(object)
17
- count(
18
- :conditions => {
19
- :handler => object.to_yaml,
20
- :locked_at => nil
21
- }
22
- ) > 0
23
- end
24
- end
25
- end
26
- end
@@ -1,96 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ThinkingSphinx::ActiveRecord::Scopes do
4
- after :each do
5
- Alpha.remove_sphinx_scopes
6
- end
7
-
8
- it "should be included into models with indexes" do
9
- Alpha.included_modules.should include(ThinkingSphinx::ActiveRecord::Scopes)
10
- end
11
-
12
- it "should not be included into models without indexes" do
13
- Gamma.included_modules.should_not include(
14
- ThinkingSphinx::ActiveRecord::Scopes
15
- )
16
- end
17
-
18
- describe '.sphinx_scope' do
19
- before :each do
20
- Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
21
- end
22
-
23
- it "should define a method on the model" do
24
- Alpha.should respond_to(:by_name)
25
- end
26
- end
27
-
28
- describe '.sphinx_scopes' do
29
- before :each do
30
- Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
31
- end
32
-
33
- it "should return an array of defined scope names as symbols" do
34
- Alpha.sphinx_scopes.should == [:by_name]
35
- end
36
- end
37
-
38
- describe '.remove_sphinx_scopes' do
39
- before :each do
40
- Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
41
- Alpha.remove_sphinx_scopes
42
- end
43
-
44
- it "should remove sphinx scope methods" do
45
- Alpha.should_not respond_to(:by_name)
46
- end
47
-
48
- it "should empty the list of sphinx scopes" do
49
- Alpha.sphinx_scopes.should be_empty
50
- end
51
- end
52
-
53
- describe '.example_scope' do
54
- before :each do
55
- Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
56
- Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
57
- Alpha.sphinx_scope(:with_betas) { {:classes => [Beta]} }
58
- end
59
-
60
- it "should return a ThinkingSphinx::Search object" do
61
- Alpha.by_name('foo').should be_a(ThinkingSphinx::Search)
62
- end
63
-
64
- it "should set the classes option" do
65
- Alpha.by_name('foo').options[:classes].should == [Alpha]
66
- end
67
-
68
- it "should be able to be called on a ThinkingSphinx::Search object" do
69
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
70
- lambda {
71
- search.by_name('foo')
72
- }.should_not raise_error
73
- end
74
-
75
- it "should return the search object it gets called upon" do
76
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
77
- search.by_name('foo').should == search
78
- end
79
-
80
- it "should apply the scope options to the underlying search object" do
81
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
82
- search.by_name('foo').options[:conditions].should == {:name => 'foo'}
83
- end
84
-
85
- it "should combine hash option scopes such as :conditions" do
86
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
87
- search.by_name('foo').by_foo('bar').options[:conditions].
88
- should == {:name => 'foo', :foo => 'bar'}
89
- end
90
-
91
- it "should combine array option scopes such as :classes" do
92
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
93
- search.with_betas.options[:classes].should == [Alpha, Beta]
94
- end
95
- end
96
- end
@@ -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