thinking-sphinx 1.5.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/README.textile +15 -48
  2. data/VERSION +1 -0
  3. data/features/attribute_transformation.feature +7 -7
  4. data/features/attribute_updates.feature +16 -18
  5. data/features/deleting_instances.feature +13 -16
  6. data/features/excerpts.feature +0 -8
  7. data/features/facets.feature +19 -25
  8. data/features/handling_edits.feature +20 -25
  9. data/features/searching_across_models.feature +1 -1
  10. data/features/searching_by_index.feature +5 -6
  11. data/features/searching_by_model.feature +29 -29
  12. data/features/sphinx_scopes.feature +0 -26
  13. data/features/step_definitions/common_steps.rb +6 -18
  14. data/features/step_definitions/scope_steps.rb +0 -4
  15. data/features/step_definitions/search_steps.rb +4 -9
  16. data/features/support/env.rb +10 -3
  17. data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -8
  18. data/features/thinking_sphinx/db/fixtures/cats.rb +1 -1
  19. data/features/thinking_sphinx/db/fixtures/dogs.rb +1 -1
  20. data/features/thinking_sphinx/db/fixtures/foxes.rb +1 -1
  21. data/features/thinking_sphinx/db/fixtures/people.rb +1 -1
  22. data/features/thinking_sphinx/db/fixtures/posts.rb +1 -5
  23. data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -1
  24. data/features/thinking_sphinx/models/alpha.rb +0 -1
  25. data/features/thinking_sphinx/models/beta.rb +0 -5
  26. data/features/thinking_sphinx/models/developer.rb +1 -6
  27. data/features/thinking_sphinx/models/music.rb +1 -3
  28. data/features/thinking_sphinx/models/person.rb +1 -2
  29. data/features/thinking_sphinx/models/post.rb +0 -1
  30. data/lib/cucumber/thinking_sphinx/external_world.rb +4 -8
  31. data/lib/cucumber/thinking_sphinx/internal_world.rb +27 -36
  32. data/lib/thinking_sphinx.rb +60 -132
  33. data/lib/thinking_sphinx/active_record.rb +98 -124
  34. data/lib/thinking_sphinx/active_record/attribute_updates.rb +13 -17
  35. data/lib/thinking_sphinx/active_record/delta.rb +15 -21
  36. data/lib/thinking_sphinx/active_record/has_many_association.rb +23 -16
  37. data/lib/thinking_sphinx/active_record/scopes.rb +0 -18
  38. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +15 -63
  39. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -4
  40. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +24 -65
  41. data/lib/thinking_sphinx/association.rb +11 -36
  42. data/lib/thinking_sphinx/attribute.rb +85 -92
  43. data/lib/thinking_sphinx/auto_version.rb +3 -21
  44. data/lib/thinking_sphinx/class_facet.rb +3 -8
  45. data/lib/thinking_sphinx/configuration.rb +58 -114
  46. data/lib/thinking_sphinx/context.rb +20 -22
  47. data/lib/thinking_sphinx/core/array.rb +13 -0
  48. data/lib/thinking_sphinx/deltas.rb +0 -2
  49. data/lib/thinking_sphinx/deltas/default_delta.rb +22 -18
  50. data/lib/thinking_sphinx/deploy/capistrano.rb +31 -30
  51. data/lib/thinking_sphinx/excerpter.rb +1 -2
  52. data/lib/thinking_sphinx/facet.rb +35 -45
  53. data/lib/thinking_sphinx/facet_search.rb +24 -58
  54. data/lib/thinking_sphinx/field.rb +0 -18
  55. data/lib/thinking_sphinx/index.rb +36 -38
  56. data/lib/thinking_sphinx/index/builder.rb +59 -74
  57. data/lib/thinking_sphinx/property.rb +45 -66
  58. data/lib/thinking_sphinx/railtie.rb +35 -0
  59. data/lib/thinking_sphinx/search.rb +250 -506
  60. data/lib/thinking_sphinx/source.rb +31 -50
  61. data/lib/thinking_sphinx/source/internal_properties.rb +3 -8
  62. data/lib/thinking_sphinx/source/sql.rb +31 -71
  63. data/lib/thinking_sphinx/tasks.rb +27 -48
  64. data/spec/thinking_sphinx/active_record/delta_spec.rb +41 -36
  65. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -96
  66. data/spec/thinking_sphinx/active_record/scopes_spec.rb +29 -29
  67. data/spec/thinking_sphinx/active_record_spec.rb +169 -140
  68. data/spec/thinking_sphinx/association_spec.rb +2 -20
  69. data/spec/thinking_sphinx/attribute_spec.rb +97 -101
  70. data/spec/thinking_sphinx/auto_version_spec.rb +11 -75
  71. data/spec/thinking_sphinx/configuration_spec.rb +62 -63
  72. data/spec/thinking_sphinx/context_spec.rb +66 -66
  73. data/spec/thinking_sphinx/facet_search_spec.rb +99 -99
  74. data/spec/thinking_sphinx/facet_spec.rb +4 -30
  75. data/spec/thinking_sphinx/field_spec.rb +3 -17
  76. data/spec/thinking_sphinx/index/builder_spec.rb +132 -169
  77. data/spec/thinking_sphinx/index_spec.rb +39 -45
  78. data/spec/thinking_sphinx/search_methods_spec.rb +33 -37
  79. data/spec/thinking_sphinx/search_spec.rb +269 -491
  80. data/spec/thinking_sphinx/source_spec.rb +48 -62
  81. data/spec/thinking_sphinx_spec.rb +49 -49
  82. data/tasks/distribution.rb +46 -0
  83. data/tasks/testing.rb +74 -0
  84. metadata +123 -199
  85. data/features/field_sorting.feature +0 -18
  86. data/features/thinking_sphinx/db/.gitignore +0 -1
  87. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
  88. data/features/thinking_sphinx/models/andrew.rb +0 -17
  89. data/lib/thinking-sphinx.rb +0 -1
  90. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
  91. data/lib/thinking_sphinx/bundled_search.rb +0 -40
  92. data/lib/thinking_sphinx/connection.rb +0 -71
  93. data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
  94. data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
  95. data/lib/thinking_sphinx/rails_additions.rb +0 -181
  96. data/spec/fixtures/data.sql +0 -32
  97. data/spec/fixtures/database.yml.default +0 -3
  98. data/spec/fixtures/models.rb +0 -161
  99. data/spec/fixtures/structure.sql +0 -146
  100. data/spec/spec_helper.rb +0 -54
  101. data/spec/sphinx_helper.rb +0 -67
  102. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
  103. data/spec/thinking_sphinx/connection_spec.rb +0 -77
  104. data/spec/thinking_sphinx/rails_additions_spec.rb +0 -203
@@ -44,30 +44,12 @@ describe ThinkingSphinx::Association do
44
44
  end
45
45
 
46
46
  it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
47
- Person.stub!(:reflect_on_association).exactly(3).times.
48
- and_return(@poly_reflection, nil, nil)
47
+ Person.stub!(:reflect_on_association => @poly_reflection)
49
48
  ThinkingSphinx::Association.should_receive(:casted_options).with(
50
49
  Person, @poly_reflection
51
50
  ).twice
52
51
  ::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
53
- with(:has_many, :polly_Person, {:casted => :options}, "AR").twice.
54
- and_return(@non_poly_reflection)
55
- ThinkingSphinx::Association.should_receive(:new).with(
56
- nil, @non_poly_reflection
57
- ).twice
58
-
59
- ThinkingSphinx::Association.children(Person, :assoc)
60
- end
61
-
62
- it "should use existing non-polymorphic 'casted' associations" do
63
- Person.stub!(:reflect_on_association).exactly(3).times.
64
- and_return(@poly_reflection, nil, @non_poly_reflection)
65
- ThinkingSphinx::Association.should_receive(:casted_options).with(
66
- Person, @poly_reflection
67
- ).once
68
- ::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
69
- with(:has_many, :polly_Person, {:casted => :options}, "AR").once.
70
- and_return(@non_poly_reflection)
52
+ with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
71
53
  ThinkingSphinx::Association.should_receive(:new).with(
72
54
  nil, @non_poly_reflection
73
55
  ).twice
@@ -68,22 +68,13 @@ describe ThinkingSphinx::Attribute do
68
68
 
69
69
  attribute.to_select_sql.should == "CONCAT_WS(' ', IFNULL(`cricket_teams`.`name`, ''), IFNULL(`football_teams`.`name`, ''), IFNULL(`football_teams`.`league`, '')) AS `team`"
70
70
  end
71
-
72
- it "should return nil if polymorphic association data does not exist" do
73
- attribute = ThinkingSphinx::Attribute.new(@source,
74
- [ThinkingSphinx::Index::FauxColumn.new(:source, :id)],
75
- :as => :source_id, :type => :integer
76
- )
77
-
78
- attribute.to_select_sql.should be_nil
79
- end
80
71
  end
81
72
 
82
73
  describe '#is_many?' do
83
74
  before :each do
84
- @assoc_a = ThinkingSphinx::Association.new(nil, nil)
85
- @assoc_b = ThinkingSphinx::Association.new(nil, nil)
86
- @assoc_c = ThinkingSphinx::Association.new(nil, nil)
75
+ @assoc_a = stub('assoc', :is_many? => true)
76
+ @assoc_b = stub('assoc', :is_many? => true)
77
+ @assoc_c = stub('assoc', :is_many? => true)
87
78
 
88
79
  @attribute = ThinkingSphinx::Attribute.new(
89
80
  @source, [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
@@ -91,9 +82,6 @@ describe ThinkingSphinx::Attribute do
91
82
  @attribute.associations = {
92
83
  :a => @assoc_a, :b => @assoc_b, :c => @assoc_c
93
84
  }
94
- @attribute.associations.values.each { |assoc|
95
- assoc.stub!(:is_many? => true)
96
- }
97
85
  end
98
86
 
99
87
  it "should return true if all associations return true to is_many?" do
@@ -298,176 +286,184 @@ describe ThinkingSphinx::Attribute do
298
286
  end
299
287
 
300
288
  describe "MVA with source query" do
301
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
302
- [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
303
- :as => :tag_ids, :source => :query)
304
- }
305
- let(:adapter) { attribute.send(:adapter) }
289
+ before :each do
290
+ @attribute = ThinkingSphinx::Attribute.new(@source,
291
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
292
+ :as => :tag_ids, :source => :query
293
+ )
294
+ end
306
295
 
307
296
  it "should use a query" do
308
- attribute.type_to_config.should == :sql_attr_multi
297
+ @attribute.type_to_config.should == :sql_attr_multi
309
298
 
310
- declaration, query = attribute.config_value.split('; ')
299
+ declaration, query = @attribute.config_value.split('; ')
311
300
  declaration.should == "uint tag_ids from query"
312
- query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
301
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
313
302
  end
314
303
  end
315
304
 
316
305
  describe "MVA with source query for a delta source" do
317
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
318
- [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
319
- :as => :tag_ids, :source => :query)
320
- }
321
- let(:adapter) { attribute.send(:adapter) }
306
+ before :each do
307
+ @attribute = ThinkingSphinx::Attribute.new(@source,
308
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
309
+ :as => :tag_ids, :source => :query
310
+ )
311
+ end
322
312
 
323
313
  it "should use a query" do
324
- attribute.type_to_config.should == :sql_attr_multi
314
+ @attribute.type_to_config.should == :sql_attr_multi
325
315
 
326
- declaration, query = attribute.config_value(nil, true).split('; ')
316
+ declaration, query = @attribute.config_value(nil, true).split('; ')
327
317
  declaration.should == "uint tag_ids from query"
328
- query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
318
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
329
319
  end
330
320
  end
331
321
 
332
322
  describe "MVA via a HABTM association with a source query" do
333
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
334
- [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
335
- :as => :link_ids, :source => :query)
336
- }
337
- let(:adapter) { attribute.send(:adapter) }
323
+ before :each do
324
+ @attribute = ThinkingSphinx::Attribute.new(@source,
325
+ [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
326
+ :as => :link_ids, :source => :query
327
+ )
328
+ end
338
329
 
339
330
  it "should use a ranged query" do
340
- attribute.type_to_config.should == :sql_attr_multi
331
+ @attribute.type_to_config.should == :sql_attr_multi
341
332
 
342
- declaration, query = attribute.config_value.split('; ')
333
+ declaration, query = @attribute.config_value.split('; ')
343
334
  declaration.should == "uint link_ids from query"
344
- query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
335
+ query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
345
336
  end
346
337
  end
347
338
 
348
339
  describe "MVA with ranged source query" do
349
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
350
- [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
351
- :as => :tag_ids, :source => :ranged_query)
352
- }
353
- let(:adapter) { attribute.send(:adapter) }
340
+ before :each do
341
+ @attribute = ThinkingSphinx::Attribute.new(@source,
342
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
343
+ :as => :tag_ids, :source => :ranged_query
344
+ )
345
+ end
354
346
 
355
347
  it "should use a ranged query" do
356
- attribute.type_to_config.should == :sql_attr_multi
348
+ @attribute.type_to_config.should == :sql_attr_multi
357
349
 
358
- declaration, query, range_query = attribute.config_value.split('; ')
350
+ declaration, query, range_query = @attribute.config_value.split('; ')
359
351
  declaration.should == "uint tag_ids from ranged-query"
360
- query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
352
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
361
353
  range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
362
354
  end
363
355
  end
364
356
 
365
357
  describe "MVA with ranged source query for a delta source" do
366
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
367
- [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
368
- :as => :tag_ids, :source => :ranged_query)
369
- }
370
- let(:adapter) { attribute.send(:adapter) }
358
+ before :each do
359
+ @attribute = ThinkingSphinx::Attribute.new(@source,
360
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
361
+ :as => :tag_ids, :source => :ranged_query
362
+ )
363
+ end
371
364
 
372
365
  it "should use a ranged query" do
373
- attribute.type_to_config.should == :sql_attr_multi
366
+ @attribute.type_to_config.should == :sql_attr_multi
374
367
 
375
- declaration, query, range_query = attribute.config_value(nil, true).split('; ')
368
+ declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
376
369
  declaration.should == "uint tag_ids from ranged-query"
377
- query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
370
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
378
371
  range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
379
372
  end
380
373
  end
381
374
 
382
375
  describe "MVA via a has-many :through with a ranged source query" do
383
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
384
- [ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
385
- :as => :football_team_ids, :source => :ranged_query)
386
- }
387
- let(:adapter) { attribute.send(:adapter) }
376
+ before :each do
377
+ @attribute = ThinkingSphinx::Attribute.new(@source,
378
+ [ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
379
+ :as => :football_team_ids, :source => :ranged_query
380
+ )
381
+ end
388
382
 
389
383
  it "should use a ranged query" do
390
- attribute.type_to_config.should == :sql_attr_multi
384
+ @attribute.type_to_config.should == :sql_attr_multi
391
385
 
392
- declaration, query, range_query = attribute.config_value.split('; ')
386
+ declaration, query, range_query = @attribute.config_value.split('; ')
393
387
  declaration.should == "uint football_team_ids from ranged-query"
394
- query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
388
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
395
389
  range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
396
390
  end
397
391
  end
398
392
 
399
393
  describe "MVA via a has-many :through using a foreign key with a ranged source query" do
400
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
401
- [ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
402
- :as => :friend_ids, :source => :ranged_query)
403
- }
404
- let(:adapter) { attribute.send(:adapter) }
394
+ before :each do
395
+ @attribute = ThinkingSphinx::Attribute.new(@source,
396
+ [ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
397
+ :as => :friend_ids, :source => :ranged_query
398
+ )
399
+ end
405
400
 
406
401
  it "should use a ranged query" do
407
- attribute.type_to_config.should == :sql_attr_multi
402
+ @attribute.type_to_config.should == :sql_attr_multi
408
403
 
409
- declaration, query, range_query = attribute.config_value.split('; ')
404
+ declaration, query, range_query = @attribute.config_value.split('; ')
410
405
  declaration.should == "uint friend_ids from ranged-query"
411
- query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
406
+ query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
412
407
  range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
413
408
  end
414
409
  end
415
410
 
416
411
  describe "MVA via a HABTM with a ranged source query" do
417
- let(:attribute) { ThinkingSphinx::Attribute.new(@source,
418
- [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
419
- :as => :link_ids, :source => :ranged_query)
420
- }
421
- let(:adapter) { attribute.send(:adapter) }
412
+ before :each do
413
+ @attribute = ThinkingSphinx::Attribute.new(@source,
414
+ [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
415
+ :as => :link_ids, :source => :ranged_query
416
+ )
417
+ end
422
418
 
423
419
  it "should use a ranged query" do
424
- attribute.type_to_config.should == :sql_attr_multi
420
+ @attribute.type_to_config.should == :sql_attr_multi
425
421
 
426
- declaration, query, range_query = attribute.config_value.split('; ')
422
+ declaration, query, range_query = @attribute.config_value.split('; ')
427
423
  declaration.should == "uint link_ids from ranged-query"
428
- query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
424
+ query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
429
425
  range_query.should == "SELECT MIN(`links_people`.`person_id`), MAX(`links_people`.`person_id`) FROM `links_people`"
430
426
  end
431
427
  end
432
428
 
433
429
  describe "MVA via two has-many associations with a ranged source query" do
434
- let(:index) { ThinkingSphinx::Index.new(Alpha) }
435
- let(:source) { ThinkingSphinx::Source.new(index) }
436
- let(:attribute) { ThinkingSphinx::Attribute.new(source,
437
- [ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
438
- :as => :gamma_values, :source => :ranged_query)
439
- }
440
- let(:adapter) { attribute.send(:adapter) }
430
+ before :each do
431
+ @index = ThinkingSphinx::Index.new(Alpha)
432
+ @source = ThinkingSphinx::Source.new(@index)
433
+ @attribute = ThinkingSphinx::Attribute.new(@source,
434
+ [ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
435
+ :as => :gamma_values, :source => :ranged_query
436
+ )
437
+ end
441
438
 
442
439
  it "should use a ranged query" do
443
- attribute.type_to_config.should == :sql_attr_multi
440
+ @attribute.type_to_config.should == :sql_attr_multi
444
441
 
445
- declaration, query, range_query = attribute.config_value.split('; ')
442
+ declaration, query, range_query = @attribute.config_value.split('; ')
446
443
  declaration.should == "uint gamma_values from ranged-query"
447
- query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end"
444
+ query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON `gammas`.`beta_id` = `betas`.`id` WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end"
448
445
  range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
449
446
  end
450
447
  end
451
448
 
452
449
  describe "MVA via two has-many associations with a ranged source query for a delta source" do
453
- let(:index) { ThinkingSphinx::Index.new(Alpha) }
454
- let(:source) { ThinkingSphinx::Source.new(index) }
455
- let(:attribute) { ThinkingSphinx::Attribute.new(source,
456
- [ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
457
- :as => :gamma_values, :source => :ranged_query)
458
- }
459
- let(:adapter) { attribute.send(:adapter) }
460
-
461
450
  before :each do
462
- index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new index, index.local_options
451
+ @index = ThinkingSphinx::Index.new(Alpha)
452
+ @source = ThinkingSphinx::Source.new(@index)
453
+ @attribute = ThinkingSphinx::Attribute.new(@source,
454
+ [ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
455
+ :as => :gamma_values, :source => :ranged_query
456
+ )
457
+
458
+ @index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
463
459
  end
464
460
 
465
461
  it "should use a ranged query" do
466
- attribute.type_to_config.should == :sql_attr_multi
462
+ @attribute.type_to_config.should == :sql_attr_multi
467
463
 
468
- declaration, query, range_query = attribute.config_value(nil, true).split('; ')
464
+ declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
469
465
  declaration.should == "uint gamma_values from ranged-query"
470
- query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)"
466
+ query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON `gammas`.`beta_id` = `betas`.`id` WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)"
471
467
  range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
472
468
  end
473
469
  end
@@ -5,97 +5,33 @@ describe ThinkingSphinx::AutoVersion do
5
5
  before :each do
6
6
  @config = ThinkingSphinx::Configuration.instance
7
7
  end
8
-
8
+
9
9
  it "should require 0.9.8 if that is the detected version" do
10
10
  ThinkingSphinx::AutoVersion.should_receive(:require).
11
11
  with('riddle/0.9.8')
12
-
12
+
13
13
  @config.stub!(:version => '0.9.8')
14
14
  ThinkingSphinx::AutoVersion.detect
15
15
  end
16
-
16
+
17
17
  it "should require 0.9.9 if that is the detected version" do
18
18
  ThinkingSphinx::AutoVersion.should_receive(:require).
19
19
  with('riddle/0.9.9')
20
-
20
+
21
21
  @config.stub!(:version => '0.9.9')
22
22
  ThinkingSphinx::AutoVersion.detect
23
23
  end
24
-
25
- it "should require 1.10-beta if that is the detected version" do
26
- ThinkingSphinx::AutoVersion.should_receive(:require).
27
- with('riddle/1.10')
28
-
29
- @config.stub!(:version => '1.10-beta')
30
- ThinkingSphinx::AutoVersion.detect
31
- end
32
-
33
- it "should require 1.10-beta if using 1.10-beta compiled with id64 support" do
34
- ThinkingSphinx::AutoVersion.should_receive(:require).
35
- with('riddle/1.10')
36
-
37
- @config.stub!(:version => '1.10-id64-beta')
38
- ThinkingSphinx::AutoVersion.detect
39
- end
40
-
41
- it "should require 2.0.1 if using Sphinx 2.0.1 beta" do
42
- ThinkingSphinx::AutoVersion.should_receive(:require).
43
- with('riddle/2.0.1')
44
-
45
- @config.stub!(:version => '2.0.1-beta')
46
- ThinkingSphinx::AutoVersion.detect
47
- end
48
-
49
- it "should require 2.0.1 if using Sphinx 2.0.2 dev" do
50
- ThinkingSphinx::AutoVersion.should_receive(:require).
51
- with('riddle/2.0.1')
52
-
53
- @config.stub!(:version => '2.0.2-dev')
54
- ThinkingSphinx::AutoVersion.detect
55
- end
56
-
57
- it "should require 2.1.0 if using Sphinx 2.0.3" do
58
- ThinkingSphinx::AutoVersion.should_receive(:require).
59
- with('riddle/2.1.0')
60
-
61
- @config.stub!(:version => '2.0.3-release')
62
- ThinkingSphinx::AutoVersion.detect
63
- end
64
-
65
- it "should require 2.1.0 if using Sphinx 2.0.3" do
66
- ThinkingSphinx::AutoVersion.should_receive(:require).
67
- with('riddle/2.1.0')
68
-
69
- @config.stub!(:version => '2.0.4-release')
70
- ThinkingSphinx::AutoVersion.detect
71
- end
72
-
73
- it "should require 2.1.0 if using Sphinx 2.0.3" do
74
- ThinkingSphinx::AutoVersion.should_receive(:require).
75
- with('riddle/2.1.0')
76
-
77
- @config.stub!(:version => '2.0.5-release')
78
- ThinkingSphinx::AutoVersion.detect
79
- end
80
-
81
- it "should require 2.1.0 if using Sphinx 2.1.0 dev" do
82
- ThinkingSphinx::AutoVersion.should_receive(:require).
83
- with('riddle/2.1.0')
84
-
85
- @config.stub!(:version => '2.1.0-dev')
86
- ThinkingSphinx::AutoVersion.detect
87
- end
88
-
89
- it "should output a warning if the detected version is unsupported" do
90
- STDERR.should_receive(:puts).with(/unsupported/i)
91
-
24
+
25
+ it "should output a warning if the detected version is something else" do
26
+ STDERR.should_receive(:puts)
27
+
92
28
  @config.stub!(:version => '0.9.7')
93
29
  ThinkingSphinx::AutoVersion.detect
94
30
  end
95
-
31
+
96
32
  it "should output a warning if the version cannot be determined" do
97
- STDERR.should_receive(:puts).at_least(:once)
98
-
33
+ STDERR.should_receive(:puts)
34
+
99
35
  @config.stub!(:version => nil)
100
36
  ThinkingSphinx::AutoVersion.detect
101
37
  end
@@ -3,33 +3,22 @@ require 'spec_helper'
3
3
  describe ThinkingSphinx::Configuration do
4
4
  describe "environment class method" do
5
5
  before :each do
6
- ThinkingSphinx::Configuration.reset_environment
7
-
6
+ Thread.current[:thinking_sphinx_environment] = nil
7
+
8
8
  ENV["RAILS_ENV"] = nil
9
9
  end
10
10
 
11
- it "should use the Merb environment value if set" do
12
- unless defined?(Merb)
13
- module ::Merb; end
14
- end
15
-
16
- ThinkingSphinx::Configuration.stub!(:defined? => true)
17
- Merb.stub!(:environment => "merb_production")
18
- ThinkingSphinx::Configuration.environment.should == "merb_production"
19
-
20
- Object.send :remove_const, :Merb
21
- end
22
-
23
- it "should use RAILS_ENV if set" do
24
- RAILS_ENV = 'global_rails'
25
-
11
+ it "should use Rails.env if set" do
12
+ was = Rails.env
13
+ Rails.env = 'global_rails'
14
+
26
15
  ThinkingSphinx::Configuration.environment.should == 'global_rails'
27
-
28
- Object.send :remove_const, :RAILS_ENV
16
+
17
+ Rails.env = was
29
18
  end
30
19
 
31
20
  it "should use the Rails environment value if set" do
32
- ENV["RAILS_ENV"] = "rails_production"
21
+ Rails.stub!(:env => "rails_production")
33
22
  ThinkingSphinx::Configuration.environment.should == "rails_production"
34
23
  end
35
24
 
@@ -37,31 +26,31 @@ describe ThinkingSphinx::Configuration do
37
26
  ThinkingSphinx::Configuration.environment.should == "development"
38
27
  end
39
28
  end
40
-
29
+
41
30
  describe '#version' do
42
31
  before :each do
43
32
  @config = ThinkingSphinx::Configuration.instance
44
33
  @config.reset
45
34
  end
46
-
35
+
47
36
  it "should use the given version from sphinx.yml if there is one" do
48
- open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
37
+ open("#{Rails.root}/config/sphinx.yml", "w") do |f|
49
38
  f.write YAML.dump({'development' => {'version' => '0.9.7'}})
50
39
  end
51
40
  @config.reset
52
-
41
+
53
42
  @config.version.should == '0.9.7'
54
-
55
- FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
43
+
44
+ FileUtils.rm "#{Rails.root}/config/sphinx.yml"
56
45
  end
57
-
46
+
58
47
  it "should detect the version from Riddle otherwise" do
59
48
  controller = @config.controller
60
49
  controller.stub!(:sphinx_version => '0.9.6')
61
-
50
+
62
51
  Riddle::Controller.stub!(:new => controller)
63
52
  @config.reset
64
-
53
+
65
54
  @config.version.should == '0.9.6'
66
55
  end
67
56
  end
@@ -92,7 +81,7 @@ describe ThinkingSphinx::Configuration do
92
81
  }
93
82
  }
94
83
 
95
- open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
84
+ open("#{Rails.root}/config/sphinx.yml", "w") do |f|
96
85
  f.write YAML.dump(@settings)
97
86
  end
98
87
  end
@@ -108,7 +97,7 @@ describe ThinkingSphinx::Configuration do
108
97
  end
109
98
 
110
99
  after :each do
111
- FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
100
+ FileUtils.rm "#{Rails.root}/config/sphinx.yml"
112
101
  end
113
102
  end
114
103
 
@@ -118,8 +107,6 @@ describe ThinkingSphinx::Configuration do
118
107
  config.app_root = "/here/somewhere"
119
108
  end
120
109
  ThinkingSphinx::Configuration.instance.app_root.should == "/here/somewhere"
121
-
122
- ThinkingSphinx::Configuration.instance.reset
123
110
  end
124
111
  end
125
112
 
@@ -135,14 +122,14 @@ describe ThinkingSphinx::Configuration do
135
122
  }
136
123
  }
137
124
 
138
- open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
125
+ open("#{Rails.root}/config/sphinx.yml", "w") do |f|
139
126
  f.write YAML.dump(@settings)
140
127
  end
141
128
 
142
129
  ThinkingSphinx::Configuration.instance.send(:parse_config)
143
130
  ThinkingSphinx::Configuration.instance.bin_path.should match(/\/$/)
144
131
 
145
- FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
132
+ FileUtils.rm "#{Rails.root}/config/sphinx.yml"
146
133
  end
147
134
  end
148
135
 
@@ -152,7 +139,7 @@ describe ThinkingSphinx::Configuration do
152
139
  "development" => {"disable_range" => true}
153
140
  }
154
141
 
155
- open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
142
+ open("#{Rails.root}/config/sphinx.yml", "w") do |f|
156
143
  f.write YAML.dump(@settings)
157
144
  end
158
145
 
@@ -165,13 +152,13 @@ describe ThinkingSphinx::Configuration do
165
152
  end
166
153
 
167
154
  after :each do
168
- FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
155
+ FileUtils.rm "#{Rails.root}/config/sphinx.yml"
169
156
  end
170
157
  end
171
158
 
172
159
  it "should insert set index options into the configuration file" do
173
160
  config = ThinkingSphinx::Configuration.instance
174
-
161
+
175
162
  ThinkingSphinx::Configuration::IndexOptions.each do |option|
176
163
  config.reset
177
164
  config.index_options[option.to_sym] = "something"
@@ -187,7 +174,7 @@ describe ThinkingSphinx::Configuration do
187
174
  it "should insert set source options into the configuration file" do
188
175
  config = ThinkingSphinx::Configuration.instance
189
176
  config.reset
190
-
177
+
191
178
  config.source_options[:sql_query_pre] = ["something"]
192
179
  ThinkingSphinx::Configuration::SourceOptions.each do |option|
193
180
  config.source_options[option.to_sym] ||= "something"
@@ -198,25 +185,27 @@ describe ThinkingSphinx::Configuration do
198
185
 
199
186
  config.source_options.delete option.to_sym
200
187
  end
201
-
202
- config.source_options[:sql_query_pre] = nil
188
+
189
+ config.source_options[:sql_query_pre] = nil
203
190
  end
204
-
191
+
205
192
  it "should not blow away delta or utf options if sql pre is specified in config" do
206
193
  config = ThinkingSphinx::Configuration.instance
207
194
  config.reset
208
-
195
+
209
196
  config.source_options[:sql_query_pre] = ["a pre query"]
210
197
  config.build
211
198
  file = open(config.config_file) { |f| f.read }
212
-
199
+
213
200
  file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = UPDATE `\w+` SET `delta` = 0 WHERE `delta` = 1/im)
214
201
  file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = \n/im)
215
-
202
+
216
203
  config.source_options[:sql_query_pre] = nil
217
204
  end
218
205
 
219
206
  it "should set any explicit prefixed or infixed fields" do
207
+ ThinkingSphinx::Configuration.instance.build
208
+
220
209
  file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
221
210
  f.read
222
211
  }
@@ -225,38 +214,48 @@ describe ThinkingSphinx::Configuration do
225
214
  end
226
215
 
227
216
  it "should not have prefix fields in indexes where nothing is set" do
217
+ ThinkingSphinx::Configuration.instance.build
218
+
228
219
  file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
229
220
  f.read
230
221
  }
231
222
  file.should_not match(/index alpha_core\s+\{\s+[^\}]*prefix_fields\s+=[^\}]*\}/m)
232
223
  end
233
-
234
- describe '#generate' do
235
- let(:config) { ThinkingSphinx::Configuration.instance }
236
-
237
- it "should set all sphinx_internal_id attributes to bigints if one is" do
238
- config.reset
239
- config.generate
240
-
241
- config.configuration.indices.each do |index|
242
- next if index.is_a? Riddle::Configuration::DistributedIndex
243
-
244
- index.sources.each do |source|
245
- source.sql_attr_bigint.should include(:sphinx_internal_id)
246
- end
247
- end
224
+
225
+ describe '#client' do
226
+ before :each do
227
+ @config = ThinkingSphinx::Configuration.instance
228
+ @config.address = 'domain.url'
229
+ @config.port = 3333
230
+ @config.configuration.searchd.max_matches = 100
231
+ end
232
+
233
+ it "should return an instance of Riddle::Client" do
234
+ @config.client.should be_a(Riddle::Client)
235
+ end
236
+
237
+ it "should use the configuration address" do
238
+ @config.client.server.should == 'domain.url'
239
+ end
240
+
241
+ it "should use the configuration port" do
242
+ @config.client.port.should == 3333
243
+ end
244
+
245
+ it "should use the configuration max matches" do
246
+ @config.client.max_matches.should == 100
248
247
  end
249
248
  end
250
-
249
+
251
250
  describe '#models_by_crc' do
252
251
  before :each do
253
252
  @config = ThinkingSphinx::Configuration.instance
254
253
  end
255
-
254
+
256
255
  it "should return a hash" do
257
256
  @config.models_by_crc.should be_a(Hash)
258
257
  end
259
-
258
+
260
259
  it "should pair class names to their crc codes" do
261
260
  @config.models_by_crc[Person.to_crc32].should == 'Person'
262
261
  @config.models_by_crc[Alpha.to_crc32].should == 'Alpha'