thinking-sphinx 3.1.4 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.circleci/config.yml +99 -0
- data/.github/actions/test/action.yml +46 -0
- data/.github/workflows/ci.yml +75 -0
- data/.gitignore +7 -2
- data/.travis.yml +31 -16
- data/Appraisals +68 -12
- data/CHANGELOG.markdown +782 -0
- data/Gemfile +13 -4
- data/Procfile.support +2 -0
- data/README.textile +41 -27
- data/Rakefile +2 -0
- data/bin/console +15 -0
- data/bin/loadsphinx +99 -0
- data/bin/testmatrix +48 -0
- data/lib/thinking/sphinx.rb +2 -0
- data/lib/thinking-sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/association.rb +2 -0
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +3 -1
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +2 -0
- data/lib/thinking_sphinx/active_record/association_proxy.rb +3 -2
- data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +3 -1
- data/lib/thinking_sphinx/active_record/attribute/type.rb +20 -4
- data/lib/thinking_sphinx/active_record/attribute/values.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute.rb +2 -0
- data/lib/thinking_sphinx/active_record/base.rb +43 -11
- data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +15 -9
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +20 -5
- data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +18 -4
- data/lib/thinking_sphinx/active_record/column.rb +2 -0
- data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +7 -1
- data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +2 -0
- data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +9 -1
- data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +2 -0
- data/lib/thinking_sphinx/active_record/database_adapters.rb +3 -1
- data/lib/thinking_sphinx/active_record/depolymorph/association_reflection.rb +32 -0
- data/lib/thinking_sphinx/active_record/depolymorph/base_reflection.rb +32 -0
- data/lib/thinking_sphinx/active_record/depolymorph/conditions_reflection.rb +40 -0
- data/lib/thinking_sphinx/active_record/depolymorph/overridden_reflection.rb +50 -0
- data/lib/thinking_sphinx/active_record/depolymorph/scoped_reflection.rb +26 -0
- data/lib/thinking_sphinx/active_record/field.rb +2 -0
- data/lib/thinking_sphinx/active_record/filter_reflection.rb +13 -71
- data/lib/thinking_sphinx/active_record/index.rb +7 -5
- data/lib/thinking_sphinx/active_record/interpreter.rb +6 -4
- data/lib/thinking_sphinx/active_record/join_association.rb +5 -1
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +22 -3
- data/lib/thinking_sphinx/active_record/polymorpher.rb +2 -0
- data/lib/thinking_sphinx/active_record/property.rb +2 -0
- data/lib/thinking_sphinx/active_record/property_query.rb +4 -1
- data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +2 -0
- data/lib/thinking_sphinx/active_record/simple_many_query.rb +2 -0
- data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
- data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +2 -0
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +13 -0
- data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +2 -0
- data/lib/thinking_sphinx/active_record/sql_builder.rb +5 -18
- data/lib/thinking_sphinx/active_record/sql_source/template.rb +5 -3
- data/lib/thinking_sphinx/active_record/sql_source.rb +35 -9
- data/lib/thinking_sphinx/active_record.rb +14 -1
- data/lib/thinking_sphinx/attribute_types.rb +72 -0
- data/lib/thinking_sphinx/batched_search.rb +2 -0
- data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
- data/lib/thinking_sphinx/callbacks.rb +29 -0
- data/lib/thinking_sphinx/capistrano/v2.rb +2 -0
- data/lib/thinking_sphinx/capistrano/v3.rb +2 -0
- data/lib/thinking_sphinx/capistrano.rb +2 -0
- data/lib/thinking_sphinx/commander.rb +27 -0
- data/lib/thinking_sphinx/commands/base.rb +53 -0
- data/lib/thinking_sphinx/commands/clear_real_time.rb +22 -0
- data/lib/thinking_sphinx/commands/clear_sql.rb +18 -0
- data/lib/thinking_sphinx/commands/configure.rb +15 -0
- data/lib/thinking_sphinx/commands/index_real_time.rb +15 -0
- data/lib/thinking_sphinx/commands/index_sql.rb +25 -0
- data/lib/thinking_sphinx/commands/merge.rb +27 -0
- data/lib/thinking_sphinx/commands/merge_and_update.rb +57 -0
- data/lib/thinking_sphinx/commands/prepare.rb +15 -0
- data/lib/thinking_sphinx/commands/rotate.rb +13 -0
- data/lib/thinking_sphinx/commands/running.rb +15 -0
- data/lib/thinking_sphinx/commands/start_attached.rb +22 -0
- data/lib/thinking_sphinx/commands/start_detached.rb +21 -0
- data/lib/thinking_sphinx/commands/stop.rb +24 -0
- data/lib/thinking_sphinx/commands.rb +20 -0
- data/lib/thinking_sphinx/configuration/consistent_ids.rb +2 -0
- data/lib/thinking_sphinx/configuration/defaults.rb +2 -0
- data/lib/thinking_sphinx/configuration/distributed_indices.rb +3 -1
- data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
- data/lib/thinking_sphinx/configuration/minimum_fields.rb +17 -12
- data/lib/thinking_sphinx/configuration.rb +90 -74
- data/lib/thinking_sphinx/connection/client.rb +74 -0
- data/lib/thinking_sphinx/connection/jruby.rb +58 -0
- data/lib/thinking_sphinx/connection/mri.rb +26 -0
- data/lib/thinking_sphinx/connection.rb +13 -114
- data/lib/thinking_sphinx/core/field.rb +2 -0
- data/lib/thinking_sphinx/core/index.rb +22 -2
- data/lib/thinking_sphinx/core/interpreter.rb +2 -0
- data/lib/thinking_sphinx/core/property.rb +2 -0
- data/lib/thinking_sphinx/core/settings.rb +2 -0
- data/lib/thinking_sphinx/core.rb +2 -0
- data/lib/thinking_sphinx/deletion.rb +33 -13
- data/lib/thinking_sphinx/deltas/default_delta.rb +3 -1
- data/lib/thinking_sphinx/deltas/delete_job.rb +16 -4
- data/lib/thinking_sphinx/deltas/index_job.rb +14 -2
- data/lib/thinking_sphinx/deltas.rb +2 -0
- data/lib/thinking_sphinx/distributed/index.rb +25 -3
- data/lib/thinking_sphinx/distributed.rb +2 -0
- data/lib/thinking_sphinx/errors.rb +47 -3
- data/lib/thinking_sphinx/excerpter.rb +2 -0
- data/lib/thinking_sphinx/facet.rb +4 -3
- data/lib/thinking_sphinx/facet_search.rb +4 -2
- data/lib/thinking_sphinx/float_formatter.rb +2 -0
- data/lib/thinking_sphinx/frameworks/plain.rb +2 -0
- data/lib/thinking_sphinx/frameworks/rails.rb +2 -0
- data/lib/thinking_sphinx/frameworks.rb +2 -0
- data/lib/thinking_sphinx/guard/file.rb +3 -1
- data/lib/thinking_sphinx/guard/files.rb +2 -0
- data/lib/thinking_sphinx/guard/none.rb +7 -0
- data/lib/thinking_sphinx/guard.rb +3 -0
- data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
- data/lib/thinking_sphinx/index.rb +2 -0
- data/lib/thinking_sphinx/index_set.rb +27 -4
- data/lib/thinking_sphinx/indexing_strategies/all_at_once.rb +9 -0
- data/lib/thinking_sphinx/indexing_strategies/one_at_a_time.rb +16 -0
- data/lib/thinking_sphinx/interfaces/base.rb +13 -0
- data/lib/thinking_sphinx/interfaces/daemon.rb +27 -0
- data/lib/thinking_sphinx/interfaces/real_time.rb +46 -0
- data/lib/thinking_sphinx/interfaces/sql.rb +53 -0
- data/lib/thinking_sphinx/interfaces.rb +10 -0
- data/lib/thinking_sphinx/logger.rb +2 -0
- data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +6 -4
- data/lib/thinking_sphinx/masks/pagination_mask.rb +2 -0
- data/lib/thinking_sphinx/masks/scopes_mask.rb +8 -0
- data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +3 -1
- data/lib/thinking_sphinx/masks.rb +2 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +32 -9
- data/lib/thinking_sphinx/middlewares/geographer.rb +2 -0
- data/lib/thinking_sphinx/middlewares/glazier.rb +14 -1
- data/lib/thinking_sphinx/middlewares/ids_only.rb +2 -0
- data/lib/thinking_sphinx/middlewares/inquirer.rb +3 -1
- data/lib/thinking_sphinx/middlewares/middleware.rb +2 -0
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +18 -16
- data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +3 -1
- data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +4 -2
- data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
- data/lib/thinking_sphinx/middlewares.rb +7 -3
- data/lib/thinking_sphinx/panes/attributes_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/distance_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/excerpts_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/weight_pane.rb +3 -1
- data/lib/thinking_sphinx/panes.rb +2 -0
- data/lib/thinking_sphinx/processor.rb +71 -0
- data/lib/thinking_sphinx/query.rb +2 -0
- data/lib/thinking_sphinx/railtie.rb +29 -2
- data/lib/thinking_sphinx/rake_interface.rb +14 -69
- data/lib/thinking_sphinx/real_time/attribute.rb +9 -1
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +17 -7
- data/lib/thinking_sphinx/real_time/field.rb +2 -0
- data/lib/thinking_sphinx/real_time/index/template.rb +19 -1
- data/lib/thinking_sphinx/real_time/index.rb +11 -5
- data/lib/thinking_sphinx/real_time/interpreter.rb +10 -6
- data/lib/thinking_sphinx/real_time/populator.rb +12 -14
- data/lib/thinking_sphinx/real_time/processor.rb +36 -0
- data/lib/thinking_sphinx/real_time/property.rb +3 -5
- data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
- data/lib/thinking_sphinx/real_time/transcriber.rb +63 -15
- data/lib/thinking_sphinx/real_time/translator.rb +39 -0
- data/lib/thinking_sphinx/real_time.rb +22 -1
- data/lib/thinking_sphinx/scopes.rb +6 -0
- data/lib/thinking_sphinx/search/batch_inquirer.rb +2 -0
- data/lib/thinking_sphinx/search/context.rb +11 -0
- data/lib/thinking_sphinx/search/glaze.rb +2 -0
- data/lib/thinking_sphinx/search/merger.rb +2 -0
- data/lib/thinking_sphinx/search/query.rb +9 -1
- data/lib/thinking_sphinx/search/stale_ids_exception.rb +7 -3
- data/lib/thinking_sphinx/search.rb +30 -2
- data/lib/thinking_sphinx/settings.rb +128 -0
- data/lib/thinking_sphinx/sinatra.rb +3 -1
- data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +19 -5
- data/lib/thinking_sphinx/tasks.rb +55 -28
- data/lib/thinking_sphinx/test.rb +3 -1
- data/lib/thinking_sphinx/utf8.rb +2 -0
- data/lib/thinking_sphinx/wildcard.rb +3 -1
- data/lib/thinking_sphinx/with_output.rb +13 -0
- data/lib/thinking_sphinx.rb +35 -4
- data/spec/acceptance/association_scoping_spec.rb +7 -5
- data/spec/acceptance/attribute_access_spec.rb +29 -12
- data/spec/acceptance/attribute_updates_spec.rb +5 -3
- data/spec/acceptance/batch_searching_spec.rb +6 -4
- data/spec/acceptance/big_integers_spec.rb +9 -7
- data/spec/acceptance/excerpts_spec.rb +11 -10
- data/spec/acceptance/facets_spec.rb +29 -16
- data/spec/acceptance/geosearching_spec.rb +22 -10
- data/spec/acceptance/grouping_by_attributes_spec.rb +30 -28
- data/spec/acceptance/index_options_spec.rb +18 -16
- data/spec/acceptance/indexing_spec.rb +5 -3
- data/spec/acceptance/merging_spec.rb +90 -0
- data/spec/acceptance/paginating_search_results_spec.rb +21 -3
- data/spec/acceptance/real_time_updates_spec.rb +103 -5
- data/spec/acceptance/remove_deleted_records_spec.rb +64 -8
- data/spec/acceptance/search_counts_spec.rb +4 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +4 -2
- data/spec/acceptance/searching_across_models_spec.rb +15 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +12 -10
- data/spec/acceptance/searching_on_fields_spec.rb +11 -9
- data/spec/acceptance/searching_with_filters_spec.rb +35 -20
- data/spec/acceptance/searching_with_sti_spec.rb +11 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +44 -17
- data/spec/acceptance/sorting_search_results_spec.rb +21 -19
- data/spec/acceptance/spec_helper.rb +2 -13
- data/spec/acceptance/specifying_sql_spec.rb +118 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +30 -21
- data/spec/acceptance/sql_deltas_spec.rb +35 -9
- data/spec/acceptance/support/database_cleaner.rb +3 -1
- data/spec/acceptance/support/sphinx_controller.rb +25 -9
- data/spec/acceptance/support/sphinx_helpers.rb +17 -2
- data/spec/acceptance/suspended_deltas_spec.rb +14 -12
- data/spec/fixtures/database.yml +1 -1
- data/spec/internal/app/indices/admin_person_index.rb +6 -0
- data/spec/internal/app/indices/album_index.rb +9 -0
- data/spec/internal/app/indices/animal_index.rb +2 -0
- data/spec/internal/app/indices/article_index.rb +10 -3
- data/spec/internal/app/indices/bird_index.rb +2 -0
- data/spec/internal/app/indices/book_index.rb +4 -1
- data/spec/internal/app/indices/car_index.rb +2 -0
- data/spec/internal/app/indices/city_index.rb +2 -0
- data/spec/internal/app/indices/colour_index.rb +7 -0
- data/spec/internal/app/indices/product_index.rb +3 -2
- data/spec/internal/app/indices/tee_index.rb +3 -1
- data/spec/internal/app/indices/user_index.rb +2 -0
- data/spec/internal/app/models/admin/person.rb +6 -0
- data/spec/internal/app/models/album.rb +25 -0
- data/spec/internal/app/models/animal.rb +3 -0
- data/spec/internal/app/models/article.rb +4 -0
- data/spec/internal/app/models/bird.rb +3 -0
- data/spec/internal/app/models/book.rb +9 -5
- data/spec/internal/app/models/car.rb +3 -1
- data/spec/internal/app/models/categorisation.rb +10 -1
- data/spec/internal/app/models/category.rb +2 -0
- data/spec/internal/app/models/city.rb +4 -0
- data/spec/internal/app/models/colour.rb +4 -0
- data/spec/internal/app/models/event.rb +2 -0
- data/spec/internal/app/models/flightless_bird.rb +2 -0
- data/spec/internal/app/models/genre.rb +2 -0
- data/spec/internal/app/models/hardcover.rb +2 -0
- data/spec/internal/app/models/mammal.rb +2 -0
- data/spec/internal/app/models/manufacturer.rb +2 -0
- data/spec/internal/app/models/product.rb +3 -1
- data/spec/internal/app/models/tag.rb +2 -0
- data/spec/internal/app/models/tagging.rb +2 -0
- data/spec/internal/app/models/tee.rb +7 -0
- data/spec/internal/app/models/tweet.rb +2 -0
- data/spec/internal/app/models/user.rb +4 -0
- data/spec/internal/config/database.yml +12 -1
- data/spec/internal/db/schema.rb +13 -1
- data/spec/spec_helper.rb +12 -1
- data/spec/support/json_column.rb +35 -0
- data/spec/support/multi_schema.rb +5 -1
- data/spec/support/mysql.rb +25 -0
- data/spec/support/sphinx_yaml_helpers.rb +8 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +3 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +43 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +31 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +81 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +56 -29
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +27 -10
- data/spec/thinking_sphinx/active_record/column_spec.rb +15 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +39 -0
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +7 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +26 -12
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +15 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +50 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +9 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +113 -80
- data/spec/thinking_sphinx/active_record/index_spec.rb +41 -37
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +62 -59
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +16 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +69 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +146 -154
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +185 -109
- data/spec/thinking_sphinx/attribute_types_spec.rb +52 -0
- data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +46 -0
- data/spec/thinking_sphinx/commands/clear_sql_spec.rb +52 -0
- data/spec/thinking_sphinx/commands/configure_spec.rb +31 -0
- data/spec/thinking_sphinx/commands/index_real_time_spec.rb +33 -0
- data/spec/thinking_sphinx/commands/index_sql_spec.rb +86 -0
- data/spec/thinking_sphinx/commands/merge_and_update_spec.rb +106 -0
- data/spec/thinking_sphinx/commands/merge_spec.rb +48 -0
- data/spec/thinking_sphinx/commands/prepare_spec.rb +31 -0
- data/spec/thinking_sphinx/commands/running_spec.rb +30 -0
- data/spec/thinking_sphinx/commands/start_detached_spec.rb +67 -0
- data/spec/thinking_sphinx/commands/stop_spec.rb +63 -0
- data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +60 -0
- data/spec/thinking_sphinx/configuration_spec.rb +247 -94
- data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
- data/spec/thinking_sphinx/connection_spec.rb +15 -13
- data/spec/thinking_sphinx/deletion_spec.rb +17 -17
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +28 -21
- data/spec/thinking_sphinx/deltas_spec.rb +14 -12
- data/spec/thinking_sphinx/errors_spec.rb +59 -27
- data/spec/thinking_sphinx/excerpter_spec.rb +12 -9
- data/spec/thinking_sphinx/facet_search_spec.rb +24 -22
- data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
- data/spec/thinking_sphinx/index_set_spec.rb +59 -18
- data/spec/thinking_sphinx/index_spec.rb +28 -26
- data/spec/thinking_sphinx/interfaces/daemon_spec.rb +60 -0
- data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
- data/spec/thinking_sphinx/interfaces/sql_spec.rb +122 -0
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +22 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +20 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +45 -21
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +11 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +12 -9
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +9 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +60 -58
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +7 -4
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +39 -17
- data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +3 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +6 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +8 -6
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +4 -2
- data/spec/thinking_sphinx/rake_interface_spec.rb +17 -235
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +15 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +114 -28
- data/spec/thinking_sphinx/real_time/field_spec.rb +16 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +83 -32
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +44 -42
- data/spec/thinking_sphinx/real_time/transcribe_instance_spec.rb +35 -0
- data/spec/thinking_sphinx/real_time/transcriber_spec.rb +109 -0
- data/spec/thinking_sphinx/real_time/translator_spec.rb +17 -0
- data/spec/thinking_sphinx/scopes_spec.rb +11 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +17 -15
- data/spec/thinking_sphinx/search/query_spec.rb +19 -10
- data/spec/thinking_sphinx/search_spec.rb +30 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +18 -11
- data/spec/thinking_sphinx_spec.rb +10 -7
- data/thinking-sphinx.gemspec +17 -10
- metadata +157 -49
- data/HISTORY +0 -248
- data/gemfiles/.gitignore +0 -1
- data/gemfiles/rails_3_2.gemfile +0 -11
- data/gemfiles/rails_4_0.gemfile +0 -11
- data/gemfiles/rails_4_1.gemfile +0 -11
- data/gemfiles/rails_4_2.gemfile +0 -11
- data/lib/thinking_sphinx/controller.rb +0 -10
- data/lib/thinking_sphinx/middlewares/utf8.rb +0 -27
- data/lib/thinking_sphinx/sphinxql.rb +0 -23
|
@@ -1,46 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::Index do
|
|
4
6
|
let(:index) { ThinkingSphinx::ActiveRecord::Index.new :user }
|
|
5
|
-
let(:indices_path) { double('indices path', :join => '') }
|
|
6
7
|
let(:config) { double('config', :settings => {},
|
|
7
|
-
:indices_location =>
|
|
8
|
+
:indices_location => 'location', :next_offset => 8,
|
|
9
|
+
:index_set_class => index_set_class) }
|
|
10
|
+
let(:index_set_class) { double :reference_name => :user }
|
|
8
11
|
|
|
9
12
|
before :each do
|
|
10
|
-
ThinkingSphinx::Configuration.
|
|
13
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
describe '#append_source' do
|
|
14
|
-
let(:model) { double('model', :primary_key => :id
|
|
17
|
+
let(:model) { double('model', :primary_key => :id,
|
|
18
|
+
:table_exists? => true) }
|
|
15
19
|
let(:source) { double('source') }
|
|
16
20
|
|
|
17
21
|
before :each do
|
|
18
|
-
ActiveSupport::Inflector.
|
|
19
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
20
|
-
config.
|
|
22
|
+
allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
|
|
23
|
+
allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages :new => source
|
|
24
|
+
allow(config).to receive_messages :next_offset => 17
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
it "adds a source to the index" do
|
|
24
|
-
index.sources.
|
|
28
|
+
expect(index.sources).to receive(:<<).with(source)
|
|
25
29
|
|
|
26
30
|
index.append_source
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
it "creates the source with the index's offset" do
|
|
30
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
34
|
+
expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
|
|
31
35
|
with(model, hash_including(:offset => 17)).and_return(source)
|
|
32
36
|
|
|
33
37
|
index.append_source
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
it "returns the new source" do
|
|
37
|
-
index.append_source.
|
|
41
|
+
expect(index.append_source).to eq(source)
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
it "defaults to the model's primary key" do
|
|
41
|
-
model.
|
|
45
|
+
allow(model).to receive_messages :primary_key => :sphinx_id
|
|
42
46
|
|
|
43
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
47
|
+
expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
|
|
44
48
|
with(model, hash_including(:primary_key => :sphinx_id)).
|
|
45
49
|
and_return(source)
|
|
46
50
|
|
|
@@ -48,9 +52,9 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
it "uses a custom column when set" do
|
|
51
|
-
model.
|
|
55
|
+
allow(model).to receive_messages :primary_key => :sphinx_id
|
|
52
56
|
|
|
53
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
57
|
+
expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
|
|
54
58
|
with(model, hash_including(:primary_key => :custom_sphinx_id)).
|
|
55
59
|
and_return(source)
|
|
56
60
|
|
|
@@ -60,9 +64,9 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
60
64
|
end
|
|
61
65
|
|
|
62
66
|
it "defaults to id if no primary key is set" do
|
|
63
|
-
model.
|
|
67
|
+
allow(model).to receive_messages :primary_key => nil
|
|
64
68
|
|
|
65
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
69
|
+
expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
|
|
66
70
|
with(model, hash_including(:primary_key => :id)).
|
|
67
71
|
and_return(source)
|
|
68
72
|
|
|
@@ -72,12 +76,12 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
72
76
|
|
|
73
77
|
describe '#delta?' do
|
|
74
78
|
it "defaults to false" do
|
|
75
|
-
index.
|
|
79
|
+
expect(index).not_to be_delta
|
|
76
80
|
end
|
|
77
81
|
|
|
78
82
|
it "reflects the delta? option" do
|
|
79
83
|
index = ThinkingSphinx::ActiveRecord::Index.new :user, :delta? => true
|
|
80
|
-
index.
|
|
84
|
+
expect(index).to be_delta
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
|
|
@@ -88,16 +92,16 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
88
92
|
index = ThinkingSphinx::ActiveRecord::Index.new :user,
|
|
89
93
|
:delta_processor => processor_class
|
|
90
94
|
|
|
91
|
-
index.delta_processor.
|
|
95
|
+
expect(index.delta_processor).to eq(processor)
|
|
92
96
|
end
|
|
93
97
|
end
|
|
94
98
|
|
|
95
99
|
describe '#document_id_for_key' do
|
|
96
100
|
it "calculates the document id based on offset and number of indices" do
|
|
97
|
-
config.
|
|
98
|
-
config.
|
|
101
|
+
allow(config).to receive_message_chain(:indices, :count).and_return(5)
|
|
102
|
+
allow(config).to receive_messages :next_offset => 7
|
|
99
103
|
|
|
100
|
-
index.document_id_for_key(123).
|
|
104
|
+
expect(index.document_id_for_key(123)).to eq(622)
|
|
101
105
|
end
|
|
102
106
|
end
|
|
103
107
|
|
|
@@ -109,14 +113,14 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
109
113
|
end
|
|
110
114
|
|
|
111
115
|
it "interprets the definition block" do
|
|
112
|
-
ThinkingSphinx::ActiveRecord::Interpreter.
|
|
116
|
+
expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:translate!).
|
|
113
117
|
with(index, block)
|
|
114
118
|
|
|
115
119
|
index.interpret_definition!
|
|
116
120
|
end
|
|
117
121
|
|
|
118
122
|
it "only interprets the definition block once" do
|
|
119
|
-
ThinkingSphinx::ActiveRecord::Interpreter.
|
|
123
|
+
expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:translate!).
|
|
120
124
|
once
|
|
121
125
|
|
|
122
126
|
index.interpret_definition!
|
|
@@ -128,13 +132,13 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
128
132
|
let(:model) { double('model') }
|
|
129
133
|
|
|
130
134
|
it "translates symbol references to model class" do
|
|
131
|
-
ActiveSupport::Inflector.
|
|
135
|
+
allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
|
|
132
136
|
|
|
133
|
-
index.model.
|
|
137
|
+
expect(index.model).to eq(model)
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
it "memoizes the result" do
|
|
137
|
-
ActiveSupport::Inflector.
|
|
141
|
+
expect(ActiveSupport::Inflector).to receive(:constantize).with('User').once.
|
|
138
142
|
and_return(model)
|
|
139
143
|
|
|
140
144
|
index.model
|
|
@@ -145,7 +149,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
145
149
|
describe '#morphology' do
|
|
146
150
|
context 'with a render' do
|
|
147
151
|
before :each do
|
|
148
|
-
FileUtils.
|
|
152
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
149
153
|
end
|
|
150
154
|
|
|
151
155
|
it "defaults to nil" do
|
|
@@ -154,7 +158,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
154
158
|
rescue Riddle::Configuration::ConfigurationError
|
|
155
159
|
end
|
|
156
160
|
|
|
157
|
-
index.morphology.
|
|
161
|
+
expect(index.morphology).to be_nil
|
|
158
162
|
end
|
|
159
163
|
|
|
160
164
|
it "reads from the settings file if provided" do
|
|
@@ -165,7 +169,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
165
169
|
rescue Riddle::Configuration::ConfigurationError
|
|
166
170
|
end
|
|
167
171
|
|
|
168
|
-
index.morphology.
|
|
172
|
+
expect(index.morphology).to eq('stem_en')
|
|
169
173
|
end
|
|
170
174
|
end
|
|
171
175
|
end
|
|
@@ -173,26 +177,26 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
173
177
|
describe '#name' do
|
|
174
178
|
it "uses the core suffix by default" do
|
|
175
179
|
index = ThinkingSphinx::ActiveRecord::Index.new :user
|
|
176
|
-
index.name.
|
|
180
|
+
expect(index.name).to eq('user_core')
|
|
177
181
|
end
|
|
178
182
|
|
|
179
183
|
it "uses the delta suffix when delta? is true" do
|
|
180
184
|
index = ThinkingSphinx::ActiveRecord::Index.new :user, :delta? => true
|
|
181
|
-
index.name.
|
|
185
|
+
expect(index.name).to eq('user_delta')
|
|
182
186
|
end
|
|
183
187
|
end
|
|
184
188
|
|
|
185
189
|
describe '#offset' do
|
|
186
190
|
before :each do
|
|
187
|
-
config.
|
|
191
|
+
allow(config).to receive_messages :next_offset => 4
|
|
188
192
|
end
|
|
189
193
|
|
|
190
194
|
it "uses the next offset value from the configuration" do
|
|
191
|
-
index.offset.
|
|
195
|
+
expect(index.offset).to eq(4)
|
|
192
196
|
end
|
|
193
197
|
|
|
194
198
|
it "uses the reference to get a unique offset" do
|
|
195
|
-
config.
|
|
199
|
+
expect(config).to receive(:next_offset).with(:user).and_return(2)
|
|
196
200
|
|
|
197
201
|
index.offset
|
|
198
202
|
end
|
|
@@ -200,11 +204,11 @@ describe ThinkingSphinx::ActiveRecord::Index do
|
|
|
200
204
|
|
|
201
205
|
describe '#render' do
|
|
202
206
|
before :each do
|
|
203
|
-
FileUtils.
|
|
207
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
204
208
|
end
|
|
205
209
|
|
|
206
210
|
it "interprets the provided definition" do
|
|
207
|
-
index.
|
|
211
|
+
expect(index).to receive(:interpret_definition!).at_least(:once)
|
|
208
212
|
|
|
209
213
|
begin
|
|
210
214
|
index.render
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
@@ -13,23 +15,28 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
13
15
|
let(:block) { Proc.new { } }
|
|
14
16
|
|
|
15
17
|
before :each do
|
|
16
|
-
ThinkingSphinx::ActiveRecord::SQLSource.
|
|
17
|
-
|
|
18
|
+
allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages(
|
|
19
|
+
:new => source
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
allow(source).to receive_messages(
|
|
23
|
+
:model => model, :add_attribute => nil, :add_field => nil
|
|
24
|
+
)
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
describe '.translate!' do
|
|
21
28
|
let(:instance) { double('interpreter', :translate! => true) }
|
|
22
29
|
|
|
23
30
|
it "creates a new interpreter instance with the given block and index" do
|
|
24
|
-
ThinkingSphinx::ActiveRecord::Interpreter.
|
|
31
|
+
expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:new).
|
|
25
32
|
with(index, block).and_return(instance)
|
|
26
33
|
|
|
27
34
|
ThinkingSphinx::ActiveRecord::Interpreter.translate! index, block
|
|
28
35
|
end
|
|
29
36
|
|
|
30
37
|
it "calls translate! on the instance" do
|
|
31
|
-
ThinkingSphinx::ActiveRecord::Interpreter.
|
|
32
|
-
instance.
|
|
38
|
+
allow(ThinkingSphinx::ActiveRecord::Interpreter).to receive_messages(:new => instance)
|
|
39
|
+
expect(instance).to receive(:translate!)
|
|
33
40
|
|
|
34
41
|
ThinkingSphinx::ActiveRecord::Interpreter.translate! index, block
|
|
35
42
|
end
|
|
@@ -37,13 +44,13 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
37
44
|
|
|
38
45
|
describe '#group_by' do
|
|
39
46
|
it "adds a source to the index" do
|
|
40
|
-
index.
|
|
47
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
41
48
|
|
|
42
49
|
instance.group_by 'lat'
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
it "only adds a single source for the given context" do
|
|
46
|
-
index.
|
|
53
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
47
54
|
|
|
48
55
|
instance.group_by 'lat'
|
|
49
56
|
instance.group_by 'lng'
|
|
@@ -52,7 +59,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
52
59
|
it "appends a new grouping statement to the source" do
|
|
53
60
|
instance.group_by 'lat'
|
|
54
61
|
|
|
55
|
-
source.groupings.
|
|
62
|
+
expect(source.groupings).to include('lat')
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
|
@@ -61,48 +68,46 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
61
68
|
let(:attribute) { double('attribute') }
|
|
62
69
|
|
|
63
70
|
before :each do
|
|
64
|
-
ThinkingSphinx::ActiveRecord::Attribute.
|
|
71
|
+
allow(ThinkingSphinx::ActiveRecord::Attribute).to receive_messages :new => attribute
|
|
65
72
|
end
|
|
66
73
|
|
|
67
74
|
it "adds a source to the index" do
|
|
68
|
-
index.
|
|
75
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
69
76
|
|
|
70
77
|
instance.has column
|
|
71
78
|
end
|
|
72
79
|
|
|
73
80
|
it "only adds a single source for the given context" do
|
|
74
|
-
index.
|
|
81
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
75
82
|
|
|
76
83
|
instance.has column
|
|
77
84
|
instance.has column
|
|
78
85
|
end
|
|
79
86
|
|
|
80
87
|
it "creates a new attribute with the provided column" do
|
|
81
|
-
ThinkingSphinx::ActiveRecord::Attribute.
|
|
88
|
+
expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
|
|
82
89
|
with(model, column, {}).and_return(attribute)
|
|
83
90
|
|
|
84
91
|
instance.has column
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
it "passes through options to the attribute" do
|
|
88
|
-
ThinkingSphinx::ActiveRecord::Attribute.
|
|
89
|
-
with(model, column, :as => :other_name).and_return(attribute)
|
|
95
|
+
expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
|
|
96
|
+
with(model, column, { :as => :other_name }).and_return(attribute)
|
|
90
97
|
|
|
91
98
|
instance.has column, :as => :other_name
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
it "adds an attribute to the source" do
|
|
95
|
-
|
|
102
|
+
expect(source).to receive(:add_attribute).with(attribute)
|
|
96
103
|
|
|
97
|
-
|
|
104
|
+
instance.has column
|
|
98
105
|
end
|
|
99
106
|
|
|
100
107
|
it "adds multiple attributes when passed multiple columns" do
|
|
101
|
-
|
|
108
|
+
expect(source).to receive(:add_attribute).with(attribute).twice
|
|
102
109
|
|
|
103
|
-
|
|
104
|
-
saved_attribute == attribute
|
|
105
|
-
}.length.should == 2
|
|
110
|
+
instance.has column, column
|
|
106
111
|
end
|
|
107
112
|
end
|
|
108
113
|
|
|
@@ -111,48 +116,46 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
111
116
|
let(:field) { double('field') }
|
|
112
117
|
|
|
113
118
|
before :each do
|
|
114
|
-
ThinkingSphinx::ActiveRecord::Field.
|
|
119
|
+
allow(ThinkingSphinx::ActiveRecord::Field).to receive_messages :new => field
|
|
115
120
|
end
|
|
116
121
|
|
|
117
122
|
it "adds a source to the index" do
|
|
118
|
-
index.
|
|
123
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
119
124
|
|
|
120
125
|
instance.indexes column
|
|
121
126
|
end
|
|
122
127
|
|
|
123
128
|
it "only adds a single source for the given context" do
|
|
124
|
-
index.
|
|
129
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
125
130
|
|
|
126
131
|
instance.indexes column
|
|
127
132
|
instance.indexes column
|
|
128
133
|
end
|
|
129
134
|
|
|
130
135
|
it "creates a new field with the provided column" do
|
|
131
|
-
ThinkingSphinx::ActiveRecord::Field.
|
|
136
|
+
expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
|
|
132
137
|
with(model, column, {}).and_return(field)
|
|
133
138
|
|
|
134
139
|
instance.indexes column
|
|
135
140
|
end
|
|
136
141
|
|
|
137
142
|
it "passes through options to the field" do
|
|
138
|
-
ThinkingSphinx::ActiveRecord::Field.
|
|
139
|
-
with(model, column, :as => :other_name).and_return(field)
|
|
143
|
+
expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
|
|
144
|
+
with(model, column, { :as => :other_name }).and_return(field)
|
|
140
145
|
|
|
141
146
|
instance.indexes column, :as => :other_name
|
|
142
147
|
end
|
|
143
148
|
|
|
144
149
|
it "adds a field to the source" do
|
|
145
|
-
|
|
150
|
+
expect(source).to receive(:add_field).with(field)
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
instance.indexes column
|
|
148
153
|
end
|
|
149
154
|
|
|
150
155
|
it "adds multiple fields when passed multiple columns" do
|
|
151
|
-
|
|
156
|
+
expect(source).to receive(:add_field).with(field).twice
|
|
152
157
|
|
|
153
|
-
|
|
154
|
-
saved_field == field
|
|
155
|
-
}.length.should == 2
|
|
158
|
+
instance.indexes column, column
|
|
156
159
|
end
|
|
157
160
|
end
|
|
158
161
|
|
|
@@ -161,24 +164,24 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
161
164
|
let(:association) { double('association') }
|
|
162
165
|
|
|
163
166
|
before :each do
|
|
164
|
-
ThinkingSphinx::ActiveRecord::Association.
|
|
167
|
+
allow(ThinkingSphinx::ActiveRecord::Association).to receive_messages :new => association
|
|
165
168
|
end
|
|
166
169
|
|
|
167
170
|
it "adds a source to the index" do
|
|
168
|
-
index.
|
|
171
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
169
172
|
|
|
170
173
|
instance.join column
|
|
171
174
|
end
|
|
172
175
|
|
|
173
176
|
it "only adds a single source for the given context" do
|
|
174
|
-
index.
|
|
177
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
175
178
|
|
|
176
179
|
instance.join column
|
|
177
180
|
instance.join column
|
|
178
181
|
end
|
|
179
182
|
|
|
180
183
|
it "creates a new association with the provided column" do
|
|
181
|
-
ThinkingSphinx::ActiveRecord::Association.
|
|
184
|
+
expect(ThinkingSphinx::ActiveRecord::Association).to receive(:new).
|
|
182
185
|
with(column).and_return(association)
|
|
183
186
|
|
|
184
187
|
instance.join column
|
|
@@ -187,15 +190,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
187
190
|
it "adds an association to the source" do
|
|
188
191
|
instance.join column
|
|
189
192
|
|
|
190
|
-
source.associations.
|
|
193
|
+
expect(source.associations).to include(association)
|
|
191
194
|
end
|
|
192
195
|
|
|
193
196
|
it "adds multiple fields when passed multiple columns" do
|
|
194
197
|
instance.join column, column
|
|
195
198
|
|
|
196
|
-
source.associations.select { |saved_assoc|
|
|
199
|
+
expect(source.associations.select { |saved_assoc|
|
|
197
200
|
saved_assoc == association
|
|
198
|
-
}.length.
|
|
201
|
+
}.length).to eq(2)
|
|
199
202
|
end
|
|
200
203
|
end
|
|
201
204
|
|
|
@@ -203,15 +206,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
203
206
|
let(:column) { double('column') }
|
|
204
207
|
|
|
205
208
|
before :each do
|
|
206
|
-
ThinkingSphinx::ActiveRecord::Column.
|
|
209
|
+
allow(ThinkingSphinx::ActiveRecord::Column).to receive_messages(:new => column)
|
|
207
210
|
end
|
|
208
211
|
|
|
209
212
|
it "returns a new column for the given method" do
|
|
210
|
-
instance.id.
|
|
213
|
+
expect(instance.id).to eq(column)
|
|
211
214
|
end
|
|
212
215
|
|
|
213
216
|
it "should initialise the column with the method name and arguments" do
|
|
214
|
-
ThinkingSphinx::ActiveRecord::Column.
|
|
217
|
+
expect(ThinkingSphinx::ActiveRecord::Column).to receive(:new).
|
|
215
218
|
with(:users, :posts, :subject).and_return(column)
|
|
216
219
|
|
|
217
220
|
instance.users(:posts, :subject)
|
|
@@ -220,26 +223,26 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
220
223
|
|
|
221
224
|
describe '#set_database' do
|
|
222
225
|
before :each do
|
|
223
|
-
source.
|
|
226
|
+
allow(source).to receive_messages :set_database_settings => true
|
|
224
227
|
|
|
225
228
|
stub_const 'ActiveRecord::Base',
|
|
226
229
|
double(:configurations => {'other' => {'baz' => 'qux'}})
|
|
227
230
|
end
|
|
228
231
|
|
|
229
232
|
it "sends through a hash if provided" do
|
|
230
|
-
source.
|
|
233
|
+
expect(source).to receive(:set_database_settings).with({ :foo => :bar })
|
|
231
234
|
|
|
232
235
|
instance.set_database :foo => :bar
|
|
233
236
|
end
|
|
234
237
|
|
|
235
238
|
it "finds the environment settings if given a string key" do
|
|
236
|
-
source.
|
|
239
|
+
expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
|
|
237
240
|
|
|
238
241
|
instance.set_database 'other'
|
|
239
242
|
end
|
|
240
243
|
|
|
241
244
|
it "finds the environment settings if given a symbol key" do
|
|
242
|
-
source.
|
|
245
|
+
expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
|
|
243
246
|
|
|
244
247
|
instance.set_database :other
|
|
245
248
|
end
|
|
@@ -247,19 +250,19 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
247
250
|
|
|
248
251
|
describe '#set_property' do
|
|
249
252
|
before :each do
|
|
250
|
-
index.class.
|
|
251
|
-
source.class.
|
|
253
|
+
allow(index.class).to receive_messages :settings => [:morphology]
|
|
254
|
+
allow(source.class).to receive_messages :settings => [:mysql_ssl_cert]
|
|
252
255
|
end
|
|
253
256
|
|
|
254
257
|
it 'saves other settings as index options' do
|
|
255
258
|
instance.set_property :field_weights => {:name => 10}
|
|
256
259
|
|
|
257
|
-
index.options[:field_weights].
|
|
260
|
+
expect(index.options[:field_weights]).to eq({:name => 10})
|
|
258
261
|
end
|
|
259
262
|
|
|
260
263
|
context 'index settings' do
|
|
261
264
|
it "sets the provided setting" do
|
|
262
|
-
index.
|
|
265
|
+
expect(index).to receive(:morphology=).with('stem_en')
|
|
263
266
|
|
|
264
267
|
instance.set_property :morphology => 'stem_en'
|
|
265
268
|
end
|
|
@@ -267,24 +270,24 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
267
270
|
|
|
268
271
|
context 'source settings' do
|
|
269
272
|
before :each do
|
|
270
|
-
source.
|
|
273
|
+
allow(source).to receive_messages :mysql_ssl_cert= => true
|
|
271
274
|
end
|
|
272
275
|
|
|
273
276
|
it "adds a source to the index" do
|
|
274
|
-
index.
|
|
277
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
275
278
|
|
|
276
279
|
instance.set_property :mysql_ssl_cert => 'private.cert'
|
|
277
280
|
end
|
|
278
281
|
|
|
279
282
|
it "only adds a single source for the given context" do
|
|
280
|
-
index.
|
|
283
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
281
284
|
|
|
282
285
|
instance.set_property :mysql_ssl_cert => 'private.cert'
|
|
283
286
|
instance.set_property :mysql_ssl_cert => 'private.cert'
|
|
284
287
|
end
|
|
285
288
|
|
|
286
289
|
it "sets the provided setting" do
|
|
287
|
-
source.
|
|
290
|
+
expect(source).to receive(:mysql_ssl_cert=).with('private.cert')
|
|
288
291
|
|
|
289
292
|
instance.set_property :mysql_ssl_cert => 'private.cert'
|
|
290
293
|
end
|
|
@@ -298,20 +301,20 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
298
301
|
}
|
|
299
302
|
|
|
300
303
|
interpreter = ThinkingSphinx::ActiveRecord::Interpreter.new index, block
|
|
301
|
-
interpreter.translate
|
|
302
|
-
|
|
304
|
+
expect(interpreter.translate!).
|
|
305
|
+
to eq(interpreter.__id__)
|
|
303
306
|
end
|
|
304
307
|
end
|
|
305
308
|
|
|
306
309
|
describe '#where' do
|
|
307
310
|
it "adds a source to the index" do
|
|
308
|
-
index.
|
|
311
|
+
expect(index).to receive(:append_source).and_return(source)
|
|
309
312
|
|
|
310
313
|
instance.where 'id > 100'
|
|
311
314
|
end
|
|
312
315
|
|
|
313
316
|
it "only adds a single source for the given context" do
|
|
314
|
-
index.
|
|
317
|
+
expect(index).to receive(:append_source).once.and_return(source)
|
|
315
318
|
|
|
316
319
|
instance.where 'id > 100'
|
|
317
320
|
instance.where 'id < 150'
|
|
@@ -320,7 +323,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
|
|
|
320
323
|
it "appends a new grouping statement to the source" do
|
|
321
324
|
instance.where 'id > 100'
|
|
322
325
|
|
|
323
|
-
source.conditions.
|
|
326
|
+
expect(source.conditions).to include('id > 100')
|
|
324
327
|
end
|
|
325
328
|
end
|
|
326
329
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::Polymorpher do
|
|
@@ -23,29 +25,29 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
|
|
|
23
25
|
let(:animal_reflection) { double 'Animal Reflection' }
|
|
24
26
|
|
|
25
27
|
before :each do
|
|
26
|
-
ThinkingSphinx::ActiveRecord::FilterReflection.
|
|
27
|
-
|
|
28
|
+
allow(ThinkingSphinx::ActiveRecord::FilterReflection).
|
|
29
|
+
to receive(:call).
|
|
28
30
|
and_return(article_reflection, animal_reflection)
|
|
29
31
|
|
|
30
|
-
model.
|
|
32
|
+
allow(model).to receive(:reflect_on_association) do |name|
|
|
31
33
|
name == :foo ? reflection : nil
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
if ActiveRecord::Reflection.respond_to?(:add_reflection)
|
|
35
|
-
ActiveRecord::Reflection.
|
|
37
|
+
allow(ActiveRecord::Reflection).to receive :add_reflection
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
it "creates a new reflection for each class" do
|
|
40
|
-
ThinkingSphinx::ActiveRecord::FilterReflection.
|
|
41
|
-
|
|
42
|
+
allow(ThinkingSphinx::ActiveRecord::FilterReflection).
|
|
43
|
+
to receive(:call).and_call_original
|
|
42
44
|
|
|
43
|
-
ThinkingSphinx::ActiveRecord::FilterReflection.
|
|
44
|
-
|
|
45
|
+
expect(ThinkingSphinx::ActiveRecord::FilterReflection).
|
|
46
|
+
to receive(:call).
|
|
45
47
|
with(reflection, :foo_article, 'Article').
|
|
46
48
|
and_return(article_reflection)
|
|
47
|
-
ThinkingSphinx::ActiveRecord::FilterReflection.
|
|
48
|
-
|
|
49
|
+
expect(ThinkingSphinx::ActiveRecord::FilterReflection).
|
|
50
|
+
to receive(:call).
|
|
49
51
|
with(reflection, :foo_animal, 'Animal').
|
|
50
52
|
and_return(animal_reflection)
|
|
51
53
|
|
|
@@ -54,9 +56,9 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
|
|
|
54
56
|
|
|
55
57
|
it "adds the new reflections to the end-of-stack model" do
|
|
56
58
|
if ActiveRecord::Reflection.respond_to?(:add_reflection)
|
|
57
|
-
ActiveRecord::Reflection.
|
|
59
|
+
expect(ActiveRecord::Reflection).to receive(:add_reflection).
|
|
58
60
|
with(model, :foo_article, article_reflection)
|
|
59
|
-
ActiveRecord::Reflection.
|
|
61
|
+
expect(ActiveRecord::Reflection).to receive(:add_reflection).
|
|
60
62
|
with(model, :foo_animal, animal_reflection)
|
|
61
63
|
|
|
62
64
|
polymorpher.morph!
|
|
@@ -69,14 +71,14 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
|
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
it "rebases each field" do
|
|
72
|
-
field.
|
|
74
|
+
expect(field).to receive(:rebase).with([:a, :b, :foo],
|
|
73
75
|
:to => [[:a, :b, :foo_article], [:a, :b, :foo_animal]])
|
|
74
76
|
|
|
75
77
|
polymorpher.morph!
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
it "rebases each attribute" do
|
|
79
|
-
attribute.
|
|
81
|
+
expect(attribute).to receive(:rebase).with([:a, :b, :foo],
|
|
80
82
|
:to => [[:a, :b, :foo_article], [:a, :b, :foo_animal]])
|
|
81
83
|
|
|
82
84
|
polymorpher.morph!
|