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,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
@@ -5,7 +7,7 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
5
7
|
:fields => [], :attributes => [], :disable_range? => false,
|
|
6
8
|
:delta_processor => nil, :conditions => [], :groupings => [],
|
|
7
9
|
:adapter => adapter, :associations => [], :primary_key => :id,
|
|
8
|
-
:options => {}) }
|
|
10
|
+
:options => {}, :properties => []) }
|
|
9
11
|
let(:model) { double('model', :connection => connection,
|
|
10
12
|
:descends_from_active_record? => true, :column_names => [],
|
|
11
13
|
:inheritance_column => 'type', :unscoped => relation,
|
|
@@ -22,24 +24,24 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
22
24
|
let(:builder) { ThinkingSphinx::ActiveRecord::SQLBuilder.new source }
|
|
23
25
|
|
|
24
26
|
before :each do
|
|
25
|
-
ThinkingSphinx::Configuration.
|
|
26
|
-
ThinkingSphinx::ActiveRecord::PropertySQLPresenter.
|
|
27
|
-
Joiner::Joins.
|
|
28
|
-
relation.
|
|
27
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
28
|
+
allow(ThinkingSphinx::ActiveRecord::PropertySQLPresenter).to receive_messages :new => presenter
|
|
29
|
+
allow(Joiner::Joins).to receive_messages :new => associations
|
|
30
|
+
allow(relation).to receive_messages :select => relation, :where => relation, :group => relation,
|
|
29
31
|
:order => relation, :joins => relation, :to_sql => ''
|
|
30
|
-
connection.
|
|
32
|
+
allow(connection).to receive(:quote_column_name) { |column| "`#{column}`"}
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
describe 'sql_query' do
|
|
34
36
|
before :each do
|
|
35
|
-
source.
|
|
37
|
+
allow(source).to receive_messages :type => 'mysql'
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
it "adds source associations to the joins of the query" do
|
|
39
41
|
source.associations << double('association',
|
|
40
42
|
:stack => [:user, :posts], :string? => false)
|
|
41
43
|
|
|
42
|
-
associations.
|
|
44
|
+
expect(associations).to receive(:add_join_to).with([:user, :posts])
|
|
43
45
|
|
|
44
46
|
builder.sql_query
|
|
45
47
|
end
|
|
@@ -48,25 +50,25 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
48
50
|
source.associations << double('association',
|
|
49
51
|
:to_s => 'my string', :string? => true)
|
|
50
52
|
|
|
51
|
-
relation.
|
|
53
|
+
expect(relation).to receive(:joins).with(['my string']).and_return(relation)
|
|
52
54
|
|
|
53
55
|
builder.sql_query
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
context 'MySQL adapter' do
|
|
57
59
|
before :each do
|
|
58
|
-
source.
|
|
60
|
+
allow(source).to receive_messages :type => 'mysql'
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
it "returns the relation's query" do
|
|
62
|
-
relation.
|
|
64
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
63
65
|
|
|
64
|
-
builder.sql_query.
|
|
66
|
+
expect(builder.sql_query).to eq('SELECT * FROM people')
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
it "ensures results aren't from cache" do
|
|
68
|
-
relation.
|
|
69
|
-
string.
|
|
70
|
+
expect(relation).to receive(:select) do |string|
|
|
71
|
+
expect(string).to match(/^SQL_NO_CACHE /)
|
|
70
72
|
relation
|
|
71
73
|
end
|
|
72
74
|
|
|
@@ -74,8 +76,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
it "adds the document id using the offset and index count" do
|
|
77
|
-
relation.
|
|
78
|
-
string.
|
|
79
|
+
expect(relation).to receive(:select) do |string|
|
|
80
|
+
expect(string).to match(/`users`.`id` \* 5 \+ 3 AS `id`/)
|
|
79
81
|
relation
|
|
80
82
|
end
|
|
81
83
|
|
|
@@ -85,8 +87,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
85
87
|
it "adds each field to the SELECT clause" do
|
|
86
88
|
source.fields << double('field')
|
|
87
89
|
|
|
88
|
-
relation.
|
|
89
|
-
string.
|
|
90
|
+
expect(relation).to receive(:select) do |string|
|
|
91
|
+
expect(string).to match(/`name` AS `name`/)
|
|
90
92
|
relation
|
|
91
93
|
end
|
|
92
94
|
|
|
@@ -95,10 +97,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
95
97
|
|
|
96
98
|
it "adds each attribute to the SELECT clause" do
|
|
97
99
|
source.attributes << double('attribute')
|
|
98
|
-
presenter.
|
|
100
|
+
allow(presenter).to receive_messages(:to_select => '`created_at` AS `created_at`')
|
|
99
101
|
|
|
100
|
-
relation.
|
|
101
|
-
string.
|
|
102
|
+
expect(relation).to receive(:select) do |string|
|
|
103
|
+
expect(string).to match(/`created_at` AS `created_at`/)
|
|
102
104
|
relation
|
|
103
105
|
end
|
|
104
106
|
|
|
@@ -106,8 +108,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
106
108
|
end
|
|
107
109
|
|
|
108
110
|
it "limits results to a set range" do
|
|
109
|
-
relation.
|
|
110
|
-
string.
|
|
111
|
+
expect(relation).to receive(:where) do |string|
|
|
112
|
+
expect(string).to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
111
113
|
relation
|
|
112
114
|
end
|
|
113
115
|
|
|
@@ -115,10 +117,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
115
117
|
end
|
|
116
118
|
|
|
117
119
|
it "shouldn't limit results to a range if ranges are disabled" do
|
|
118
|
-
source.
|
|
120
|
+
allow(source).to receive_messages :disable_range? => true
|
|
119
121
|
|
|
120
|
-
relation.
|
|
121
|
-
string.
|
|
122
|
+
expect(relation).to receive(:where) do |string|
|
|
123
|
+
expect(string).not_to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
122
124
|
relation
|
|
123
125
|
end
|
|
124
126
|
|
|
@@ -128,8 +130,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
128
130
|
it "adds source conditions" do
|
|
129
131
|
source.conditions << 'created_at > NOW()'
|
|
130
132
|
|
|
131
|
-
relation.
|
|
132
|
-
string.
|
|
133
|
+
expect(relation).to receive(:where) do |string|
|
|
134
|
+
expect(string).to match(/created_at > NOW()/)
|
|
133
135
|
relation
|
|
134
136
|
end
|
|
135
137
|
|
|
@@ -137,8 +139,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
137
139
|
end
|
|
138
140
|
|
|
139
141
|
it "groups by the primary key" do
|
|
140
|
-
relation.
|
|
141
|
-
string.
|
|
142
|
+
expect(relation).to receive(:group) do |string|
|
|
143
|
+
expect(string).to match(/`users`.`id`/)
|
|
142
144
|
relation
|
|
143
145
|
end
|
|
144
146
|
|
|
@@ -148,8 +150,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
148
150
|
it "groups each field" do
|
|
149
151
|
source.fields << double('field')
|
|
150
152
|
|
|
151
|
-
relation.
|
|
152
|
-
string.
|
|
153
|
+
expect(relation).to receive(:group) do |string|
|
|
154
|
+
expect(string).to match(/`name`/)
|
|
153
155
|
relation
|
|
154
156
|
end
|
|
155
157
|
|
|
@@ -158,10 +160,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
158
160
|
|
|
159
161
|
it "groups each attribute" do
|
|
160
162
|
source.attributes << double('attribute')
|
|
161
|
-
presenter.
|
|
163
|
+
allow(presenter).to receive_messages(:to_group => '`created_at`')
|
|
162
164
|
|
|
163
|
-
relation.
|
|
164
|
-
string.
|
|
165
|
+
expect(relation).to receive(:group) do |string|
|
|
166
|
+
expect(string).to match(/`created_at`/)
|
|
165
167
|
relation
|
|
166
168
|
end
|
|
167
169
|
|
|
@@ -171,8 +173,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
171
173
|
it "groups by source groupings" do
|
|
172
174
|
source.groupings << '`latitude`'
|
|
173
175
|
|
|
174
|
-
relation.
|
|
175
|
-
string.
|
|
176
|
+
expect(relation).to receive(:group) do |string|
|
|
177
|
+
expect(string).to match(/`latitude`/)
|
|
176
178
|
relation
|
|
177
179
|
end
|
|
178
180
|
|
|
@@ -180,7 +182,7 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
it "orders by NULL" do
|
|
183
|
-
relation.
|
|
185
|
+
expect(relation).to receive(:order).with('NULL').and_return(relation)
|
|
184
186
|
|
|
185
187
|
builder.sql_query
|
|
186
188
|
end
|
|
@@ -188,13 +190,13 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
188
190
|
context 'STI model' do
|
|
189
191
|
before :each do
|
|
190
192
|
model.column_names << 'type'
|
|
191
|
-
model.
|
|
192
|
-
model.
|
|
193
|
+
allow(model).to receive_messages :descends_from_active_record? => false
|
|
194
|
+
allow(model).to receive_messages :store_full_sti_class => true
|
|
193
195
|
end
|
|
194
196
|
|
|
195
197
|
it "groups by the inheritance column" do
|
|
196
|
-
relation.
|
|
197
|
-
string.
|
|
198
|
+
expect(relation).to receive(:group) do |string|
|
|
199
|
+
expect(string).to match(/`users`.`type`/)
|
|
198
200
|
relation
|
|
199
201
|
end
|
|
200
202
|
|
|
@@ -204,12 +206,12 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
204
206
|
context 'with a custom inheritance column' do
|
|
205
207
|
before :each do
|
|
206
208
|
model.column_names << 'custom_type'
|
|
207
|
-
model.
|
|
209
|
+
allow(model).to receive_messages :inheritance_column => 'custom_type'
|
|
208
210
|
end
|
|
209
211
|
|
|
210
212
|
it "groups by the right column" do
|
|
211
|
-
relation.
|
|
212
|
-
string.
|
|
213
|
+
expect(relation).to receive(:group) do |string|
|
|
214
|
+
expect(string).to match(/`users`.`custom_type`/)
|
|
213
215
|
relation
|
|
214
216
|
end
|
|
215
217
|
|
|
@@ -222,14 +224,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
222
224
|
let(:processor) { double('processor') }
|
|
223
225
|
|
|
224
226
|
before :each do
|
|
225
|
-
source.
|
|
226
|
-
source.
|
|
227
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
228
|
+
allow(source).to receive_messages :delta? => true
|
|
227
229
|
end
|
|
228
230
|
|
|
229
231
|
it "filters by the provided clause" do
|
|
230
|
-
processor.
|
|
231
|
-
relation.
|
|
232
|
-
string.
|
|
232
|
+
expect(processor).to receive(:clause).with(true).and_return('`delta` = 1')
|
|
233
|
+
expect(relation).to receive(:where) do |string|
|
|
234
|
+
expect(string).to match(/`delta` = 1/)
|
|
233
235
|
relation
|
|
234
236
|
end
|
|
235
237
|
|
|
@@ -243,20 +245,20 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
243
245
|
:to_group => '"name"') }
|
|
244
246
|
|
|
245
247
|
before :each do
|
|
246
|
-
source.
|
|
247
|
-
model.
|
|
248
|
-
connection.
|
|
248
|
+
allow(source).to receive_messages :type => 'pgsql'
|
|
249
|
+
allow(model).to receive_messages :quoted_table_name => '"users"'
|
|
250
|
+
allow(connection).to receive(:quote_column_name) { |column| "\"#{column}\""}
|
|
249
251
|
end
|
|
250
252
|
|
|
251
253
|
it "returns the relation's query" do
|
|
252
|
-
relation.
|
|
254
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
253
255
|
|
|
254
|
-
builder.sql_query.
|
|
256
|
+
expect(builder.sql_query).to eq('SELECT * FROM people')
|
|
255
257
|
end
|
|
256
258
|
|
|
257
259
|
it "adds the document id using the offset and index count" do
|
|
258
|
-
relation.
|
|
259
|
-
string.
|
|
260
|
+
expect(relation).to receive(:select) do |string|
|
|
261
|
+
expect(string).to match(/"users"."id" \* 5 \+ 3 AS "id"/)
|
|
260
262
|
relation
|
|
261
263
|
end
|
|
262
264
|
|
|
@@ -266,8 +268,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
266
268
|
it "adds each field to the SELECT clause" do
|
|
267
269
|
source.fields << double('field')
|
|
268
270
|
|
|
269
|
-
relation.
|
|
270
|
-
string.
|
|
271
|
+
expect(relation).to receive(:select) do |string|
|
|
272
|
+
expect(string).to match(/"name" AS "name"/)
|
|
271
273
|
relation
|
|
272
274
|
end
|
|
273
275
|
|
|
@@ -276,10 +278,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
276
278
|
|
|
277
279
|
it "adds each attribute to the SELECT clause" do
|
|
278
280
|
source.attributes << double('attribute')
|
|
279
|
-
presenter.
|
|
281
|
+
allow(presenter).to receive_messages(:to_select => '"created_at" AS "created_at"')
|
|
280
282
|
|
|
281
|
-
relation.
|
|
282
|
-
string.
|
|
283
|
+
expect(relation).to receive(:select) do |string|
|
|
284
|
+
expect(string).to match(/"created_at" AS "created_at"/)
|
|
283
285
|
relation
|
|
284
286
|
end
|
|
285
287
|
|
|
@@ -287,8 +289,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
287
289
|
end
|
|
288
290
|
|
|
289
291
|
it "limits results to a set range" do
|
|
290
|
-
relation.
|
|
291
|
-
string.
|
|
292
|
+
expect(relation).to receive(:where) do |string|
|
|
293
|
+
expect(string).to match(/"users"."id" BETWEEN \$start AND \$end/)
|
|
292
294
|
relation
|
|
293
295
|
end
|
|
294
296
|
|
|
@@ -296,10 +298,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
296
298
|
end
|
|
297
299
|
|
|
298
300
|
it "shouldn't limit results to a range if ranges are disabled" do
|
|
299
|
-
source.
|
|
301
|
+
allow(source).to receive_messages :disable_range? => true
|
|
300
302
|
|
|
301
|
-
relation.
|
|
302
|
-
string.
|
|
303
|
+
expect(relation).to receive(:where) do |string|
|
|
304
|
+
expect(string).not_to match(/"users"."id" BETWEEN \$start AND \$end/)
|
|
303
305
|
relation
|
|
304
306
|
end
|
|
305
307
|
|
|
@@ -309,8 +311,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
309
311
|
it "adds source conditions" do
|
|
310
312
|
source.conditions << 'created_at > NOW()'
|
|
311
313
|
|
|
312
|
-
relation.
|
|
313
|
-
string.
|
|
314
|
+
expect(relation).to receive(:where) do |string|
|
|
315
|
+
expect(string).to match(/created_at > NOW()/)
|
|
314
316
|
relation
|
|
315
317
|
end
|
|
316
318
|
|
|
@@ -318,8 +320,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
318
320
|
end
|
|
319
321
|
|
|
320
322
|
it "groups by the primary key" do
|
|
321
|
-
relation.
|
|
322
|
-
string.
|
|
323
|
+
expect(relation).to receive(:group) do |string|
|
|
324
|
+
expect(string).to match(/"users"."id"/)
|
|
323
325
|
relation
|
|
324
326
|
end
|
|
325
327
|
|
|
@@ -329,8 +331,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
329
331
|
it "groups each field" do
|
|
330
332
|
source.fields << double('field')
|
|
331
333
|
|
|
332
|
-
relation.
|
|
333
|
-
string.
|
|
334
|
+
expect(relation).to receive(:group) do |string|
|
|
335
|
+
expect(string).to match(/"name"/)
|
|
334
336
|
relation
|
|
335
337
|
end
|
|
336
338
|
|
|
@@ -339,10 +341,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
339
341
|
|
|
340
342
|
it "groups each attribute" do
|
|
341
343
|
source.attributes << double('attribute')
|
|
342
|
-
presenter.
|
|
344
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
343
345
|
|
|
344
|
-
relation.
|
|
345
|
-
string.
|
|
346
|
+
expect(relation).to receive(:group) do |string|
|
|
347
|
+
expect(string).to match(/"created_at"/)
|
|
346
348
|
relation
|
|
347
349
|
end
|
|
348
350
|
|
|
@@ -352,8 +354,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
352
354
|
it "groups by source groupings" do
|
|
353
355
|
source.groupings << '"latitude"'
|
|
354
356
|
|
|
355
|
-
relation.
|
|
356
|
-
string.
|
|
357
|
+
expect(relation).to receive(:group) do |string|
|
|
358
|
+
expect(string).to match(/"latitude"/)
|
|
357
359
|
relation
|
|
358
360
|
end
|
|
359
361
|
|
|
@@ -361,7 +363,7 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
361
363
|
end
|
|
362
364
|
|
|
363
365
|
it "has no ORDER clause" do
|
|
364
|
-
relation.
|
|
366
|
+
expect(relation).not_to receive(:order)
|
|
365
367
|
|
|
366
368
|
builder.sql_query
|
|
367
369
|
end
|
|
@@ -372,8 +374,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
372
374
|
end
|
|
373
375
|
|
|
374
376
|
it "groups by the primary key" do
|
|
375
|
-
relation.
|
|
376
|
-
string.
|
|
377
|
+
expect(relation).to receive(:group) do |string|
|
|
378
|
+
expect(string).to match(/"users"."id"/)
|
|
377
379
|
relation
|
|
378
380
|
end
|
|
379
381
|
|
|
@@ -383,8 +385,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
383
385
|
it "does not group by fields" do
|
|
384
386
|
source.fields << double('field')
|
|
385
387
|
|
|
386
|
-
relation.
|
|
387
|
-
string.
|
|
388
|
+
expect(relation).to receive(:group) do |string|
|
|
389
|
+
expect(string).not_to match(/"name"/)
|
|
388
390
|
relation
|
|
389
391
|
end
|
|
390
392
|
|
|
@@ -393,10 +395,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
393
395
|
|
|
394
396
|
it "does not group by attributes" do
|
|
395
397
|
source.attributes << double('attribute')
|
|
396
|
-
presenter.
|
|
398
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
397
399
|
|
|
398
|
-
relation.
|
|
399
|
-
string.
|
|
400
|
+
expect(relation).to receive(:group) do |string|
|
|
401
|
+
expect(string).not_to match(/"created_at"/)
|
|
400
402
|
relation
|
|
401
403
|
end
|
|
402
404
|
|
|
@@ -406,8 +408,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
406
408
|
it "groups by source groupings" do
|
|
407
409
|
source.groupings << '"latitude"'
|
|
408
410
|
|
|
409
|
-
relation.
|
|
410
|
-
string.
|
|
411
|
+
expect(relation).to receive(:group) do |string|
|
|
412
|
+
expect(string).to match(/"latitude"/)
|
|
411
413
|
relation
|
|
412
414
|
end
|
|
413
415
|
|
|
@@ -421,8 +423,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
421
423
|
end
|
|
422
424
|
|
|
423
425
|
it "groups by the primary key" do
|
|
424
|
-
relation.
|
|
425
|
-
string.
|
|
426
|
+
expect(relation).to receive(:group) do |string|
|
|
427
|
+
expect(string).to match(/"users"."id"/)
|
|
426
428
|
relation
|
|
427
429
|
end
|
|
428
430
|
|
|
@@ -432,8 +434,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
432
434
|
it "does not group by fields" do
|
|
433
435
|
source.fields << double('field')
|
|
434
436
|
|
|
435
|
-
relation.
|
|
436
|
-
string.
|
|
437
|
+
expect(relation).to receive(:group) do |string|
|
|
438
|
+
expect(string).not_to match(/"name"/)
|
|
437
439
|
relation
|
|
438
440
|
end
|
|
439
441
|
|
|
@@ -442,10 +444,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
442
444
|
|
|
443
445
|
it "does not group by attributes" do
|
|
444
446
|
source.attributes << double('attribute')
|
|
445
|
-
presenter.
|
|
447
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
446
448
|
|
|
447
|
-
relation.
|
|
448
|
-
string.
|
|
449
|
+
expect(relation).to receive(:group) do |string|
|
|
450
|
+
expect(string).not_to match(/"created_at"/)
|
|
449
451
|
relation
|
|
450
452
|
end
|
|
451
453
|
|
|
@@ -455,8 +457,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
455
457
|
it "groups by source groupings" do
|
|
456
458
|
source.groupings << '"latitude"'
|
|
457
459
|
|
|
458
|
-
relation.
|
|
459
|
-
string.
|
|
460
|
+
expect(relation).to receive(:group) do |string|
|
|
461
|
+
expect(string).to match(/"latitude"/)
|
|
460
462
|
relation
|
|
461
463
|
end
|
|
462
464
|
|
|
@@ -467,13 +469,13 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
467
469
|
context 'STI model' do
|
|
468
470
|
before :each do
|
|
469
471
|
model.column_names << 'type'
|
|
470
|
-
model.
|
|
471
|
-
model.
|
|
472
|
+
allow(model).to receive_messages :descends_from_active_record? => false
|
|
473
|
+
allow(model).to receive_messages :store_full_sti_class => true
|
|
472
474
|
end
|
|
473
475
|
|
|
474
476
|
it "groups by the inheritance column" do
|
|
475
|
-
relation.
|
|
476
|
-
string.
|
|
477
|
+
expect(relation).to receive(:group) do |string|
|
|
478
|
+
expect(string).to match(/"users"."type"/)
|
|
477
479
|
relation
|
|
478
480
|
end
|
|
479
481
|
|
|
@@ -483,12 +485,12 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
483
485
|
context 'with a custom inheritance column' do
|
|
484
486
|
before :each do
|
|
485
487
|
model.column_names << 'custom_type'
|
|
486
|
-
model.
|
|
488
|
+
allow(model).to receive_messages :inheritance_column => 'custom_type'
|
|
487
489
|
end
|
|
488
490
|
|
|
489
491
|
it "groups by the right column" do
|
|
490
|
-
relation.
|
|
491
|
-
string.
|
|
492
|
+
expect(relation).to receive(:group) do |string|
|
|
493
|
+
expect(string).to match(/"users"."custom_type"/)
|
|
492
494
|
relation
|
|
493
495
|
end
|
|
494
496
|
|
|
@@ -501,14 +503,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
501
503
|
let(:processor) { double('processor') }
|
|
502
504
|
|
|
503
505
|
before :each do
|
|
504
|
-
source.
|
|
505
|
-
source.
|
|
506
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
507
|
+
allow(source).to receive_messages :delta? => true
|
|
506
508
|
end
|
|
507
509
|
|
|
508
510
|
it "filters by the provided clause" do
|
|
509
|
-
processor.
|
|
510
|
-
relation.
|
|
511
|
-
string.
|
|
511
|
+
expect(processor).to receive(:clause).with(true).and_return('"delta" = 1')
|
|
512
|
+
expect(relation).to receive(:where) do |string|
|
|
513
|
+
expect(string).to match(/"delta" = 1/)
|
|
512
514
|
relation
|
|
513
515
|
end
|
|
514
516
|
|
|
@@ -518,66 +520,56 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
518
520
|
end
|
|
519
521
|
end
|
|
520
522
|
|
|
521
|
-
describe '
|
|
523
|
+
describe 'sql_query_pre' do
|
|
522
524
|
let(:processor) { double('processor', :reset_query => 'RESET DELTAS') }
|
|
523
525
|
|
|
524
|
-
|
|
525
|
-
source.
|
|
526
|
-
|
|
527
|
-
builder.sql_query_post_index.should include('RESET DELTAS')
|
|
528
|
-
end
|
|
529
|
-
|
|
530
|
-
it "adds no reset delta query if there is a delta processor and this is the delta source" do
|
|
531
|
-
source.stub :delta_processor => processor, :delta? => true
|
|
532
|
-
|
|
533
|
-
builder.sql_query_post_index.should_not include('RESET DELTAS')
|
|
526
|
+
before :each do
|
|
527
|
+
allow(source).to receive_messages :options => {}, :delta_processor => nil, :delta? => false
|
|
528
|
+
allow(adapter).to receive_messages :utf8_query_pre => ['SET UTF8']
|
|
534
529
|
end
|
|
535
|
-
end
|
|
536
530
|
|
|
537
|
-
|
|
538
|
-
|
|
531
|
+
it "adds a reset delta query if there is a delta processor and this is the core source" do
|
|
532
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
539
533
|
|
|
540
|
-
|
|
541
|
-
source.stub :options => {}, :delta_processor => nil, :delta? => false
|
|
542
|
-
adapter.stub :utf8_query_pre => ['SET UTF8']
|
|
534
|
+
expect(builder.sql_query_pre).to include('RESET DELTAS')
|
|
543
535
|
end
|
|
544
536
|
|
|
545
537
|
it "does not add a reset query if there is no delta processor" do
|
|
546
|
-
builder.sql_query_pre.
|
|
538
|
+
expect(builder.sql_query_pre).not_to include('RESET DELTAS')
|
|
547
539
|
end
|
|
548
540
|
|
|
549
541
|
it "does not add a reset query if this is a delta source" do
|
|
550
|
-
source.
|
|
551
|
-
source.
|
|
542
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
543
|
+
allow(source).to receive_messages :delta? => true
|
|
552
544
|
|
|
553
|
-
builder.sql_query_pre.
|
|
545
|
+
expect(builder.sql_query_pre).not_to include('RESET DELTAS')
|
|
554
546
|
end
|
|
555
547
|
|
|
556
548
|
it "sets the group_concat_max_len value if set" do
|
|
557
549
|
source.options[:group_concat_max_len] = 123
|
|
558
550
|
|
|
559
|
-
builder.sql_query_pre.
|
|
560
|
-
|
|
551
|
+
expect(builder.sql_query_pre).
|
|
552
|
+
to include('SET SESSION group_concat_max_len = 123')
|
|
561
553
|
end
|
|
562
554
|
|
|
563
555
|
it "does not set the group_concat_max_len if not provided" do
|
|
564
556
|
source.options[:group_concat_max_len] = nil
|
|
565
557
|
|
|
566
|
-
builder.sql_query_pre.select { |sql|
|
|
558
|
+
expect(builder.sql_query_pre.select { |sql|
|
|
567
559
|
sql[/SET SESSION group_concat_max_len/]
|
|
568
|
-
}.
|
|
560
|
+
}).to be_empty
|
|
569
561
|
end
|
|
570
562
|
|
|
571
563
|
it "sets the connection to use UTF-8 if required" do
|
|
572
564
|
source.options[:utf8?] = true
|
|
573
565
|
|
|
574
|
-
builder.sql_query_pre.
|
|
566
|
+
expect(builder.sql_query_pre).to include('SET UTF8')
|
|
575
567
|
end
|
|
576
568
|
|
|
577
569
|
it "does not set the connection to use UTF-8 if not required" do
|
|
578
570
|
source.options[:utf8?] = false
|
|
579
571
|
|
|
580
|
-
builder.sql_query_pre.
|
|
572
|
+
expect(builder.sql_query_pre).not_to include('SET UTF8')
|
|
581
573
|
end
|
|
582
574
|
|
|
583
575
|
it "adds a time-zone query by default" do
|
|
@@ -593,26 +585,26 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
593
585
|
|
|
594
586
|
describe 'sql_query_range' do
|
|
595
587
|
before :each do
|
|
596
|
-
adapter.
|
|
588
|
+
allow(adapter).to receive(:convert_nulls) { |string, default|
|
|
597
589
|
"ISNULL(#{string}, #{default})"
|
|
598
590
|
}
|
|
599
591
|
end
|
|
600
592
|
|
|
601
593
|
it "returns the relation's query" do
|
|
602
|
-
relation.
|
|
594
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
603
595
|
|
|
604
|
-
builder.sql_query_range.
|
|
596
|
+
expect(builder.sql_query_range).to eq('SELECT * FROM people')
|
|
605
597
|
end
|
|
606
598
|
|
|
607
599
|
it "returns nil if ranges are disabled" do
|
|
608
|
-
source.
|
|
600
|
+
allow(source).to receive_messages :disable_range? => true
|
|
609
601
|
|
|
610
|
-
builder.sql_query_range.
|
|
602
|
+
expect(builder.sql_query_range).to be_nil
|
|
611
603
|
end
|
|
612
604
|
|
|
613
605
|
it "selects the minimum primary key value, allowing for nulls" do
|
|
614
|
-
relation.
|
|
615
|
-
string.
|
|
606
|
+
expect(relation).to receive(:select) do |string|
|
|
607
|
+
expect(string).to match(/ISNULL\(MIN\(`users`.`id`\), 1\)/)
|
|
616
608
|
relation
|
|
617
609
|
end
|
|
618
610
|
|
|
@@ -620,8 +612,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
620
612
|
end
|
|
621
613
|
|
|
622
614
|
it "selects the maximum primary key value, allowing for nulls" do
|
|
623
|
-
relation.
|
|
624
|
-
string.
|
|
615
|
+
expect(relation).to receive(:select) do |string|
|
|
616
|
+
expect(string).to match(/ISNULL\(MAX\(`users`.`id`\), 1\)/)
|
|
625
617
|
relation
|
|
626
618
|
end
|
|
627
619
|
|
|
@@ -629,8 +621,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
629
621
|
end
|
|
630
622
|
|
|
631
623
|
it "shouldn't limit results to a range" do
|
|
632
|
-
relation.
|
|
633
|
-
string.
|
|
624
|
+
expect(relation).to receive(:where) do |string|
|
|
625
|
+
expect(string).not_to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
634
626
|
relation
|
|
635
627
|
end
|
|
636
628
|
|
|
@@ -640,8 +632,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
640
632
|
it "does not add source conditions" do
|
|
641
633
|
source.conditions << 'created_at > NOW()'
|
|
642
634
|
|
|
643
|
-
relation.
|
|
644
|
-
string.
|
|
635
|
+
expect(relation).to receive(:where) do |string|
|
|
636
|
+
expect(string).not_to match(/created_at > NOW()/)
|
|
645
637
|
relation
|
|
646
638
|
end
|
|
647
639
|
|
|
@@ -652,14 +644,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
652
644
|
let(:processor) { double('processor') }
|
|
653
645
|
|
|
654
646
|
before :each do
|
|
655
|
-
source.
|
|
656
|
-
source.
|
|
647
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
648
|
+
allow(source).to receive_messages :delta? => true
|
|
657
649
|
end
|
|
658
650
|
|
|
659
651
|
it "filters by the provided clause" do
|
|
660
|
-
processor.
|
|
661
|
-
relation.
|
|
662
|
-
string.
|
|
652
|
+
expect(processor).to receive(:clause).with(true).and_return('`delta` = 1')
|
|
653
|
+
expect(relation).to receive(:where) do |string|
|
|
654
|
+
expect(string).to match(/`delta` = 1/)
|
|
663
655
|
relation
|
|
664
656
|
end
|
|
665
657
|
|