thinking-sphinx 2.1.0 → 3.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +13 -0
- data/Appraisals +7 -0
- data/Gemfile +10 -0
- data/HISTORY +2 -267
- data/LICENCE +1 -1
- data/README.textile +194 -226
- data/Rakefile +24 -0
- data/gemfiles/.gitignore +1 -0
- data/gemfiles/rails_3_1.gemfile +11 -0
- data/gemfiles/rails_3_2.gemfile +11 -0
- data/lib/thinking-sphinx.rb +1 -1
- data/lib/thinking_sphinx.rb +34 -292
- data/lib/thinking_sphinx/active_record.rb +22 -383
- data/lib/thinking_sphinx/active_record/association.rb +9 -0
- data/lib/thinking_sphinx/active_record/association_proxy.rb +68 -0
- data/lib/thinking_sphinx/active_record/associations.rb +68 -0
- data/lib/thinking_sphinx/active_record/attribute.rb +20 -0
- data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +32 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +79 -0
- data/lib/thinking_sphinx/active_record/attribute/values.rb +18 -0
- data/lib/thinking_sphinx/active_record/base.rb +36 -0
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +31 -0
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +55 -0
- data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +59 -0
- data/lib/thinking_sphinx/active_record/column.rb +30 -0
- data/lib/thinking_sphinx/active_record/database_adapters.rb +51 -0
- data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +13 -0
- data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +23 -0
- data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +25 -0
- data/lib/thinking_sphinx/active_record/field.rb +11 -0
- data/lib/thinking_sphinx/active_record/index.rb +55 -0
- data/lib/thinking_sphinx/active_record/interpreter.rb +47 -0
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +10 -58
- data/lib/thinking_sphinx/active_record/property.rb +28 -0
- data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +60 -0
- data/lib/thinking_sphinx/active_record/sql_builder.rb +159 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +138 -0
- data/lib/thinking_sphinx/active_record/sql_source/template.rb +46 -0
- data/lib/thinking_sphinx/batched_search.rb +26 -0
- data/lib/thinking_sphinx/callbacks.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +80 -331
- data/lib/thinking_sphinx/configuration/consistent_ids.rb +31 -0
- data/lib/thinking_sphinx/configuration/defaults.rb +5 -0
- data/lib/thinking_sphinx/core.rb +6 -0
- data/lib/thinking_sphinx/core/index.rb +68 -0
- data/lib/thinking_sphinx/core/interpreter.rb +19 -0
- data/lib/thinking_sphinx/deltas.rb +35 -26
- data/lib/thinking_sphinx/deltas/default_delta.rb +56 -56
- data/lib/thinking_sphinx/excerpter.rb +23 -21
- data/lib/thinking_sphinx/facet.rb +22 -127
- data/lib/thinking_sphinx/facet_search.rb +95 -162
- data/lib/thinking_sphinx/index.rb +39 -143
- data/lib/thinking_sphinx/index_set.rb +51 -0
- data/lib/thinking_sphinx/masks.rb +8 -0
- data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +23 -0
- data/lib/thinking_sphinx/masks/pagination_mask.rb +60 -0
- data/lib/thinking_sphinx/masks/scopes_mask.rb +35 -0
- data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +11 -0
- data/lib/thinking_sphinx/middlewares.rb +36 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +73 -0
- data/lib/thinking_sphinx/middlewares/geographer.rb +53 -0
- data/lib/thinking_sphinx/middlewares/glazier.rb +39 -0
- data/lib/thinking_sphinx/middlewares/ids_only.rb +13 -0
- data/lib/thinking_sphinx/middlewares/inquirer.rb +62 -0
- data/lib/thinking_sphinx/middlewares/middleware.rb +9 -0
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +149 -0
- data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +45 -0
- data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +46 -0
- data/lib/thinking_sphinx/panes.rb +8 -0
- data/lib/thinking_sphinx/panes/attributes_pane.rb +9 -0
- data/lib/thinking_sphinx/panes/distance_pane.rb +13 -0
- data/lib/thinking_sphinx/panes/excerpts_pane.rb +37 -0
- data/lib/thinking_sphinx/panes/weight_pane.rb +9 -0
- data/lib/thinking_sphinx/railtie.rb +6 -40
- data/lib/thinking_sphinx/rake_interface.rb +47 -0
- data/lib/thinking_sphinx/real_time.rb +11 -0
- data/lib/thinking_sphinx/real_time/attribute.rb +5 -0
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +48 -0
- data/lib/thinking_sphinx/real_time/field.rb +3 -0
- data/lib/thinking_sphinx/real_time/index.rb +47 -0
- data/lib/thinking_sphinx/real_time/index/template.rb +33 -0
- data/lib/thinking_sphinx/real_time/interpreter.rb +23 -0
- data/lib/thinking_sphinx/real_time/property.rb +16 -0
- data/lib/thinking_sphinx/scopes.rb +22 -0
- data/lib/thinking_sphinx/search.rb +90 -1028
- data/lib/thinking_sphinx/search/batch_inquirer.rb +27 -0
- data/lib/thinking_sphinx/search/context.rb +26 -0
- data/lib/thinking_sphinx/search/glaze.rb +32 -0
- data/lib/thinking_sphinx/search/merger.rb +24 -0
- data/lib/thinking_sphinx/search/query.rb +43 -0
- data/lib/thinking_sphinx/search/stale_ids_exception.rb +11 -0
- data/lib/thinking_sphinx/search/translator.rb +50 -0
- data/lib/thinking_sphinx/tasks.rb +22 -125
- data/lib/thinking_sphinx/test.rb +9 -19
- data/sketchpad.rb +58 -0
- data/spec/acceptance/association_scoping_spec.rb +23 -0
- data/spec/acceptance/attribute_access_spec.rb +39 -0
- data/spec/acceptance/attribute_updates_spec.rb +16 -0
- data/spec/acceptance/batch_searching_spec.rb +21 -0
- data/spec/acceptance/big_integers_spec.rb +27 -0
- data/spec/acceptance/excerpts_spec.rb +14 -0
- data/spec/acceptance/facets_spec.rb +122 -0
- data/spec/acceptance/geosearching_spec.rb +39 -0
- data/spec/acceptance/grouping_by_attributes_spec.rb +77 -0
- data/spec/acceptance/paginating_search_results_spec.rb +24 -0
- data/spec/acceptance/remove_deleted_records_spec.rb +23 -0
- data/spec/acceptance/search_counts_spec.rb +18 -0
- data/spec/acceptance/search_for_just_ids_spec.rb +19 -0
- data/spec/acceptance/searching_across_models_spec.rb +28 -0
- data/spec/acceptance/searching_on_fields_spec.rb +56 -0
- data/spec/acceptance/searching_with_filters_spec.rb +109 -0
- data/spec/acceptance/searching_with_sti_spec.rb +55 -0
- data/spec/acceptance/searching_within_a_model_spec.rb +52 -0
- data/spec/acceptance/sorting_search_results_spec.rb +41 -0
- data/spec/acceptance/spec_helper.rb +4 -0
- data/spec/acceptance/specifying_sql_spec.rb +62 -0
- data/spec/acceptance/sphinx_scopes_spec.rb +49 -0
- data/spec/acceptance/sql_deltas_spec.rb +43 -0
- data/spec/acceptance/support/database_cleaner.rb +11 -0
- data/spec/acceptance/support/sphinx_controller.rb +39 -0
- data/spec/acceptance/support/sphinx_helpers.rb +24 -0
- data/spec/acceptance/suspended_deltas_spec.rb +20 -0
- data/spec/internal/.gitignore +1 -0
- data/spec/internal/app/indices/animal_index.rb +3 -0
- data/spec/internal/app/indices/article_index.rb +24 -0
- data/spec/internal/app/indices/book_index.rb +8 -0
- data/spec/internal/app/indices/city_index.rb +6 -0
- data/spec/internal/app/indices/product_index.rb +3 -0
- data/spec/internal/app/indices/tee_index.rb +4 -0
- data/spec/internal/app/indices/user_index.rb +5 -0
- data/spec/internal/app/models/animal.rb +2 -0
- data/spec/internal/app/models/article.rb +5 -0
- data/spec/internal/app/models/bird.rb +2 -0
- data/spec/internal/app/models/book.rb +11 -0
- data/spec/internal/app/models/city.rb +2 -0
- data/spec/internal/app/models/colour.rb +3 -0
- data/spec/internal/app/models/flightless_bird.rb +2 -0
- data/spec/internal/app/models/mammal.rb +2 -0
- data/spec/internal/app/models/product.rb +3 -0
- data/spec/internal/app/models/tag.rb +4 -0
- data/{features/thinking_sphinx → spec/internal/app}/models/tagging.rb +1 -1
- data/spec/internal/app/models/tee.rb +3 -0
- data/spec/internal/app/models/tweet.rb +3 -0
- data/spec/internal/app/models/user.rb +3 -0
- data/spec/internal/config/database.yml +5 -0
- data/spec/internal/db/schema.rb +65 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/spec_helper.rb +8 -49
- data/spec/support/sphinx_yaml_helpers.rb +9 -0
- data/spec/thinking_sphinx/active_record/association_spec.rb +12 -0
- data/spec/thinking_sphinx/active_record/associations_spec.rb +184 -0
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +147 -0
- data/spec/thinking_sphinx/active_record/base_spec.rb +61 -0
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +80 -0
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +147 -0
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +69 -0
- data/spec/thinking_sphinx/active_record/column_spec.rb +47 -0
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +31 -0
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +43 -0
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +45 -0
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +108 -0
- data/spec/thinking_sphinx/active_record/field_spec.rb +36 -0
- data/spec/thinking_sphinx/active_record/index_spec.rb +208 -0
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +293 -0
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +162 -0
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +666 -0
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +401 -0
- data/spec/thinking_sphinx/configuration_spec.rb +264 -171
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +116 -0
- data/spec/thinking_sphinx/deltas_spec.rb +58 -0
- data/spec/thinking_sphinx/excerpter_spec.rb +40 -38
- data/spec/thinking_sphinx/facet_search_spec.rb +49 -151
- data/spec/thinking_sphinx/index_set_spec.rb +68 -0
- data/spec/thinking_sphinx/index_spec.rb +91 -155
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +121 -0
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +68 -0
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +132 -0
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +89 -0
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +62 -0
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +55 -0
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +271 -0
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +47 -0
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +91 -0
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +21 -0
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +41 -0
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +53 -0
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +20 -0
- data/spec/thinking_sphinx/rake_interface_spec.rb +147 -0
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +62 -0
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +76 -0
- data/spec/thinking_sphinx/real_time/field_spec.rb +54 -0
- data/spec/thinking_sphinx/real_time/index_spec.rb +154 -0
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +147 -0
- data/spec/thinking_sphinx/scopes_spec.rb +38 -0
- data/spec/thinking_sphinx/search/glaze_spec.rb +55 -0
- data/spec/thinking_sphinx/search/query_spec.rb +46 -0
- data/spec/thinking_sphinx/search_spec.rb +65 -1357
- data/spec/thinking_sphinx_spec.rb +19 -182
- data/thinking-sphinx.gemspec +33 -0
- metadata +318 -431
- data/features/abstract_inheritance.feature +0 -10
- data/features/alternate_primary_key.feature +0 -27
- data/features/attribute_transformation.feature +0 -22
- data/features/attribute_updates.feature +0 -79
- data/features/deleting_instances.feature +0 -70
- data/features/direct_attributes.feature +0 -11
- data/features/excerpts.feature +0 -21
- data/features/extensible_delta_indexing.feature +0 -9
- data/features/facets.feature +0 -88
- data/features/facets_across_model.feature +0 -29
- data/features/field_sorting.feature +0 -18
- data/features/handling_edits.feature +0 -97
- data/features/retry_stale_indexes.feature +0 -24
- data/features/searching_across_models.feature +0 -20
- data/features/searching_by_index.feature +0 -41
- data/features/searching_by_model.feature +0 -175
- data/features/searching_with_find_arguments.feature +0 -56
- data/features/sphinx_detection.feature +0 -25
- data/features/sphinx_scopes.feature +0 -68
- data/features/step_definitions/alpha_steps.rb +0 -16
- data/features/step_definitions/beta_steps.rb +0 -7
- data/features/step_definitions/common_steps.rb +0 -205
- data/features/step_definitions/extensible_delta_indexing_steps.rb +0 -7
- data/features/step_definitions/facet_steps.rb +0 -96
- data/features/step_definitions/find_arguments_steps.rb +0 -36
- data/features/step_definitions/gamma_steps.rb +0 -15
- data/features/step_definitions/scope_steps.rb +0 -19
- data/features/step_definitions/search_steps.rb +0 -94
- data/features/step_definitions/sphinx_steps.rb +0 -35
- data/features/sti_searching.feature +0 -19
- data/features/support/env.rb +0 -24
- data/features/support/lib/generic_delta_handler.rb +0 -8
- data/features/thinking_sphinx/database.example.yml +0 -3
- data/features/thinking_sphinx/db/.gitignore +0 -1
- data/features/thinking_sphinx/db/fixtures/alphas.rb +0 -8
- data/features/thinking_sphinx/db/fixtures/authors.rb +0 -1
- data/features/thinking_sphinx/db/fixtures/betas.rb +0 -11
- data/features/thinking_sphinx/db/fixtures/boxes.rb +0 -9
- data/features/thinking_sphinx/db/fixtures/categories.rb +0 -1
- data/features/thinking_sphinx/db/fixtures/cats.rb +0 -3
- data/features/thinking_sphinx/db/fixtures/comments.rb +0 -24
- data/features/thinking_sphinx/db/fixtures/developers.rb +0 -31
- data/features/thinking_sphinx/db/fixtures/dogs.rb +0 -3
- data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +0 -10
- data/features/thinking_sphinx/db/fixtures/foxes.rb +0 -3
- data/features/thinking_sphinx/db/fixtures/gammas.rb +0 -10
- data/features/thinking_sphinx/db/fixtures/music.rb +0 -4
- data/features/thinking_sphinx/db/fixtures/people.rb +0 -1001
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
- data/features/thinking_sphinx/db/fixtures/posts.rb +0 -10
- data/features/thinking_sphinx/db/fixtures/robots.rb +0 -8
- data/features/thinking_sphinx/db/fixtures/tags.rb +0 -27
- data/features/thinking_sphinx/db/migrations/create_alphas.rb +0 -8
- data/features/thinking_sphinx/db/migrations/create_animals.rb +0 -5
- data/features/thinking_sphinx/db/migrations/create_authors.rb +0 -3
- data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +0 -6
- data/features/thinking_sphinx/db/migrations/create_betas.rb +0 -5
- data/features/thinking_sphinx/db/migrations/create_boxes.rb +0 -5
- data/features/thinking_sphinx/db/migrations/create_categories.rb +0 -3
- data/features/thinking_sphinx/db/migrations/create_comments.rb +0 -10
- data/features/thinking_sphinx/db/migrations/create_developers.rb +0 -7
- data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +0 -5
- data/features/thinking_sphinx/db/migrations/create_gammas.rb +0 -3
- data/features/thinking_sphinx/db/migrations/create_genres.rb +0 -3
- data/features/thinking_sphinx/db/migrations/create_music.rb +0 -6
- data/features/thinking_sphinx/db/migrations/create_people.rb +0 -13
- data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -6
- data/features/thinking_sphinx/db/migrations/create_robots.rb +0 -4
- data/features/thinking_sphinx/db/migrations/create_taggings.rb +0 -5
- data/features/thinking_sphinx/db/migrations/create_tags.rb +0 -4
- data/features/thinking_sphinx/models/alpha.rb +0 -23
- data/features/thinking_sphinx/models/andrew.rb +0 -17
- data/features/thinking_sphinx/models/animal.rb +0 -5
- data/features/thinking_sphinx/models/author.rb +0 -3
- data/features/thinking_sphinx/models/beta.rb +0 -13
- data/features/thinking_sphinx/models/box.rb +0 -8
- data/features/thinking_sphinx/models/cat.rb +0 -3
- data/features/thinking_sphinx/models/category.rb +0 -4
- data/features/thinking_sphinx/models/comment.rb +0 -10
- data/features/thinking_sphinx/models/developer.rb +0 -21
- data/features/thinking_sphinx/models/dog.rb +0 -3
- data/features/thinking_sphinx/models/extensible_beta.rb +0 -9
- data/features/thinking_sphinx/models/fox.rb +0 -5
- data/features/thinking_sphinx/models/gamma.rb +0 -5
- data/features/thinking_sphinx/models/genre.rb +0 -3
- data/features/thinking_sphinx/models/medium.rb +0 -5
- data/features/thinking_sphinx/models/music.rb +0 -10
- data/features/thinking_sphinx/models/person.rb +0 -24
- data/features/thinking_sphinx/models/post.rb +0 -22
- data/features/thinking_sphinx/models/robot.rb +0 -12
- data/features/thinking_sphinx/models/tag.rb +0 -3
- data/lib/cucumber/thinking_sphinx/external_world.rb +0 -12
- data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -137
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -28
- data/lib/thinking_sphinx/action_controller.rb +0 -31
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -54
- data/lib/thinking_sphinx/active_record/collection_proxy.rb +0 -47
- data/lib/thinking_sphinx/active_record/collection_proxy_with_scopes.rb +0 -27
- data/lib/thinking_sphinx/active_record/delta.rb +0 -67
- data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -44
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -110
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -94
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -62
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -188
- data/lib/thinking_sphinx/association.rb +0 -230
- data/lib/thinking_sphinx/attribute.rb +0 -405
- data/lib/thinking_sphinx/auto_version.rb +0 -40
- data/lib/thinking_sphinx/bundled_search.rb +0 -40
- data/lib/thinking_sphinx/class_facet.rb +0 -20
- data/lib/thinking_sphinx/connection.rb +0 -71
- data/lib/thinking_sphinx/context.rb +0 -81
- data/lib/thinking_sphinx/core/string.rb +0 -15
- data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
- data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
- data/lib/thinking_sphinx/deploy/capistrano.rb +0 -99
- data/lib/thinking_sphinx/field.rb +0 -98
- data/lib/thinking_sphinx/index/builder.rb +0 -315
- data/lib/thinking_sphinx/index/faux_column.rb +0 -118
- data/lib/thinking_sphinx/join.rb +0 -37
- data/lib/thinking_sphinx/property.rb +0 -187
- data/lib/thinking_sphinx/search_methods.rb +0 -439
- data/lib/thinking_sphinx/sinatra.rb +0 -7
- data/lib/thinking_sphinx/source.rb +0 -194
- data/lib/thinking_sphinx/source/internal_properties.rb +0 -51
- data/lib/thinking_sphinx/source/sql.rb +0 -174
- data/spec/fixtures/data.sql +0 -32
- data/spec/fixtures/database.yml.default +0 -3
- data/spec/fixtures/models.rb +0 -164
- data/spec/fixtures/structure.sql +0 -146
- data/spec/sphinx_helper.rb +0 -60
- data/spec/support/rails.rb +0 -25
- data/spec/thinking_sphinx/active_record/delta_spec.rb +0 -123
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -173
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +0 -177
- data/spec/thinking_sphinx/active_record_spec.rb +0 -573
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
- data/spec/thinking_sphinx/association_spec.rb +0 -250
- data/spec/thinking_sphinx/attribute_spec.rb +0 -552
- data/spec/thinking_sphinx/auto_version_spec.rb +0 -103
- data/spec/thinking_sphinx/connection_spec.rb +0 -77
- data/spec/thinking_sphinx/context_spec.rb +0 -127
- data/spec/thinking_sphinx/core/array_spec.rb +0 -9
- data/spec/thinking_sphinx/core/string_spec.rb +0 -9
- data/spec/thinking_sphinx/facet_spec.rb +0 -359
- data/spec/thinking_sphinx/field_spec.rb +0 -127
- data/spec/thinking_sphinx/index/builder_spec.rb +0 -532
- data/spec/thinking_sphinx/index/faux_column_spec.rb +0 -36
- data/spec/thinking_sphinx/search_methods_spec.rb +0 -156
- data/spec/thinking_sphinx/source_spec.rb +0 -267
- data/spec/thinking_sphinx/test_spec.rb +0 -20
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
|
4
|
-
describe "search method" do
|
5
|
-
before :each do
|
6
|
-
Friendship.stub!(:search => true)
|
7
|
-
|
8
|
-
@person = Person.find(:first)
|
9
|
-
@index = Friendship.sphinx_indexes.first
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise an error if the required attribute doesn't exist" do
|
13
|
-
@index.stub!(:attributes => [])
|
14
|
-
|
15
|
-
lambda { @person.friendships.search "test" }.should raise_error(RuntimeError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should add a filter for the attribute into a normal search call" do
|
19
|
-
Friendship.should_receive(:search) do |query, options|
|
20
|
-
options[:with][:person_id].should == @person.id
|
21
|
-
end
|
22
|
-
|
23
|
-
@person.friendships.search "test"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should add a filter for an aliased attribute into a normal search call" do
|
27
|
-
@team = CricketTeam.new
|
28
|
-
@team.stub!(:id => 1)
|
29
|
-
|
30
|
-
Person.should_receive(:search).with do |query, options|
|
31
|
-
options[:with][:team_id].should == @team.id
|
32
|
-
end
|
33
|
-
|
34
|
-
@team.people.search "test"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should define indexes for the reflection class" do
|
38
|
-
Friendship.should_receive(:define_indexes)
|
39
|
-
|
40
|
-
@person.friendships.search 'test'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "facets method" do
|
45
|
-
before :each do
|
46
|
-
Friendship.stub!(:facets => true)
|
47
|
-
|
48
|
-
@person = Person.find(:first)
|
49
|
-
@index = Friendship.sphinx_indexes.first
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should raise an error if the required attribute doesn't exist" do
|
53
|
-
@index.stub!(:attributes => [])
|
54
|
-
|
55
|
-
lambda { @person.friendships.facets "test" }.should raise_error(RuntimeError)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should add a filter for the attribute into a normal facets call" do
|
59
|
-
Friendship.should_receive(:facets) do |query, options|
|
60
|
-
options[:with][:person_id].should == @person.id
|
61
|
-
end
|
62
|
-
|
63
|
-
@person.friendships.facets "test"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should add a filter for an aliased attribute into a normal facets call" do
|
67
|
-
@team = CricketTeam.new
|
68
|
-
@team.stub!(:id => 1)
|
69
|
-
|
70
|
-
Person.should_receive(:facets).with do |query, options|
|
71
|
-
options[:with][:team_id].should == @team.id
|
72
|
-
end
|
73
|
-
|
74
|
-
@team.people.facets "test"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should define indexes for the reflection class" do
|
78
|
-
Friendship.should_receive(:define_indexes)
|
79
|
-
|
80
|
-
@person.friendships.facets 'test'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "search method for has_many :through" do
|
85
|
-
before :each do
|
86
|
-
Person.stub!(:search => true)
|
87
|
-
|
88
|
-
@person = Person.find(:first)
|
89
|
-
@index = Person.sphinx_indexes.first
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should raise an error if the required attribute doesn't exist" do
|
93
|
-
@index.stub!(:attributes => [])
|
94
|
-
|
95
|
-
lambda { @person.friends.search "test" }.should raise_error(RuntimeError)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should add a filter for the attribute into a normal search call" do
|
99
|
-
Person.should_receive(:search).with do |query, options|
|
100
|
-
options[:with][:friendly_ids].should == @person.id
|
101
|
-
end
|
102
|
-
|
103
|
-
@person.friends.search "test"
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should add a filter for an aliased attribute into a normal search call" do
|
107
|
-
@team = FootballTeam.new
|
108
|
-
@team.stub!(:id => 1)
|
109
|
-
|
110
|
-
Person.should_receive(:search).with do |query, options|
|
111
|
-
options[:with][:football_team_id].should == @team.id
|
112
|
-
end
|
113
|
-
|
114
|
-
@team.people.search "test"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "facets method for has_many :through" do
|
119
|
-
before :each do
|
120
|
-
Person.stub!(:facets => true)
|
121
|
-
|
122
|
-
@person = Person.find(:first)
|
123
|
-
@index = Person.sphinx_indexes.first
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should raise an error if the required attribute doesn't exist" do
|
127
|
-
@index.stub!(:attributes => [])
|
128
|
-
|
129
|
-
lambda { @person.friends.facets "test" }.should raise_error(RuntimeError)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should add a filter for the attribute into a normal facets call" do
|
133
|
-
Person.should_receive(:facets).with do |query, options|
|
134
|
-
options[:with][:friendly_ids].should == @person.id
|
135
|
-
end
|
136
|
-
|
137
|
-
@person.friends.facets "test"
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should add a filter for an aliased attribute into a normal facets call" do
|
141
|
-
@team = FootballTeam.new
|
142
|
-
@team.stub!(:id => 1)
|
143
|
-
|
144
|
-
Person.should_receive(:facets).with do |query, options|
|
145
|
-
options[:with][:football_team_id].should == @team.id
|
146
|
-
end
|
147
|
-
|
148
|
-
@team.people.facets "test"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe 'filtering sphinx scopes' do
|
153
|
-
before :each do
|
154
|
-
Friendship.stub!(:search => Friendship)
|
155
|
-
|
156
|
-
@person = Person.find(:first)
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should add a filter for the attribute in a sphinx scope call" do
|
160
|
-
Friendship.should_receive(:search).with do |options|
|
161
|
-
options[:with][:person_id].should == @person.id
|
162
|
-
Friendship
|
163
|
-
end
|
164
|
-
|
165
|
-
@person.friendships.reverse
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should pass method_missing onto CollectionProxy" do
|
169
|
-
Friendship.stub!(:missing_method => true)
|
170
|
-
@person.friendships.missing_method.should == true
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
@@ -1,177 +0,0 @@
|
|
1
|
-
require '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 '.default_sphinx_scope' do
|
39
|
-
before :each do
|
40
|
-
Alpha.sphinx_scope(:scope_used_as_default_scope) { {:conditions => {:name => 'name'}} }
|
41
|
-
Alpha.default_sphinx_scope :scope_used_as_default_scope
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return an array of defined scope names as symbols" do
|
45
|
-
Alpha.sphinx_scopes.should == [:scope_used_as_default_scope]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should have a default_sphinx_scope" do
|
49
|
-
Alpha.has_default_sphinx_scope?.should be_true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '.remove_sphinx_scopes' do
|
54
|
-
before :each do
|
55
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
56
|
-
Alpha.remove_sphinx_scopes
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should remove sphinx scope methods" do
|
60
|
-
Alpha.should_not respond_to(:by_name)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should empty the list of sphinx scopes" do
|
64
|
-
Alpha.sphinx_scopes.should be_empty
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '.example_default_scope' do
|
69
|
-
before :each do
|
70
|
-
Alpha.sphinx_scope(:foo_scope){ {:conditions => {:name => 'foo'}} }
|
71
|
-
Alpha.default_sphinx_scope :foo_scope
|
72
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
73
|
-
Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should return a ThinkingSphinx::Search object" do
|
77
|
-
Alpha.search.should be_a(ThinkingSphinx::Search)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should apply the default scope options to the underlying search object" do
|
81
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
82
|
-
search.search.options[:conditions].should == {:name => 'foo'}
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should apply the default scope options and scope options to the underlying search object" do
|
86
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
87
|
-
search.by_foo('foo').search.options[:conditions].should == {:foo => 'foo', :name => 'foo'}
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should apply the default scope options before other scope options to the underlying search object" do
|
91
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
92
|
-
search.by_name('bar').search.options[:conditions].should == {:name => 'bar'}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '.example_scope' do
|
97
|
-
before :each do
|
98
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
99
|
-
Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
|
100
|
-
Alpha.sphinx_scope(:with_betas) { {:classes => [Beta]} }
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should return a ThinkingSphinx::Search object" do
|
104
|
-
Alpha.by_name('foo').should be_a(ThinkingSphinx::Search)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should set the classes option" do
|
108
|
-
Alpha.by_name('foo').options[:classes].should == [Alpha]
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should be able to be called on a ThinkingSphinx::Search object" do
|
112
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
113
|
-
lambda {
|
114
|
-
search.by_name('foo')
|
115
|
-
}.should_not raise_error
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should return the search object it gets called upon" do
|
119
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
120
|
-
search.by_name('foo').object_id.should == search.object_id
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should apply the scope options to the underlying search object" do
|
124
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
125
|
-
search.by_name('foo').options[:conditions].should == {:name => 'foo'}
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should combine hash option scopes such as :conditions" do
|
129
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
130
|
-
search.by_name('foo').by_foo('bar').options[:conditions].
|
131
|
-
should == {:name => 'foo', :foo => 'bar'}
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should combine array option scopes such as :classes" do
|
135
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
136
|
-
search.with_betas.options[:classes].should == [Alpha, Beta]
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe '.search_count_with_scope' do
|
141
|
-
before :each do
|
142
|
-
@config = ThinkingSphinx::Configuration.instance
|
143
|
-
@client = Riddle::Client.new
|
144
|
-
|
145
|
-
ThinkingSphinx::Connection.stub(:take).and_yield(@client)
|
146
|
-
|
147
|
-
@client.stub!(:query => {:matches => [], :total_found => 43})
|
148
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
149
|
-
Alpha.sphinx_scope(:ids_only) { {:ids_only => true} }
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should return the total number of results" do
|
153
|
-
Alpha.by_name('foo').search_count.should == 43
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should not make any calls to the database" do
|
157
|
-
Alpha.should_not_receive(:find)
|
158
|
-
|
159
|
-
Alpha.by_name('foo').search_count
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should not leave the :ids_only option set and the results populated if it was not set before" do
|
163
|
-
stored_scope = Alpha.by_name('foo')
|
164
|
-
stored_scope.search_count
|
165
|
-
stored_scope.options[:ids_only].should be_false
|
166
|
-
stored_scope.populated?.should be_false
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should leave the :ids_only option set and the results populated if it was set before" do
|
170
|
-
stored_scope = Alpha.by_name('foo').ids_only
|
171
|
-
stored_scope.search_count
|
172
|
-
stored_scope.options[:ids_only].should be_true
|
173
|
-
stored_scope.populated?.should be_true
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
@@ -1,573 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::ActiveRecord do
|
4
|
-
before :each do
|
5
|
-
@existing_alpha_indexes = Alpha.sphinx_indexes.clone
|
6
|
-
@existing_beta_indexes = Beta.sphinx_indexes.clone
|
7
|
-
|
8
|
-
Alpha.send :defined_indexes=, false
|
9
|
-
Beta.send :defined_indexes=, false
|
10
|
-
|
11
|
-
Alpha.sphinx_indexes.clear
|
12
|
-
Beta.sphinx_indexes.clear
|
13
|
-
end
|
14
|
-
|
15
|
-
after :each do
|
16
|
-
Alpha.sphinx_indexes.replace @existing_alpha_indexes
|
17
|
-
Beta.sphinx_indexes.replace @existing_beta_indexes
|
18
|
-
|
19
|
-
Alpha.send :defined_indexes=, true
|
20
|
-
Beta.send :defined_indexes=, true
|
21
|
-
|
22
|
-
Alpha.sphinx_index_blocks.clear
|
23
|
-
Beta.sphinx_index_blocks.clear
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.define_index' do
|
27
|
-
it "should do nothing if indexes are disabled" do
|
28
|
-
ThinkingSphinx.define_indexes = false
|
29
|
-
ThinkingSphinx::Index.should_not_receive(:new)
|
30
|
-
|
31
|
-
Alpha.define_index { }
|
32
|
-
Alpha.define_indexes
|
33
|
-
|
34
|
-
ThinkingSphinx.define_indexes = true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should not evaluate the index block automatically" do
|
38
|
-
lambda {
|
39
|
-
Alpha.define_index { raise StandardError }
|
40
|
-
}.should_not raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should add the model to the context collection" do
|
44
|
-
Alpha.define_index { indexes :name }
|
45
|
-
|
46
|
-
ThinkingSphinx.context.indexed_models.should include("Alpha")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should die quietly if there is a database error" do
|
50
|
-
ThinkingSphinx::Index::Builder.stub(:generate).
|
51
|
-
and_raise(Mysql2::Error.new(''))
|
52
|
-
Alpha.define_index { indexes :name }
|
53
|
-
|
54
|
-
lambda {
|
55
|
-
Alpha.define_indexes
|
56
|
-
}.should_not raise_error
|
57
|
-
end unless RUBY_PLATFORM == 'java'
|
58
|
-
|
59
|
-
it "should die noisily if there is a non-database error" do
|
60
|
-
ThinkingSphinx::Index::Builder.stub(:generate) { raise StandardError }
|
61
|
-
Alpha.define_index { indexes :name }
|
62
|
-
|
63
|
-
lambda {
|
64
|
-
Alpha.define_indexes
|
65
|
-
}.should raise_error
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should set the index's name using the parameter if provided" do
|
69
|
-
Alpha.define_index('custom') { indexes :name }
|
70
|
-
Alpha.define_indexes
|
71
|
-
|
72
|
-
Alpha.sphinx_indexes.first.name.should == 'custom'
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'callbacks' do
|
76
|
-
it "should add a before_validation callback to define_indexes" do
|
77
|
-
Alpha.should_receive(:before_validation).with(:define_indexes)
|
78
|
-
|
79
|
-
Alpha.define_index { }
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not add a before_validation callback twice" do
|
83
|
-
Alpha.should_receive(:before_validation).with(:define_indexes).once
|
84
|
-
|
85
|
-
Alpha.define_index { }
|
86
|
-
Alpha.define_index { }
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should add a before_destroy callback to define_indexes" do
|
90
|
-
Alpha.should_receive(:before_destroy).with(:define_indexes)
|
91
|
-
|
92
|
-
Alpha.define_index { }
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should not add a before_destroy callback twice" do
|
96
|
-
Alpha.should_receive(:before_destroy).with(:define_indexes).once
|
97
|
-
|
98
|
-
Alpha.define_index { }
|
99
|
-
Alpha.define_index { }
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should add a toggle_deleted callback when defined" do
|
103
|
-
Alpha.should_receive(:after_destroy).with(:toggle_deleted)
|
104
|
-
|
105
|
-
Alpha.define_index { indexes :name }
|
106
|
-
Alpha.define_indexes
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should not add toggle_deleted callback more than once" do
|
110
|
-
Alpha.should_receive(:after_destroy).with(:toggle_deleted).once
|
111
|
-
|
112
|
-
Alpha.define_index { indexes :name }
|
113
|
-
Alpha.define_index { indexes :name }
|
114
|
-
Alpha.define_indexes
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should add a update_attribute_values callback when defined" do
|
118
|
-
Alpha.should_receive(:after_save).with(:update_attribute_values)
|
119
|
-
|
120
|
-
Alpha.define_index { indexes :name }
|
121
|
-
Alpha.define_indexes
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should not add update_attribute_values callback more than once" do
|
125
|
-
Alpha.should_receive(:after_save).with(:update_attribute_values).once
|
126
|
-
|
127
|
-
Alpha.define_index { indexes :name }
|
128
|
-
Alpha.define_index { indexes :name }
|
129
|
-
Alpha.define_indexes
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should add a toggle_delta callback if deltas are enabled" do
|
133
|
-
Beta.should_receive(:before_save).with(:toggle_delta)
|
134
|
-
|
135
|
-
Beta.define_index {
|
136
|
-
indexes :name
|
137
|
-
set_property :delta => true
|
138
|
-
}
|
139
|
-
Beta.define_indexes
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should not add a toggle_delta callback if deltas are disabled" do
|
143
|
-
Alpha.should_not_receive(:before_save).with(:toggle_delta)
|
144
|
-
|
145
|
-
Alpha.define_index { indexes :name }
|
146
|
-
Alpha.define_indexes
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should add the toggle_delta callback if deltas are disabled in other indexes" do
|
150
|
-
Beta.should_receive(:before_save).with(:toggle_delta).once
|
151
|
-
|
152
|
-
Beta.define_index { indexes :name }
|
153
|
-
Beta.define_index('foo') {
|
154
|
-
indexes :name
|
155
|
-
set_property :delta => true
|
156
|
-
}
|
157
|
-
Beta.define_indexes
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should only add the toggle_delta callback once" do
|
161
|
-
Beta.should_receive(:before_save).with(:toggle_delta).once
|
162
|
-
|
163
|
-
Beta.define_index {
|
164
|
-
indexes :name
|
165
|
-
set_property :delta => true
|
166
|
-
}
|
167
|
-
Beta.define_index {
|
168
|
-
indexes :name
|
169
|
-
set_property :delta => true
|
170
|
-
}
|
171
|
-
Beta.define_indexes
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should add an index_delta callback if deltas are enabled" do
|
175
|
-
Beta.stub!(:after_save => true)
|
176
|
-
Beta.should_receive(:after_commit).with(:index_delta)
|
177
|
-
|
178
|
-
Beta.define_index {
|
179
|
-
indexes :name
|
180
|
-
set_property :delta => true
|
181
|
-
}
|
182
|
-
Beta.define_indexes
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should not add an index_delta callback if deltas are disabled" do
|
186
|
-
Alpha.should_not_receive(:after_commit).with(:index_delta)
|
187
|
-
|
188
|
-
Alpha.define_index { indexes :name }
|
189
|
-
Alpha.define_indexes
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should add the index_delta callback if deltas are disabled in other indexes" do
|
193
|
-
Beta.stub!(:after_commit => true)
|
194
|
-
Beta.should_receive(:after_commit).with(:index_delta).once
|
195
|
-
|
196
|
-
Beta.define_index { indexes :name }
|
197
|
-
Beta.define_index('foo') {
|
198
|
-
indexes :name
|
199
|
-
set_property :delta => true
|
200
|
-
}
|
201
|
-
Beta.define_indexes
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should only add the index_delta callback once" do
|
205
|
-
Beta.stub!(:after_commit => true)
|
206
|
-
Beta.should_receive(:after_commit).with(:index_delta).once
|
207
|
-
|
208
|
-
Beta.define_index {
|
209
|
-
indexes :name
|
210
|
-
set_property :delta => true
|
211
|
-
}
|
212
|
-
Beta.define_index {
|
213
|
-
indexes :name
|
214
|
-
set_property :delta => true
|
215
|
-
}
|
216
|
-
Beta.define_indexes
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe '.define_indexes' do
|
222
|
-
it "should process define_index blocks" do
|
223
|
-
Beta.define_index { indexes :name }
|
224
|
-
Beta.sphinx_indexes.length.should == 0
|
225
|
-
|
226
|
-
Beta.define_indexes
|
227
|
-
Beta.sphinx_indexes.length.should == 1
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should not re-add indexes" do
|
231
|
-
Beta.define_index { indexes :name }
|
232
|
-
Beta.define_indexes
|
233
|
-
Beta.define_indexes
|
234
|
-
|
235
|
-
Beta.sphinx_indexes.length.should == 1
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
describe '.source_of_sphinx_index' do
|
240
|
-
it "should return self if model defines an index" do
|
241
|
-
Person.source_of_sphinx_index.should == Person
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should return the parent if model inherits an index" do
|
245
|
-
Admin::Person.source_of_sphinx_index.should == Person
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe '.to_crc32' do
|
250
|
-
it "should return an integer" do
|
251
|
-
Person.to_crc32.should be_a_kind_of(Integer)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe '.to_crc32s' do
|
256
|
-
it "should return an array" do
|
257
|
-
Person.to_crc32s.should be_a_kind_of(Array)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "toggle_deleted method" do
|
262
|
-
before :each do
|
263
|
-
ThinkingSphinx.stub!(:sphinx_running? => true)
|
264
|
-
|
265
|
-
@configuration = ThinkingSphinx::Configuration.instance
|
266
|
-
@configuration.stub!(
|
267
|
-
:address => "an address",
|
268
|
-
:port => 123
|
269
|
-
)
|
270
|
-
@client = Riddle::Client.new
|
271
|
-
@client.stub!(:update => true)
|
272
|
-
@person = Person.find(:first)
|
273
|
-
|
274
|
-
ThinkingSphinx::Connection.stub(:take).and_yield(@client)
|
275
|
-
Person.sphinx_indexes.each { |index| index.stub!(:delta? => false) }
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should update the core index's deleted flag if in core index" do
|
279
|
-
@client.should_receive(:update).with(
|
280
|
-
"person_core", ["sphinx_deleted"], {@person.sphinx_document_id => [1]}
|
281
|
-
)
|
282
|
-
|
283
|
-
@person.toggle_deleted
|
284
|
-
end
|
285
|
-
|
286
|
-
it "shouldn't attempt to update the deleted flag if sphinx isn't running" do
|
287
|
-
ThinkingSphinx.stub!(:sphinx_running? => false)
|
288
|
-
@client.should_not_receive(:update)
|
289
|
-
|
290
|
-
@person.toggle_deleted
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should update the delta index's deleted flag if delta indexes are enabled and the instance's delta is true" do
|
294
|
-
ThinkingSphinx.deltas_enabled = true
|
295
|
-
Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
|
296
|
-
@person.delta = true
|
297
|
-
@client.should_receive(:update).with(
|
298
|
-
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => [1]}
|
299
|
-
)
|
300
|
-
|
301
|
-
@person.toggle_deleted
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should not update the delta index's deleted flag if delta indexes are enabled and the instance's delta is false" do
|
305
|
-
ThinkingSphinx.deltas_enabled = true
|
306
|
-
Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
|
307
|
-
@person.delta = false
|
308
|
-
@client.should_not_receive(:update).with(
|
309
|
-
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => [1]}
|
310
|
-
)
|
311
|
-
|
312
|
-
@person.toggle_deleted
|
313
|
-
end
|
314
|
-
|
315
|
-
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
|
316
|
-
ThinkingSphinx.deltas_enabled = true
|
317
|
-
Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
|
318
|
-
@person.delta = 0
|
319
|
-
@client.should_not_receive(:update).with(
|
320
|
-
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => [1]}
|
321
|
-
)
|
322
|
-
|
323
|
-
@person.toggle_deleted
|
324
|
-
end
|
325
|
-
|
326
|
-
it "shouldn't update the delta index if delta indexes are disabled" do
|
327
|
-
ThinkingSphinx.deltas_enabled = true
|
328
|
-
@client.should_not_receive(:update).with(
|
329
|
-
"person_delta", ["sphinx_deleted"], {@person.sphinx_document_id => [1]}
|
330
|
-
)
|
331
|
-
|
332
|
-
@person.toggle_deleted
|
333
|
-
end
|
334
|
-
|
335
|
-
it "should not update either index if updates are disabled" do
|
336
|
-
ThinkingSphinx.updates_enabled = false
|
337
|
-
ThinkingSphinx.deltas_enabled = true
|
338
|
-
Person.sphinx_indexes.each { |index| index.stub!(:delta? => true) }
|
339
|
-
@person.delta = true
|
340
|
-
@client.should_not_receive(:update)
|
341
|
-
|
342
|
-
@person.toggle_deleted
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe "sphinx_indexes in the inheritance chain (STI)" do
|
347
|
-
it "should hand defined indexes on a class down to its child classes" do
|
348
|
-
Child.sphinx_indexes.should include(*Person.sphinx_indexes)
|
349
|
-
end
|
350
|
-
|
351
|
-
it "should allow associations to other STI models" do
|
352
|
-
source = Child.sphinx_indexes.last.sources.first
|
353
|
-
sql = source.to_riddle_for_core(0, 0).sql_query
|
354
|
-
sql.gsub!('$start', '0').gsub!('$end', '100')
|
355
|
-
lambda {
|
356
|
-
Child.connection.execute(sql)
|
357
|
-
}.should_not raise_error(ActiveRecord::StatementInvalid)
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
describe '#sphinx_document_id' do
|
362
|
-
before :each do
|
363
|
-
Alpha.define_index { indexes :name }
|
364
|
-
Beta.define_index { indexes :name }
|
365
|
-
end
|
366
|
-
|
367
|
-
it "should return values with the expected offset" do
|
368
|
-
person = Person.find(:first)
|
369
|
-
model_count = ThinkingSphinx.context.indexed_models.length
|
370
|
-
Person.stub!(:sphinx_offset => 3)
|
371
|
-
|
372
|
-
(person.id * model_count + 3).should == person.sphinx_document_id
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
describe '#primary_key_for_sphinx' do
|
377
|
-
before :each do
|
378
|
-
@person = Person.find(:first)
|
379
|
-
end
|
380
|
-
|
381
|
-
after :each do
|
382
|
-
Person.clear_primary_key_for_sphinx
|
383
|
-
end
|
384
|
-
|
385
|
-
after :each do
|
386
|
-
Person.set_sphinx_primary_key nil
|
387
|
-
end
|
388
|
-
|
389
|
-
it "should return the id by default" do
|
390
|
-
@person.primary_key_for_sphinx.should == @person.id
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should use the sphinx primary key to determine the value" do
|
394
|
-
Person.set_sphinx_primary_key :first_name
|
395
|
-
@person.primary_key_for_sphinx.should == @person.first_name
|
396
|
-
end
|
397
|
-
|
398
|
-
it "should not use accessor methods but the attributes hash" do
|
399
|
-
id = @person.id
|
400
|
-
@person.stub!(:id => 'unique_hash')
|
401
|
-
@person.primary_key_for_sphinx.should == id
|
402
|
-
end
|
403
|
-
|
404
|
-
it "should be inherited by subclasses" do
|
405
|
-
Person.set_sphinx_primary_key :first_name
|
406
|
-
Parent.superclass.custom_primary_key_for_sphinx?
|
407
|
-
Parent.primary_key_for_sphinx.should == Person.primary_key_for_sphinx
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe '#types_for_sphinx' do
|
412
|
-
after :each do
|
413
|
-
Person.set_sphinx_types nil
|
414
|
-
end
|
415
|
-
|
416
|
-
it "should return nil by default" do
|
417
|
-
Person.sphinx_types.should == nil
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should return the specified value" do
|
421
|
-
Person.set_sphinx_types %w(Person Parent)
|
422
|
-
Person.sphinx_types.should == %w(Person Parent)
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
describe '.sphinx_index_names' do
|
427
|
-
it "should return the core index" do
|
428
|
-
Alpha.define_index { indexes :name }
|
429
|
-
Alpha.define_indexes
|
430
|
-
Alpha.sphinx_index_names.should == ['alpha_core']
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should return the delta index if enabled" do
|
434
|
-
Beta.define_index {
|
435
|
-
indexes :name
|
436
|
-
set_property :delta => true
|
437
|
-
}
|
438
|
-
Beta.define_indexes
|
439
|
-
|
440
|
-
Beta.sphinx_index_names.should == ['beta_core', 'beta_delta']
|
441
|
-
end
|
442
|
-
|
443
|
-
it "should return the superclass with an index definition" do
|
444
|
-
Parent.sphinx_index_names.should == ['person_core', 'person_delta']
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
describe '.indexed_by_sphinx?' do
|
449
|
-
it "should return true if there is at least one index on the model" do
|
450
|
-
Alpha.define_index { indexes :name }
|
451
|
-
Alpha.define_indexes
|
452
|
-
|
453
|
-
Alpha.should be_indexed_by_sphinx
|
454
|
-
end
|
455
|
-
|
456
|
-
it "should return false if there are no indexes on the model" do
|
457
|
-
Gamma.should_not be_indexed_by_sphinx
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
describe '.delta_indexed_by_sphinx?' do
|
462
|
-
it "should return true if there is at least one delta index on the model" do
|
463
|
-
Beta.define_index {
|
464
|
-
indexes :name
|
465
|
-
set_property :delta => true
|
466
|
-
}
|
467
|
-
Beta.define_indexes
|
468
|
-
|
469
|
-
Beta.should be_delta_indexed_by_sphinx
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should return false if there are no delta indexes on the model" do
|
473
|
-
Alpha.define_index { indexes :name }
|
474
|
-
Alpha.define_indexes
|
475
|
-
|
476
|
-
Alpha.should_not be_delta_indexed_by_sphinx
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
describe '.delete_in_index' do
|
481
|
-
before :each do
|
482
|
-
@client = stub('client')
|
483
|
-
ThinkingSphinx.stub!(:sphinx_running? => true)
|
484
|
-
ThinkingSphinx::Connection.stub(:take).and_yield(@client)
|
485
|
-
end
|
486
|
-
|
487
|
-
it "should direct the update to the supplied index" do
|
488
|
-
@client.should_receive(:update) do |index, attributes, values|
|
489
|
-
index.should == 'custom_index_core'
|
490
|
-
end
|
491
|
-
|
492
|
-
Alpha.delete_in_index('custom_index_core', 42)
|
493
|
-
end
|
494
|
-
|
495
|
-
it "should set the sphinx_deleted flag to true" do
|
496
|
-
@client.should_receive(:update) do |index, attributes, values|
|
497
|
-
attributes.should == ['sphinx_deleted']
|
498
|
-
values.should == {42 => [1]}
|
499
|
-
end
|
500
|
-
|
501
|
-
Alpha.delete_in_index('alpha_core', 42)
|
502
|
-
end
|
503
|
-
end
|
504
|
-
|
505
|
-
describe '.core_index_names' do
|
506
|
-
it "should return each index's core name" do
|
507
|
-
Alpha.define_index('foo') { indexes :name }
|
508
|
-
Alpha.define_index('bar') { indexes :name }
|
509
|
-
Alpha.define_indexes
|
510
|
-
|
511
|
-
Alpha.core_index_names.should == ['foo_core', 'bar_core']
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
describe '.delta_index_names' do
|
516
|
-
it "should return index delta names, for indexes with deltas enabled" do
|
517
|
-
Alpha.define_index('foo') { indexes :name }
|
518
|
-
Alpha.define_index('bar') { indexes :name }
|
519
|
-
Alpha.define_indexes
|
520
|
-
Alpha.sphinx_indexes.first.delta_object = stub('delta')
|
521
|
-
|
522
|
-
Alpha.delta_index_names.should == ['foo_delta']
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
describe '.sphinx_offset' do
|
527
|
-
before :each do
|
528
|
-
@context = ThinkingSphinx.context
|
529
|
-
end
|
530
|
-
|
531
|
-
it "should return the index of the model's name in all known indexed models" do
|
532
|
-
@context.stub!(:indexed_models => ['Alpha', 'Beta'])
|
533
|
-
|
534
|
-
Alpha.sphinx_offset.should == 0
|
535
|
-
Beta.sphinx_offset.should == 1
|
536
|
-
end
|
537
|
-
|
538
|
-
it "should ignore classes that have indexed superclasses" do
|
539
|
-
@context.stub!(:indexed_models => ['Alpha', 'Parent', 'Person'])
|
540
|
-
|
541
|
-
Person.sphinx_offset.should == 1
|
542
|
-
end
|
543
|
-
|
544
|
-
it "should respect first known indexed parents" do
|
545
|
-
@context.stub!(:indexed_models => ['Alpha', 'Parent', 'Person'])
|
546
|
-
|
547
|
-
Parent.sphinx_offset.should == 1
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
describe '.has_sphinx_indexes?' do
|
552
|
-
it "should return true if there are sphinx indexes defined" do
|
553
|
-
Alpha.sphinx_indexes.replace [stub('index')]
|
554
|
-
Alpha.sphinx_index_blocks.replace []
|
555
|
-
|
556
|
-
Alpha.should have_sphinx_indexes
|
557
|
-
end
|
558
|
-
|
559
|
-
it "should return true if there are sphinx index blocks defined" do
|
560
|
-
Alpha.sphinx_indexes.replace []
|
561
|
-
Alpha.sphinx_index_blocks.replace [stub('lambda')]
|
562
|
-
|
563
|
-
Alpha.should have_sphinx_indexes
|
564
|
-
end
|
565
|
-
|
566
|
-
it "should return false if there are no sphinx indexes or blocks" do
|
567
|
-
Alpha.sphinx_indexes.clear
|
568
|
-
Alpha.sphinx_index_blocks.clear
|
569
|
-
|
570
|
-
Alpha.should_not have_sphinx_indexes
|
571
|
-
end
|
572
|
-
end
|
573
|
-
end
|