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::SQLSource do
|
|
@@ -9,42 +11,80 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
9
11
|
let(:db_config) { {:host => 'localhost', :user => 'root',
|
|
10
12
|
:database => 'default'} }
|
|
11
13
|
let(:source) { ThinkingSphinx::ActiveRecord::SQLSource.new(model,
|
|
12
|
-
:position => 3) }
|
|
14
|
+
:position => 3, :primary_key => model.primary_key || :id ) }
|
|
13
15
|
let(:adapter) { double('adapter') }
|
|
14
16
|
|
|
15
17
|
before :each do
|
|
16
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
|
17
|
-
|
|
18
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters.
|
|
19
|
-
|
|
18
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
|
19
|
+
to receive_messages(:=== => true)
|
|
20
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
|
|
21
|
+
to receive_messages(:adapter_for => adapter)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
describe '#adapter' do
|
|
23
25
|
it "returns a database adapter for the model" do
|
|
24
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters.
|
|
25
|
-
|
|
26
|
+
expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
|
|
27
|
+
to receive(:adapter_for).with(model).and_return(adapter)
|
|
26
28
|
|
|
27
|
-
source.adapter.
|
|
29
|
+
expect(source.adapter).to eq(adapter)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#add_attribute' do
|
|
34
|
+
let(:attribute) { double('attribute', name: 'my_attribute') }
|
|
35
|
+
|
|
36
|
+
it "appends attributes to the collection" do
|
|
37
|
+
source.add_attribute attribute
|
|
38
|
+
|
|
39
|
+
expect(source.attributes.collect(&:name)).to include('my_attribute')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "replaces attributes with the same name" do
|
|
43
|
+
source.add_attribute double('attribute', name: 'my_attribute')
|
|
44
|
+
source.add_attribute attribute
|
|
45
|
+
|
|
46
|
+
matching = source.attributes.select { |attr| attr.name == attribute.name }
|
|
47
|
+
|
|
48
|
+
expect(matching).to eq([attribute])
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe '#add_field' do
|
|
53
|
+
let(:field) { double('field', name: 'my_field') }
|
|
54
|
+
|
|
55
|
+
it "appends fields to the collection" do
|
|
56
|
+
source.add_field field
|
|
57
|
+
|
|
58
|
+
expect(source.fields.collect(&:name)).to include('my_field')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "replaces fields with the same name" do
|
|
62
|
+
source.add_field double('field', name: 'my_field')
|
|
63
|
+
source.add_field field
|
|
64
|
+
|
|
65
|
+
matching = source.fields.select { |fld| fld.name == field.name }
|
|
66
|
+
|
|
67
|
+
expect(matching).to eq([field])
|
|
28
68
|
end
|
|
29
69
|
end
|
|
30
70
|
|
|
31
71
|
describe '#attributes' do
|
|
32
72
|
it "has the internal id attribute by default" do
|
|
33
|
-
source.attributes.collect(&:name).
|
|
73
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_internal_id')
|
|
34
74
|
end
|
|
35
75
|
|
|
36
76
|
it "has the class name attribute by default" do
|
|
37
|
-
source.attributes.collect(&:name).
|
|
77
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_internal_class')
|
|
38
78
|
end
|
|
39
79
|
|
|
40
80
|
it "has the internal deleted attribute by default" do
|
|
41
|
-
source.attributes.collect(&:name).
|
|
81
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_deleted')
|
|
42
82
|
end
|
|
43
83
|
|
|
44
84
|
it "marks the internal class attribute as a facet" do
|
|
45
|
-
source.attributes.detect { |attribute|
|
|
85
|
+
expect(source.attributes.detect { |attribute|
|
|
46
86
|
attribute.name == 'sphinx_internal_class'
|
|
47
|
-
}.options[:facet].
|
|
87
|
+
}.options[:facet]).to be_truthy
|
|
48
88
|
end
|
|
49
89
|
end
|
|
50
90
|
|
|
@@ -53,27 +93,29 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
53
93
|
let(:processor) { double('processor') }
|
|
54
94
|
let(:source) {
|
|
55
95
|
ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
56
|
-
:delta_processor => processor_class
|
|
96
|
+
:delta_processor => processor_class,
|
|
97
|
+
:primary_key => model.primary_key || :id
|
|
57
98
|
}
|
|
58
99
|
let(:source_with_options) {
|
|
59
100
|
ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
60
101
|
:delta_processor => processor_class,
|
|
61
|
-
:delta_options => { :opt_key => :opt_value }
|
|
102
|
+
:delta_options => { :opt_key => :opt_value },
|
|
103
|
+
:primary_key => model.primary_key || :id
|
|
62
104
|
}
|
|
63
105
|
|
|
64
106
|
it "loads the processor with the adapter" do
|
|
65
|
-
processor_class.
|
|
107
|
+
expect(processor_class).to receive(:try).with(:new, adapter, {}).
|
|
66
108
|
and_return processor
|
|
67
109
|
|
|
68
110
|
source.delta_processor
|
|
69
111
|
end
|
|
70
112
|
|
|
71
113
|
it "returns the given processor" do
|
|
72
|
-
source.delta_processor.
|
|
114
|
+
expect(source.delta_processor).to eq(processor)
|
|
73
115
|
end
|
|
74
116
|
|
|
75
117
|
it "passes given options to the processor" do
|
|
76
|
-
processor_class.
|
|
118
|
+
expect(processor_class).to receive(:try).with(:new, adapter, {:opt_key => :opt_value})
|
|
77
119
|
source_with_options.delta_processor
|
|
78
120
|
end
|
|
79
121
|
end
|
|
@@ -81,77 +123,99 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
81
123
|
describe '#delta?' do
|
|
82
124
|
it "returns the given delta setting" do
|
|
83
125
|
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
84
|
-
:delta? => true
|
|
126
|
+
:delta? => true,
|
|
127
|
+
:primary_key => model.primary_key || :id
|
|
85
128
|
|
|
86
|
-
source.
|
|
129
|
+
expect(source).to be_a_delta
|
|
87
130
|
end
|
|
88
131
|
end
|
|
89
132
|
|
|
90
133
|
describe '#disable_range?' do
|
|
91
134
|
it "returns the given range setting" do
|
|
92
135
|
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
93
|
-
:disable_range? => true
|
|
136
|
+
:disable_range? => true,
|
|
137
|
+
:primary_key => model.primary_key || :id
|
|
94
138
|
|
|
95
|
-
source.disable_range
|
|
139
|
+
expect(source.disable_range?).to be_truthy
|
|
96
140
|
end
|
|
97
141
|
end
|
|
98
142
|
|
|
99
143
|
describe '#fields' do
|
|
100
144
|
it "has the internal class field by default" do
|
|
101
|
-
source.fields.collect(&:name).
|
|
102
|
-
|
|
145
|
+
expect(source.fields.collect(&:name)).
|
|
146
|
+
to include('sphinx_internal_class_name')
|
|
103
147
|
end
|
|
104
148
|
|
|
105
149
|
it "sets the sphinx class field to use a string of the class name" do
|
|
106
|
-
source.fields.detect { |field|
|
|
150
|
+
expect(source.fields.detect { |field|
|
|
107
151
|
field.name == 'sphinx_internal_class_name'
|
|
108
|
-
}.columns.first.__name.
|
|
152
|
+
}.columns.first.__name).to eq("'User'")
|
|
109
153
|
end
|
|
110
154
|
|
|
111
155
|
it "uses the inheritance column if it exists for the sphinx class field" do
|
|
112
|
-
adapter.
|
|
113
|
-
adapter.
|
|
156
|
+
allow(adapter).to receive_messages :quoted_table_name => '"users"', :quote => '"type"'
|
|
157
|
+
allow(adapter).to receive(:convert_blank) { |clause, default|
|
|
114
158
|
"coalesce(nullif(#{clause}, ''), #{default})"
|
|
115
159
|
}
|
|
116
|
-
model.
|
|
160
|
+
allow(model).to receive_messages :column_names => ['type'], :sti_name => 'User'
|
|
117
161
|
|
|
118
|
-
source.fields.detect { |field|
|
|
162
|
+
expect(source.fields.detect { |field|
|
|
119
163
|
field.name == 'sphinx_internal_class_name'
|
|
120
|
-
}.columns.first.__name.
|
|
121
|
-
|
|
164
|
+
}.columns.first.__name).
|
|
165
|
+
to eq("coalesce(nullif(\"users\".\"type\", ''), 'User')")
|
|
122
166
|
end
|
|
123
167
|
end
|
|
124
168
|
|
|
125
169
|
describe '#name' do
|
|
126
170
|
it "defaults to the model name downcased with the given position" do
|
|
127
|
-
source.name.
|
|
171
|
+
expect(source.name).to eq('user_3')
|
|
128
172
|
end
|
|
129
173
|
|
|
130
174
|
it "allows for custom names, but adds the position suffix" do
|
|
131
175
|
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
132
|
-
:name => 'people', :position => 2
|
|
176
|
+
:name => 'people', :position => 2, :primary_key => model.primary_key || :id
|
|
133
177
|
|
|
134
|
-
source.name.
|
|
178
|
+
expect(source.name).to eq('people_2')
|
|
135
179
|
end
|
|
136
180
|
end
|
|
137
181
|
|
|
138
182
|
describe '#offset' do
|
|
139
183
|
it "returns the given offset" do
|
|
140
|
-
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
184
|
+
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
|
185
|
+
:offset => 12, :primary_key => model.primary_key || :id
|
|
141
186
|
|
|
142
|
-
source.offset.
|
|
187
|
+
expect(source.offset).to eq(12)
|
|
143
188
|
end
|
|
144
189
|
end
|
|
145
190
|
|
|
146
191
|
describe '#options' do
|
|
147
192
|
it "defaults to having utf8? set to false" do
|
|
148
|
-
source.options[:utf8?].
|
|
193
|
+
expect(source.options[:utf8?]).to be_falsey
|
|
149
194
|
end
|
|
150
195
|
|
|
151
196
|
it "sets utf8? to true if the database encoding is utf8" do
|
|
152
197
|
db_config[:encoding] = 'utf8'
|
|
153
198
|
|
|
154
|
-
source.options[:utf8?].
|
|
199
|
+
expect(source.options[:utf8?]).to be_truthy
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "sets utf8? to true if the database encoding starts with utf8" do
|
|
203
|
+
db_config[:encoding] = 'utf8mb4'
|
|
204
|
+
|
|
205
|
+
expect(source.options[:utf8?]).to be_truthy
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
describe "#primary key" do
|
|
209
|
+
let(:model) { double('model', :connection => connection,
|
|
210
|
+
:name => 'User', :column_names => [], :inheritance_column => 'type') }
|
|
211
|
+
let(:source) { ThinkingSphinx::ActiveRecord::SQLSource.new(model,
|
|
212
|
+
:position => 3, :primary_key => :custom_key) }
|
|
213
|
+
let(:template) { ThinkingSphinx::ActiveRecord::SQLSource::Template.new(source) }
|
|
214
|
+
|
|
215
|
+
it 'template should allow primary key from options' do
|
|
216
|
+
template.apply
|
|
217
|
+
template.source.attributes.collect(&:columns) == :custom_key
|
|
218
|
+
end
|
|
155
219
|
end
|
|
156
220
|
end
|
|
157
221
|
|
|
@@ -164,42 +228,34 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
164
228
|
let(:template) { double('template', :apply => true) }
|
|
165
229
|
|
|
166
230
|
before :each do
|
|
167
|
-
ThinkingSphinx::ActiveRecord::SQLBuilder.
|
|
168
|
-
ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter.
|
|
169
|
-
ThinkingSphinx::ActiveRecord::SQLSource::Template.
|
|
170
|
-
ThinkingSphinx::Configuration.
|
|
231
|
+
allow(ThinkingSphinx::ActiveRecord::SQLBuilder).to receive_messages :new => builder
|
|
232
|
+
allow(ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter).to receive_messages :new => presenter
|
|
233
|
+
allow(ThinkingSphinx::ActiveRecord::SQLSource::Template).to receive_messages :new => template
|
|
234
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
171
235
|
end
|
|
172
236
|
|
|
173
237
|
it "uses the builder's sql_query value" do
|
|
174
|
-
builder.
|
|
238
|
+
allow(builder).to receive_messages :sql_query => 'select * from table'
|
|
175
239
|
|
|
176
240
|
source.render
|
|
177
241
|
|
|
178
|
-
source.sql_query.
|
|
242
|
+
expect(source.sql_query).to eq('select * from table')
|
|
179
243
|
end
|
|
180
244
|
|
|
181
245
|
it "uses the builder's sql_query_range value" do
|
|
182
|
-
builder.
|
|
246
|
+
allow(builder).to receive_messages :sql_query_range => 'select 0, 10 from table'
|
|
183
247
|
|
|
184
248
|
source.render
|
|
185
249
|
|
|
186
|
-
source.sql_query_range.
|
|
250
|
+
expect(source.sql_query_range).to eq('select 0, 10 from table')
|
|
187
251
|
end
|
|
188
252
|
|
|
189
253
|
it "appends the builder's sql_query_pre value" do
|
|
190
|
-
builder.
|
|
191
|
-
|
|
192
|
-
source.render
|
|
193
|
-
|
|
194
|
-
source.sql_query_pre.should == ['Change Setting']
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "appends the builder's sql_query_post_index value" do
|
|
198
|
-
builder.stub! :sql_query_post_index => ['RESET DELTAS']
|
|
254
|
+
allow(builder).to receive_messages :sql_query_pre => ['Change Setting']
|
|
199
255
|
|
|
200
256
|
source.render
|
|
201
257
|
|
|
202
|
-
source.
|
|
258
|
+
expect(source.sql_query_pre).to eq(['Change Setting'])
|
|
203
259
|
end
|
|
204
260
|
|
|
205
261
|
it "adds fields with attributes to sql_field_string" do
|
|
@@ -208,7 +264,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
208
264
|
|
|
209
265
|
source.render
|
|
210
266
|
|
|
211
|
-
source.sql_field_string.
|
|
267
|
+
expect(source.sql_field_string).to include('title')
|
|
212
268
|
end
|
|
213
269
|
|
|
214
270
|
it "adds any joined or file fields" do
|
|
@@ -217,7 +273,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
217
273
|
|
|
218
274
|
source.render
|
|
219
275
|
|
|
220
|
-
source.sql_file_field.
|
|
276
|
+
expect(source.sql_file_field).to include('title')
|
|
221
277
|
end
|
|
222
278
|
|
|
223
279
|
it "adds wordcounted fields to sql_field_str2wordcount" do
|
|
@@ -226,11 +282,11 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
226
282
|
|
|
227
283
|
source.render
|
|
228
284
|
|
|
229
|
-
source.sql_field_str2wordcount.
|
|
285
|
+
expect(source.sql_field_str2wordcount).to include('title')
|
|
230
286
|
end
|
|
231
287
|
|
|
232
288
|
it "adds any joined fields" do
|
|
233
|
-
ThinkingSphinx::ActiveRecord::PropertyQuery.
|
|
289
|
+
allow(ThinkingSphinx::ActiveRecord::PropertyQuery).to receive_messages(
|
|
234
290
|
:new => double(:to_s => 'query for title')
|
|
235
291
|
)
|
|
236
292
|
source.fields << double('field', :name => 'title',
|
|
@@ -239,99 +295,99 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
239
295
|
|
|
240
296
|
source.render
|
|
241
297
|
|
|
242
|
-
source.sql_joined_field.
|
|
298
|
+
expect(source.sql_joined_field).to include('query for title')
|
|
243
299
|
end
|
|
244
300
|
|
|
245
301
|
it "adds integer attributes to sql_attr_uint" do
|
|
246
302
|
source.attributes << double('attribute')
|
|
247
|
-
presenter.
|
|
303
|
+
allow(presenter).to receive_messages :declaration => 'count', :collection_type => :uint
|
|
248
304
|
|
|
249
305
|
source.render
|
|
250
306
|
|
|
251
|
-
source.sql_attr_uint.
|
|
307
|
+
expect(source.sql_attr_uint).to include('count')
|
|
252
308
|
end
|
|
253
309
|
|
|
254
310
|
it "adds boolean attributes to sql_attr_bool" do
|
|
255
311
|
source.attributes << double('attribute')
|
|
256
|
-
presenter.
|
|
312
|
+
allow(presenter).to receive_messages :declaration => 'published', :collection_type => :bool
|
|
257
313
|
|
|
258
314
|
source.render
|
|
259
315
|
|
|
260
|
-
source.sql_attr_bool.
|
|
316
|
+
expect(source.sql_attr_bool).to include('published')
|
|
261
317
|
end
|
|
262
318
|
|
|
263
319
|
it "adds string attributes to sql_attr_string" do
|
|
264
320
|
source.attributes << double('attribute')
|
|
265
|
-
presenter.
|
|
321
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :string
|
|
266
322
|
|
|
267
323
|
source.render
|
|
268
324
|
|
|
269
|
-
source.sql_attr_string.
|
|
325
|
+
expect(source.sql_attr_string).to include('name')
|
|
270
326
|
end
|
|
271
327
|
|
|
272
|
-
it "adds timestamp attributes to
|
|
328
|
+
it "adds timestamp attributes to sql_attr_uint" do
|
|
273
329
|
source.attributes << double('attribute')
|
|
274
|
-
presenter.
|
|
275
|
-
:collection_type => :
|
|
330
|
+
allow(presenter).to receive_messages :declaration => 'created_at',
|
|
331
|
+
:collection_type => :uint
|
|
276
332
|
|
|
277
333
|
source.render
|
|
278
334
|
|
|
279
|
-
source.
|
|
335
|
+
expect(source.sql_attr_uint).to include('created_at')
|
|
280
336
|
end
|
|
281
337
|
|
|
282
338
|
it "adds float attributes to sql_attr_float" do
|
|
283
339
|
source.attributes << double('attribute')
|
|
284
|
-
presenter.
|
|
340
|
+
allow(presenter).to receive_messages :declaration => 'rating', :collection_type => :float
|
|
285
341
|
|
|
286
342
|
source.render
|
|
287
343
|
|
|
288
|
-
source.sql_attr_float.
|
|
344
|
+
expect(source.sql_attr_float).to include('rating')
|
|
289
345
|
end
|
|
290
346
|
|
|
291
347
|
it "adds bigint attributes to sql_attr_bigint" do
|
|
292
348
|
source.attributes << double('attribute')
|
|
293
|
-
presenter.
|
|
349
|
+
allow(presenter).to receive_messages :declaration => 'super_id', :collection_type => :bigint
|
|
294
350
|
|
|
295
351
|
source.render
|
|
296
352
|
|
|
297
|
-
source.sql_attr_bigint.
|
|
353
|
+
expect(source.sql_attr_bigint).to include('super_id')
|
|
298
354
|
end
|
|
299
355
|
|
|
300
356
|
it "adds ordinal strings to sql_attr_str2ordinal" do
|
|
301
357
|
source.attributes << double('attribute')
|
|
302
|
-
presenter.
|
|
358
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2ordinal
|
|
303
359
|
|
|
304
360
|
source.render
|
|
305
361
|
|
|
306
|
-
source.sql_attr_str2ordinal.
|
|
362
|
+
expect(source.sql_attr_str2ordinal).to include('name')
|
|
307
363
|
end
|
|
308
364
|
|
|
309
365
|
it "adds multi-value attributes to sql_attr_multi" do
|
|
310
366
|
source.attributes << double('attribute')
|
|
311
|
-
presenter.
|
|
367
|
+
allow(presenter).to receive_messages :declaration => 'uint tag_ids from field',
|
|
312
368
|
:collection_type => :multi
|
|
313
369
|
|
|
314
370
|
source.render
|
|
315
371
|
|
|
316
|
-
source.sql_attr_multi.
|
|
372
|
+
expect(source.sql_attr_multi).to include('uint tag_ids from field')
|
|
317
373
|
end
|
|
318
374
|
|
|
319
375
|
it "adds word count attributes to sql_attr_str2wordcount" do
|
|
320
376
|
source.attributes << double('attribute')
|
|
321
|
-
presenter.
|
|
377
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2wordcount
|
|
322
378
|
|
|
323
379
|
source.render
|
|
324
380
|
|
|
325
|
-
source.sql_attr_str2wordcount.
|
|
381
|
+
expect(source.sql_attr_str2wordcount).to include('name')
|
|
326
382
|
end
|
|
327
383
|
|
|
328
384
|
it "adds json attributes to sql_attr_json" do
|
|
329
385
|
source.attributes << double('attribute')
|
|
330
|
-
presenter.
|
|
386
|
+
allow(presenter).to receive_messages :declaration => 'json', :collection_type => :json
|
|
331
387
|
|
|
332
388
|
source.render
|
|
333
389
|
|
|
334
|
-
source.sql_attr_json.
|
|
390
|
+
expect(source.sql_attr_json).to include('json')
|
|
335
391
|
end
|
|
336
392
|
|
|
337
393
|
it "adds relevant settings from thinking_sphinx.yml" do
|
|
@@ -340,7 +396,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
340
396
|
|
|
341
397
|
source.render
|
|
342
398
|
|
|
343
|
-
source.mysql_ssl_cert.
|
|
399
|
+
expect(source.mysql_ssl_cert).to eq('foo.cert')
|
|
344
400
|
end
|
|
345
401
|
end
|
|
346
402
|
|
|
@@ -348,84 +404,104 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
|
348
404
|
it "sets the sql_host setting from the model's database settings" do
|
|
349
405
|
source.set_database_settings :host => '12.34.56.78'
|
|
350
406
|
|
|
351
|
-
source.sql_host.
|
|
407
|
+
expect(source.sql_host).to eq('12.34.56.78')
|
|
352
408
|
end
|
|
353
409
|
|
|
354
410
|
it "defaults sql_host to localhost if the model has no host" do
|
|
355
411
|
source.set_database_settings :host => nil
|
|
356
412
|
|
|
357
|
-
source.sql_host.
|
|
413
|
+
expect(source.sql_host).to eq('localhost')
|
|
358
414
|
end
|
|
359
415
|
|
|
360
416
|
it "sets the sql_user setting from the model's database settings" do
|
|
361
417
|
source.set_database_settings :username => 'pat'
|
|
362
418
|
|
|
363
|
-
source.sql_user.
|
|
419
|
+
expect(source.sql_user).to eq('pat')
|
|
364
420
|
end
|
|
365
421
|
|
|
366
422
|
it "uses the user setting if username is not set in the model" do
|
|
367
423
|
source.set_database_settings :username => nil, :user => 'pat'
|
|
368
424
|
|
|
369
|
-
source.sql_user.
|
|
425
|
+
expect(source.sql_user).to eq('pat')
|
|
370
426
|
end
|
|
371
427
|
|
|
372
428
|
it "sets the sql_pass setting from the model's database settings" do
|
|
373
429
|
source.set_database_settings :password => 'swordfish'
|
|
374
430
|
|
|
375
|
-
source.sql_pass.
|
|
431
|
+
expect(source.sql_pass).to eq('swordfish')
|
|
376
432
|
end
|
|
377
433
|
|
|
378
434
|
it "escapes hashes in the password for sql_pass" do
|
|
379
435
|
source.set_database_settings :password => 'sword#fish'
|
|
380
436
|
|
|
381
|
-
source.sql_pass.
|
|
437
|
+
expect(source.sql_pass).to eq('sword\#fish')
|
|
382
438
|
end
|
|
383
439
|
|
|
384
440
|
it "sets the sql_db setting from the model's database settings" do
|
|
385
441
|
source.set_database_settings :database => 'rails_app'
|
|
386
442
|
|
|
387
|
-
source.sql_db.
|
|
443
|
+
expect(source.sql_db).to eq('rails_app')
|
|
388
444
|
end
|
|
389
445
|
|
|
390
446
|
it "sets the sql_port setting from the model's database settings" do
|
|
391
447
|
source.set_database_settings :port => 5432
|
|
392
448
|
|
|
393
|
-
source.sql_port.
|
|
449
|
+
expect(source.sql_port).to eq(5432)
|
|
394
450
|
end
|
|
395
451
|
|
|
396
452
|
it "sets the sql_sock setting from the model's database settings" do
|
|
397
453
|
source.set_database_settings :socket => '/unix/socket'
|
|
398
454
|
|
|
399
|
-
source.sql_sock.
|
|
455
|
+
expect(source.sql_sock).to eq('/unix/socket')
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
it "sets the mysql_ssl_cert from the model's database settings" do
|
|
459
|
+
source.set_database_settings :sslcert => '/path/to/cert.pem'
|
|
460
|
+
|
|
461
|
+
expect(source.mysql_ssl_cert).to eq '/path/to/cert.pem'
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
it "sets the mysql_ssl_key from the model's database settings" do
|
|
465
|
+
source.set_database_settings :sslkey => '/path/to/key.pem'
|
|
466
|
+
|
|
467
|
+
expect(source.mysql_ssl_key).to eq '/path/to/key.pem'
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
it "sets the mysql_ssl_ca from the model's database settings" do
|
|
471
|
+
source.set_database_settings :sslca => '/path/to/ca.pem'
|
|
472
|
+
|
|
473
|
+
expect(source.mysql_ssl_ca).to eq '/path/to/ca.pem'
|
|
400
474
|
end
|
|
401
475
|
end
|
|
402
476
|
|
|
403
477
|
describe '#type' do
|
|
404
478
|
it "is mysql when using the MySQL Adapter" do
|
|
405
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
|
406
|
-
|
|
407
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
|
408
|
-
|
|
479
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
|
480
|
+
to receive_messages(:=== => true)
|
|
481
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
|
482
|
+
to receive_messages(:=== => false)
|
|
409
483
|
|
|
410
|
-
source.type.
|
|
484
|
+
expect(source.type).to eq('mysql')
|
|
411
485
|
end
|
|
412
486
|
|
|
413
487
|
it "is pgsql when using the PostgreSQL Adapter" do
|
|
414
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
|
415
|
-
|
|
416
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
|
417
|
-
|
|
488
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
|
489
|
+
to receive_messages(:=== => false)
|
|
490
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
|
491
|
+
to receive_messages(:=== => true)
|
|
418
492
|
|
|
419
|
-
source.type.
|
|
493
|
+
expect(source.type).to eq('pgsql')
|
|
420
494
|
end
|
|
421
495
|
|
|
422
496
|
it "raises an exception for any other adapter" do
|
|
423
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
|
424
|
-
|
|
425
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
|
426
|
-
|
|
497
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
|
498
|
+
to receive_messages(:=== => false)
|
|
499
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
|
500
|
+
to receive_messages(:=== => false)
|
|
427
501
|
|
|
428
|
-
|
|
502
|
+
expect { source.type }.to raise_error(
|
|
503
|
+
ThinkingSphinx::UnknownDatabaseAdapter
|
|
504
|
+
)
|
|
429
505
|
end
|
|
430
506
|
end
|
|
431
507
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe ThinkingSphinx::AttributeTypes do
|
|
6
|
+
let(:configuration) {
|
|
7
|
+
double('configuration', :configuration_file => 'sphinx.conf')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
before :each do
|
|
11
|
+
allow(ThinkingSphinx::Configuration).to receive(:instance).
|
|
12
|
+
and_return(configuration)
|
|
13
|
+
|
|
14
|
+
allow(File).to receive(:exist?).with('sphinx.conf').and_return(true)
|
|
15
|
+
allow(File).to receive(:read).with('sphinx.conf').and_return(<<-CONF)
|
|
16
|
+
index plain_index
|
|
17
|
+
{
|
|
18
|
+
source = plain_source
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
source plain_source
|
|
22
|
+
{
|
|
23
|
+
type = mysql
|
|
24
|
+
sql_attr_uint = customer_id
|
|
25
|
+
sql_attr_float = price
|
|
26
|
+
sql_attr_multi = uint comment_ids from field
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
index rt_index
|
|
30
|
+
{
|
|
31
|
+
type = rt
|
|
32
|
+
rt_attr_uint = user_id
|
|
33
|
+
rt_attr_multi = comment_ids
|
|
34
|
+
}
|
|
35
|
+
CONF
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'returns an empty hash if no configuration file exists' do
|
|
39
|
+
allow(File).to receive(:exist?).with('sphinx.conf').and_return(false)
|
|
40
|
+
|
|
41
|
+
expect(ThinkingSphinx::AttributeTypes.new.call).to eq({})
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns all known attributes' do
|
|
45
|
+
expect(ThinkingSphinx::AttributeTypes.new.call).to eq({
|
|
46
|
+
'customer_id' => [:uint],
|
|
47
|
+
'price' => [:float],
|
|
48
|
+
'comment_ids' => [:uint],
|
|
49
|
+
'user_id' => [:uint]
|
|
50
|
+
})
|
|
51
|
+
end
|
|
52
|
+
end
|