dpickett-thinking-sphinx 1.1.12 → 1.1.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.textile +19 -0
  2. data/lib/thinking_sphinx.rb +36 -2
  3. data/lib/thinking_sphinx/active_record.rb +18 -3
  4. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +9 -3
  5. data/lib/thinking_sphinx/association.rb +4 -1
  6. data/lib/thinking_sphinx/attribute.rb +85 -43
  7. data/lib/thinking_sphinx/configuration.rb +33 -12
  8. data/lib/thinking_sphinx/deltas.rb +9 -6
  9. data/lib/thinking_sphinx/deltas/datetime_delta.rb +3 -3
  10. data/lib/thinking_sphinx/deltas/default_delta.rb +4 -4
  11. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +1 -1
  12. data/lib/thinking_sphinx/deploy/capistrano.rb +82 -64
  13. data/lib/thinking_sphinx/facet.rb +58 -21
  14. data/lib/thinking_sphinx/facet_collection.rb +12 -13
  15. data/lib/thinking_sphinx/field.rb +3 -1
  16. data/lib/thinking_sphinx/index.rb +28 -353
  17. data/lib/thinking_sphinx/index/builder.rb +255 -232
  18. data/lib/thinking_sphinx/property.rb +29 -2
  19. data/lib/thinking_sphinx/search.rb +32 -96
  20. data/lib/thinking_sphinx/search/facets.rb +104 -0
  21. data/lib/thinking_sphinx/source.rb +150 -0
  22. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  23. data/lib/thinking_sphinx/source/sql.rb +128 -0
  24. data/lib/thinking_sphinx/tasks.rb +42 -8
  25. data/rails/init.rb +14 -0
  26. data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +5 -5
  27. data/spec/unit/thinking_sphinx/active_record/search_spec.rb +4 -4
  28. data/spec/unit/thinking_sphinx/active_record_spec.rb +52 -39
  29. data/spec/unit/thinking_sphinx/association_spec.rb +4 -5
  30. data/spec/unit/thinking_sphinx/attribute_spec.rb +209 -19
  31. data/spec/unit/thinking_sphinx/collection_spec.rb +7 -6
  32. data/spec/unit/thinking_sphinx/configuration_spec.rb +93 -7
  33. data/spec/unit/thinking_sphinx/facet_spec.rb +256 -0
  34. data/spec/unit/thinking_sphinx/field_spec.rb +26 -17
  35. data/spec/unit/thinking_sphinx/index/builder_spec.rb +351 -1
  36. data/spec/unit/thinking_sphinx/index_spec.rb +3 -102
  37. data/spec/unit/thinking_sphinx/rails_additions_spec.rb +13 -5
  38. data/spec/unit/thinking_sphinx/search_spec.rb +154 -29
  39. data/spec/unit/thinking_sphinx/source_spec.rb +217 -0
  40. data/spec/unit/thinking_sphinx_spec.rb +22 -4
  41. data/tasks/distribution.rb +19 -0
  42. data/vendor/riddle/lib/riddle.rb +1 -1
  43. data/vendor/riddle/lib/riddle/configuration/section.rb +7 -1
  44. metadata +26 -3
@@ -0,0 +1,46 @@
1
+ module ThinkingSphinx
2
+ class Source
3
+ module InternalProperties
4
+ def add_internal_attributes_and_facets
5
+ add_internal_attribute :sphinx_internal_id, :integer, @model.primary_key.to_sym
6
+ add_internal_attribute :class_crc, :integer, crc_column, true
7
+ add_internal_attribute :subclass_crcs, :multi, subclasses_to_s
8
+ add_internal_attribute :sphinx_deleted, :integer, "0"
9
+
10
+ add_internal_facet :class_crc
11
+ end
12
+
13
+ def add_internal_attribute(name, type, contents, facet = false)
14
+ return unless attribute_by_alias(name).nil?
15
+
16
+ Attribute.new(self,
17
+ ThinkingSphinx::Index::FauxColumn.new(contents),
18
+ :type => type,
19
+ :as => name,
20
+ :facet => facet,
21
+ :admin => true
22
+ )
23
+ end
24
+
25
+ def add_internal_facet(name)
26
+ return unless facet_by_alias(name).nil?
27
+
28
+ @model.sphinx_facets << ClassFacet.new(attribute_by_alias(name))
29
+ end
30
+
31
+ def attribute_by_alias(attr_alias)
32
+ @attributes.detect { |attrib| attrib.alias == attr_alias }
33
+ end
34
+
35
+ def facet_by_alias(name)
36
+ @model.sphinx_facets.detect { |facet| facet.name == name }
37
+ end
38
+
39
+ def subclasses_to_s
40
+ "'" + (@model.send(:subclasses).collect { |klass|
41
+ klass.to_crc32.to_s
42
+ } << @model.to_crc32.to_s).join(",") + "'"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,128 @@
1
+ module ThinkingSphinx
2
+ class Source
3
+ module SQL
4
+ # Generates the big SQL statement to get the data back for all the fields
5
+ # and attributes, using all the relevant association joins. If you want
6
+ # the version filtered for delta values, send through :delta => true in the
7
+ # options. Won't do much though if the index isn't set up to support a
8
+ # delta sibling.
9
+ #
10
+ # Examples:
11
+ #
12
+ # source.to_sql
13
+ # source.to_sql(:delta => true)
14
+ #
15
+ def to_sql(options={})
16
+ sql = <<-SQL
17
+ SELECT #{ sql_select_clause options[:offset] }
18
+ FROM #{ @model.quoted_table_name }
19
+ #{ all_associations.collect { |assoc| assoc.to_sql }.join(' ') }
20
+ #{ sql_where_clause(options) }
21
+ GROUP BY #{ sql_group_clause }
22
+ SQL
23
+
24
+ sql += " ORDER BY NULL" if adapter.sphinx_identifier == "mysql"
25
+ sql
26
+ end
27
+
28
+ # Simple helper method for the query range SQL - which is a statement that
29
+ # returns minimum and maximum id values. These can be filtered by delta -
30
+ # so pass in :delta => true to get the delta version of the SQL.
31
+ #
32
+ def to_sql_query_range(options={})
33
+ return nil if @index.options[:disable_range]
34
+
35
+ min_statement = adapter.convert_nulls(
36
+ "MIN(#{quote_column(@model.primary_key)})", 1
37
+ )
38
+ max_statement = adapter.convert_nulls(
39
+ "MAX(#{quote_column(@model.primary_key)})", 1
40
+ )
41
+
42
+ sql = "SELECT #{min_statement}, #{max_statement} " +
43
+ "FROM #{@model.quoted_table_name} "
44
+ if self.delta? && !@index.delta_object.clause(@model, options[:delta]).blank?
45
+ sql << "WHERE #{@index.delta_object.clause(@model, options[:delta])}"
46
+ end
47
+
48
+ sql
49
+ end
50
+
51
+ # Simple helper method for the query info SQL - which is a statement that
52
+ # returns the single row for a corresponding id.
53
+ #
54
+ def to_sql_query_info(offset)
55
+ "SELECT * FROM #{@model.quoted_table_name} WHERE " +
56
+ "#{quote_column(@model.primary_key)} = (($id - #{offset}) / #{ThinkingSphinx.indexed_models.size})"
57
+ end
58
+
59
+ def sql_select_clause(offset)
60
+ unique_id_expr = ThinkingSphinx.unique_id_expression(offset)
61
+
62
+ (
63
+ ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} #{unique_id_expr} AS #{quote_column(@model.primary_key)} "] +
64
+ @fields.collect { |field| field.to_select_sql } +
65
+ @attributes.collect { |attribute| attribute.to_select_sql }
66
+ ).compact.join(", ")
67
+ end
68
+
69
+ def sql_where_clause(options)
70
+ logic = []
71
+ logic += [
72
+ "#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} >= $start",
73
+ "#{@model.quoted_table_name}.#{quote_column(@model.primary_key)} <= $end"
74
+ ] unless @index.options[:disable_range]
75
+
76
+ if self.delta? && !@index.delta_object.clause(@model, options[:delta]).blank?
77
+ logic << "#{@index.delta_object.clause(@model, options[:delta])}"
78
+ end
79
+
80
+ logic += (@conditions || [])
81
+ logic.empty? ? "" : "WHERE #{logic.join(' AND ')}"
82
+ end
83
+
84
+ def sql_group_clause
85
+ internal_groupings = []
86
+ if @model.column_names.include?(@model.inheritance_column)
87
+ internal_groupings << "#{@model.quoted_table_name}.#{quote_column(@model.inheritance_column)}"
88
+ end
89
+
90
+ (
91
+ ["#{@model.quoted_table_name}.#{quote_column(@model.primary_key)}"] +
92
+ @fields.collect { |field| field.to_group_sql }.compact +
93
+ @attributes.collect { |attribute| attribute.to_group_sql }.compact +
94
+ @groupings + internal_groupings
95
+ ).join(", ")
96
+ end
97
+
98
+ def sql_query_pre_for_core
99
+ if self.delta? && !@index.delta_object.reset_query(@model).blank?
100
+ [@index.delta_object.reset_query(@model)]
101
+ else
102
+ []
103
+ end
104
+ end
105
+
106
+ def sql_query_pre_for_delta
107
+ [""]
108
+ end
109
+
110
+ def quote_column(column)
111
+ @model.connection.quote_column_name(column)
112
+ end
113
+
114
+ def crc_column
115
+ if @model.table_exists? &&
116
+ @model.column_names.include?(@model.inheritance_column)
117
+
118
+ adapter.cast_to_unsigned(adapter.convert_nulls(
119
+ adapter.crc(adapter.quote_with_table(@model.inheritance_column), true),
120
+ @model.to_crc32
121
+ ))
122
+ else
123
+ @model.to_crc32.to_s
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -2,10 +2,19 @@ require 'fileutils'
2
2
 
3
3
  namespace :thinking_sphinx do
4
4
  task :app_env do
5
- Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
5
+ if defined?(RAILS_ROOT)
6
+ Rake::Task[:environment].invoke
7
+ Rails.configuration.cache_classes = false
8
+ end
9
+
6
10
  Rake::Task[:merb_env].invoke if defined?(Merb)
7
11
  end
8
12
 
13
+ desc "Output the current Thinking Sphinx version"
14
+ task :version => :app_env do
15
+ puts "Thinking Sphinx v" + ThinkingSphinx::Version::String
16
+ end
17
+
9
18
  desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
10
19
  task :running_start => :app_env do
11
20
  Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
@@ -21,9 +30,7 @@ namespace :thinking_sphinx do
21
30
 
22
31
  Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
23
32
 
24
- cmd = "#{config.bin_path}searchd --pidfile --config #{config.config_file}"
25
- puts cmd
26
- system cmd
33
+ system! "#{config.bin_path}#{config.searchd_binary_name} --pidfile --config #{config.config_file}"
27
34
 
28
35
  sleep(2)
29
36
 
@@ -39,7 +46,7 @@ namespace :thinking_sphinx do
39
46
  raise RuntimeError, "searchd is not running." unless sphinx_running?
40
47
  config = ThinkingSphinx::Configuration.instance
41
48
  pid = sphinx_pid
42
- system "#{config.bin_path}searchd --stop --config #{config.config_file}"
49
+ system! "#{config.bin_path}#{config.searchd_binary_name} --stop --config #{config.config_file}"
43
50
  puts "Stopped search daemon (pid #{pid})."
44
51
  end
45
52
 
@@ -64,10 +71,17 @@ namespace :thinking_sphinx do
64
71
  end
65
72
 
66
73
  FileUtils.mkdir_p config.searchd_file_path
67
- cmd = "#{config.bin_path}indexer --config #{config.config_file} --all"
74
+ cmd = "#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --all"
68
75
  cmd << " --rotate" if sphinx_running?
69
- puts cmd
70
- system cmd
76
+
77
+ system! cmd
78
+ end
79
+
80
+ desc "Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx"
81
+ task :rebuild => :app_env do
82
+ Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
83
+ Rake::Task["thinking_sphinx:index"].invoke
84
+ Rake::Task["thinking_sphinx:start"].invoke
71
85
  end
72
86
 
73
87
  namespace :index do
@@ -96,6 +110,8 @@ namespace :thinking_sphinx do
96
110
  end
97
111
 
98
112
  namespace :ts do
113
+ desc "Output the current Thinking Sphinx version"
114
+ task :version => "thinking_sphinx:version"
99
115
  desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
100
116
  task :run => "thinking_sphinx:running_start"
101
117
  desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
@@ -115,6 +131,8 @@ namespace :ts do
115
131
  task :conf => "thinking_sphinx:configure"
116
132
  desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
117
133
  task :config => "thinking_sphinx:configure"
134
+ desc "Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx"
135
+ task :rebuild => "thinking_sphinx:rebuild"
118
136
  desc "Process stored delta index requests"
119
137
  task :dd => "thinking_sphinx:delayed_delta"
120
138
  end
@@ -126,3 +144,19 @@ end
126
144
  def sphinx_running?
127
145
  ThinkingSphinx.sphinx_running?
128
146
  end
147
+
148
+ # a fail-fast, hopefully helpful version of system
149
+ def system!(cmd)
150
+ unless system(cmd)
151
+ raise <<-SYSTEM_CALL_FAILED
152
+ The following command failed:
153
+ #{cmd}
154
+
155
+ This could be caused by a PATH issue in the environment of cron/passenger/etc. Your current PATH:
156
+ #{ENV['PATH']}
157
+ You can set the path to your indexer and searchd binaries using the bin_path property in config/sphinx.yml:
158
+ production:
159
+ bin_path: '/usr/local/bin'
160
+ SYSTEM_CALL_FAILED
161
+ end
162
+ end
@@ -0,0 +1,14 @@
1
+ require 'thinking_sphinx'
2
+ require 'action_controller/dispatcher'
3
+
4
+ ActionController::Dispatcher.to_prepare :thinking_sphinx do
5
+ # Force internationalisation to be loaded.
6
+ if Rails::VERSION::STRING.to_f > 2.2
7
+ I18n.backend.reload!
8
+ I18n.backend.available_locales
9
+ elsif Rails::VERSION::STRING.to_f > 2.1
10
+ I18n.backend.load_translations(*I18n.load_path)
11
+ end
12
+
13
+ ThinkingSphinx::Configuration.instance.load_models
14
+ end
@@ -80,7 +80,8 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
80
80
  :sphinx_document_id => 1
81
81
  )
82
82
 
83
- @client = Riddle::Client.stub_instance(:update => true)
83
+ @client = Riddle::Client.new
84
+ @client.stub!(:update => true)
84
85
  Riddle::Client.stub_method(:new => @client)
85
86
  end
86
87
 
@@ -120,17 +121,16 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
120
121
  end
121
122
 
122
123
  it "shouldn't update the deleted attribute if not in the index" do
123
- @person.send(:index_delta)
124
+ @client.should_not_receive(:update)
124
125
 
125
- @client.should_not have_received(:update)
126
+ @person.send(:index_delta)
126
127
  end
127
128
 
128
129
  it "should update the deleted attribute if in the core index" do
129
130
  @person.stub_method(:in_both_indexes? => true)
131
+ @client.should_receive(:update)
130
132
 
131
133
  @person.send(:index_delta)
132
-
133
- @client.should have_received(:update)
134
134
  end
135
135
  end
136
136
  end
@@ -2,19 +2,19 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe "ThinkingSphinx::ActiveRecord::Search" do
4
4
  it "should add search_for_ids to ActiveRecord::Base" do
5
- ActiveRecord::Base.methods.should include("search_for_ids")
5
+ ActiveRecord::Base.should respond_to("search_for_ids")
6
6
  end
7
7
 
8
8
  it "should add search_for_ids to ActiveRecord::Base" do
9
- ActiveRecord::Base.methods.should include("search")
9
+ ActiveRecord::Base.should respond_to("search")
10
10
  end
11
11
 
12
12
  it "should add search_count to ActiveRecord::Base" do
13
- ActiveRecord::Base.methods.should include("search_count")
13
+ ActiveRecord::Base.should respond_to("search_count")
14
14
  end
15
15
 
16
16
  it "should add search_for_id to ActiveRecord::Base" do
17
- ActiveRecord::Base.methods.should include("search_for_id")
17
+ ActiveRecord::Base.should respond_to("search_for_id")
18
18
  end
19
19
 
20
20
  describe "search_for_ids method" do
@@ -3,7 +3,7 @@ require 'spec/spec_helper'
3
3
  describe "ThinkingSphinx::ActiveRecord" do
4
4
  describe "define_index method" do
5
5
  before :each do
6
- module TestModule
6
+ module ::TestModule
7
7
  class TestModel < ActiveRecord::Base; end
8
8
  end
9
9
 
@@ -14,7 +14,7 @@ describe "ThinkingSphinx::ActiveRecord" do
14
14
  )
15
15
 
16
16
  @index = ThinkingSphinx::Index.stub_instance(:delta? => false)
17
- ThinkingSphinx::Index.stub_method(:new => @index)
17
+ ThinkingSphinx::Index::Builder.stub_method(:generate => @index)
18
18
  end
19
19
 
20
20
  after :each do
@@ -24,17 +24,17 @@ describe "ThinkingSphinx::ActiveRecord" do
24
24
  ThinkingSphinx.indexed_models.delete "TestModule::TestModel"
25
25
  end
26
26
 
27
- it "should return nil and do nothing if indexes are disabled" do
27
+ it "should do nothing if indexes are disabled" do
28
28
  ThinkingSphinx.stub_method(:define_indexes? => false)
29
29
 
30
- TestModule::TestModel.define_index {}.should be_nil
30
+ TestModule::TestModel.define_index {}
31
31
  ThinkingSphinx::Index.should_not have_received(:new)
32
32
 
33
33
  ThinkingSphinx.unstub_method(:define_indexes?)
34
34
  end
35
35
 
36
36
  it "should add a new index to the model" do
37
- TestModule::TestModel.define_index do; end
37
+ TestModule::TestModel.define_index {}
38
38
 
39
39
  TestModule::TestModel.sphinx_indexes.length.should == 1
40
40
  end
@@ -92,6 +92,22 @@ describe "ThinkingSphinx::ActiveRecord" do
92
92
  it "should return the new index" do
93
93
  TestModule::TestModel.define_index.should == @index
94
94
  end
95
+
96
+ it "should die quietly if there is a database error" do
97
+ ThinkingSphinx::Index::Builder.stub_method_to_raise(:generate => Mysql::Error)
98
+
99
+ lambda {
100
+ TestModule::TestModel.define_index
101
+ }.should_not raise_error
102
+ end
103
+
104
+ it "should die noisily if there is a non-database error" do
105
+ ThinkingSphinx::Index::Builder.stub_method_to_raise(:generate => StandardError)
106
+
107
+ lambda {
108
+ TestModule::TestModel.define_index
109
+ }.should raise_error
110
+ end
95
111
  end
96
112
 
97
113
  describe "index methods" do
@@ -144,7 +160,7 @@ describe "ThinkingSphinx::ActiveRecord" do
144
160
  end
145
161
 
146
162
  it "should return the parent if model inherits an index" do
147
- Parent.source_of_sphinx_index.should == Person
163
+ Admin::Person.source_of_sphinx_index.should == Person
148
164
  end
149
165
  end
150
166
 
@@ -169,7 +185,8 @@ describe "ThinkingSphinx::ActiveRecord" do
169
185
  :address => "an address",
170
186
  :port => 123
171
187
  )
172
- @client = Riddle::Client.stub_instance(:update => true)
188
+ @client = Riddle::Client.new
189
+ @client.stub!(:update => true)
173
190
  @person = Person.find(:first)
174
191
 
175
192
  Riddle::Client.stub_method(:new => @client)
@@ -186,87 +203,82 @@ describe "ThinkingSphinx::ActiveRecord" do
186
203
  end
187
204
 
188
205
  it "should update the core index's deleted flag if in core index" do
189
- @person.toggle_deleted
190
-
191
- @client.should have_received(:update).with(
206
+ @client.should_receive(:update).with(
192
207
  "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
193
208
  )
209
+
210
+ @person.toggle_deleted
194
211
  end
195
212
 
196
213
  it "shouldn't update the core index's deleted flag if the record isn't in it" do
197
214
  @person.stub_method(:in_core_index? => false)
198
-
199
- @person.toggle_deleted
200
-
201
- @client.should_not have_received(:update).with(
215
+ @client.should_not_receive(:update).with(
202
216
  "person_core", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
203
217
  )
218
+
219
+ @person.toggle_deleted
204
220
  end
205
221
 
206
222
  it "shouldn't attempt to update the deleted flag if sphinx isn't running" do
207
223
  ThinkingSphinx.stub_method(:sphinx_running? => false)
224
+ @client.should_not_receive(:update)
208
225
 
209
226
  @person.toggle_deleted
210
227
 
211
228
  @person.should_not have_received(:in_core_index?)
212
- @client.should_not have_received(:update)
213
229
  end
214
230
 
215
231
  it "should update the delta index's deleted flag if delta indexes are enabled and the instance's delta is true" do
216
232
  ThinkingSphinx.stub_method(:deltas_enabled? => true)
217
233
  Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
218
234
  @person.delta = true
219
-
220
- @person.toggle_deleted
221
-
222
- @client.should have_received(:update).with(
235
+ @client.should_receive(:update).with(
223
236
  "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
224
237
  )
238
+
239
+ @person.toggle_deleted
225
240
  end
226
241
 
227
242
  it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is false" do
228
243
  ThinkingSphinx.stub_method(:deltas_enabled? => true)
229
244
  Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
230
245
  @person.delta = false
231
-
232
- @person.toggle_deleted
233
-
234
- @client.should_not have_received(:update).with(
246
+ @client.should_not_receive(:update).with(
235
247
  "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
236
248
  )
249
+
250
+ @person.toggle_deleted
237
251
  end
238
252
 
239
253
  it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is equivalent to false" do
240
254
  ThinkingSphinx.stub_method(:deltas_enabled? => true)
241
255
  Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
242
256
  @person.delta = 0
243
-
244
- @person.toggle_deleted
245
-
246
- @client.should_not have_received(:update).with(
257
+ @client.should_not_receive(:update).with(
247
258
  "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
248
259
  )
260
+
261
+ @person.toggle_deleted
249
262
  end
250
263
 
251
264
  it "shouldn't update the delta index if delta indexes are disabled" do
252
265
  ThinkingSphinx.stub_method(:deltas_enabled? => true)
253
- @person.toggle_deleted
254
-
255
- @client.should_not have_received(:update).with(
266
+ @client.should_not_receive(:update).with(
256
267
  "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
257
268
  )
269
+
270
+ @person.toggle_deleted
258
271
  end
259
272
 
260
273
  it "should not update the delta index if delta indexing is disabled" do
261
274
  ThinkingSphinx.stub_method(:deltas_enabled? => false)
262
275
  Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
263
276
  @person.delta = true
264
-
265
- @person.toggle_deleted
266
-
267
- @client.should_not have_received(:update).with(
277
+ @client.should_not_receive(:update).with(
268
278
  "person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => 1}
269
279
  )
280
+
281
+ @person.toggle_deleted
270
282
  end
271
283
 
272
284
  it "should not update either index if updates are disabled" do
@@ -276,10 +288,9 @@ describe "ThinkingSphinx::ActiveRecord" do
276
288
  )
277
289
  Person.sphinx_indexes.each { |index| index.stub_method(:delta? => true) }
278
290
  @person.delta = true
291
+ @client.should_not_receive(:update)
279
292
 
280
293
  @person.toggle_deleted
281
-
282
- @client.should_not have_received(:update)
283
294
  end
284
295
  end
285
296
 
@@ -289,10 +300,12 @@ describe "ThinkingSphinx::ActiveRecord" do
289
300
  end
290
301
 
291
302
  it "should allow associations to other STI models" do
292
- Child.sphinx_indexes.last.link!
293
- sql = Child.sphinx_indexes.last.to_riddle_for_core(0, 0).sql_query
303
+ source = Child.sphinx_indexes.last.sources.first
304
+ sql = source.to_riddle_for_core(0, 0).sql_query
294
305
  sql.gsub!('$start', '0').gsub!('$end', '100')
295
- lambda { Child.connection.execute(sql) }.should_not raise_error(ActiveRecord::StatementInvalid)
306
+ lambda {
307
+ Child.connection.execute(sql)
308
+ }.should_not raise_error(ActiveRecord::StatementInvalid)
296
309
  end
297
310
  end
298
311