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::Callbacks::DeltaCallbacks do
|
|
@@ -11,7 +13,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
before :each do
|
|
14
|
-
ThinkingSphinx::Configuration.
|
|
16
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
[:after_commit, :before_save].each do |callback|
|
|
@@ -19,20 +21,20 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
|
19
21
|
let(:callbacks) { double('callbacks', callback => nil) }
|
|
20
22
|
|
|
21
23
|
before :each do
|
|
22
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
|
23
|
-
|
|
24
|
+
allow(ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks).
|
|
25
|
+
to receive_messages :new => callbacks
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
it "builds an object from the instance" do
|
|
27
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
|
28
|
-
|
|
29
|
+
expect(ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks).
|
|
30
|
+
to receive(:new).with(instance).and_return(callbacks)
|
|
29
31
|
|
|
30
32
|
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
|
31
33
|
send(callback, instance)
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
it "invokes #{callback} on the object" do
|
|
35
|
-
callbacks.
|
|
37
|
+
expect(callbacks).to receive(callback)
|
|
36
38
|
|
|
37
39
|
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
|
38
40
|
send(callback, instance)
|
|
@@ -42,22 +44,23 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
|
42
44
|
|
|
43
45
|
describe '#after_commit' do
|
|
44
46
|
let(:index) {
|
|
45
|
-
double('index', :delta? => false, :delta_processor => processor
|
|
47
|
+
double('index', :delta? => false, :delta_processor => processor,
|
|
48
|
+
:type => 'plain')
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
before :each do
|
|
49
|
-
config.
|
|
52
|
+
allow(config).to receive_messages :index_set_class => double(:new => [index])
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
context 'without delta indices' do
|
|
53
56
|
it "does not fire a delta index when no delta indices" do
|
|
54
|
-
processor.
|
|
57
|
+
expect(processor).not_to receive(:index)
|
|
55
58
|
|
|
56
59
|
callbacks.after_commit
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
it "does not delete the instance from any index" do
|
|
60
|
-
processor.
|
|
63
|
+
expect(processor).not_to receive(:delete)
|
|
61
64
|
|
|
62
65
|
callbacks.after_commit
|
|
63
66
|
end
|
|
@@ -65,58 +68,58 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
|
65
68
|
|
|
66
69
|
context 'with delta indices' do
|
|
67
70
|
let(:core_index) { double('index', :delta? => false, :name => 'foo_core',
|
|
68
|
-
:delta_processor => processor) }
|
|
71
|
+
:delta_processor => processor, :type => 'plain') }
|
|
69
72
|
let(:delta_index) { double('index', :delta? => true, :name => 'foo_delta',
|
|
70
|
-
:delta_processor => processor) }
|
|
73
|
+
:delta_processor => processor, :type => 'plain') }
|
|
71
74
|
|
|
72
75
|
before :each do
|
|
73
|
-
ThinkingSphinx::Deltas.
|
|
76
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => false
|
|
74
77
|
|
|
75
|
-
config.
|
|
78
|
+
allow(config).to receive_messages :index_set_class => double(
|
|
76
79
|
:new => [core_index, delta_index]
|
|
77
80
|
)
|
|
78
81
|
end
|
|
79
82
|
|
|
80
83
|
it "only indexes delta indices" do
|
|
81
|
-
processor.
|
|
84
|
+
expect(processor).to receive(:index).with(delta_index)
|
|
82
85
|
|
|
83
86
|
callbacks.after_commit
|
|
84
87
|
end
|
|
85
88
|
|
|
86
89
|
it "does not process delta indices when deltas are suspended" do
|
|
87
|
-
ThinkingSphinx::Deltas.
|
|
90
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => true
|
|
88
91
|
|
|
89
|
-
processor.
|
|
92
|
+
expect(processor).not_to receive(:index)
|
|
90
93
|
|
|
91
94
|
callbacks.after_commit
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
it "deletes the instance from the core index" do
|
|
95
|
-
processor.
|
|
98
|
+
expect(processor).to receive(:delete).with(core_index, instance)
|
|
96
99
|
|
|
97
100
|
callbacks.after_commit
|
|
98
101
|
end
|
|
99
102
|
|
|
100
103
|
it "does not index if model's delta flag is not true" do
|
|
101
|
-
processor.
|
|
104
|
+
allow(processor).to receive_messages :toggled? => false
|
|
102
105
|
|
|
103
|
-
processor.
|
|
106
|
+
expect(processor).not_to receive(:index)
|
|
104
107
|
|
|
105
108
|
callbacks.after_commit
|
|
106
109
|
end
|
|
107
110
|
|
|
108
111
|
it "does not delete if model's delta flag is not true" do
|
|
109
|
-
processor.
|
|
112
|
+
allow(processor).to receive_messages :toggled? => false
|
|
110
113
|
|
|
111
|
-
processor.
|
|
114
|
+
expect(processor).not_to receive(:delete)
|
|
112
115
|
|
|
113
116
|
callbacks.after_commit
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
it "does not delete when deltas are suspended" do
|
|
117
|
-
ThinkingSphinx::Deltas.
|
|
120
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => true
|
|
118
121
|
|
|
119
|
-
processor.
|
|
122
|
+
expect(processor).not_to receive(:delete)
|
|
120
123
|
|
|
121
124
|
callbacks.after_commit
|
|
122
125
|
end
|
|
@@ -125,23 +128,47 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
|
125
128
|
|
|
126
129
|
describe '#before_save' do
|
|
127
130
|
let(:index) {
|
|
128
|
-
double('index', :delta? => true, :delta_processor => processor
|
|
131
|
+
double('index', :delta? => true, :delta_processor => processor,
|
|
132
|
+
:type => 'plain')
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
before :each do
|
|
132
|
-
config.
|
|
136
|
+
allow(config).to receive_messages :index_set_class => double(:new => [index])
|
|
137
|
+
allow(instance).to receive_messages(
|
|
138
|
+
:changed? => true,
|
|
139
|
+
:new_record? => false
|
|
140
|
+
)
|
|
133
141
|
end
|
|
134
142
|
|
|
135
143
|
it "sets delta to true if there are delta indices" do
|
|
136
|
-
processor.
|
|
144
|
+
expect(processor).to receive(:toggle).with(instance)
|
|
137
145
|
|
|
138
146
|
callbacks.before_save
|
|
139
147
|
end
|
|
140
148
|
|
|
141
149
|
it "does not try to set delta to true if there are no delta indices" do
|
|
142
|
-
index.
|
|
150
|
+
allow(index).to receive_messages :delta? => false
|
|
151
|
+
|
|
152
|
+
expect(processor).not_to receive(:toggle)
|
|
153
|
+
|
|
154
|
+
callbacks.before_save
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "does not try to set delta to true if the instance is unchanged" do
|
|
158
|
+
allow(instance).to receive_messages :changed? => false
|
|
159
|
+
|
|
160
|
+
expect(processor).not_to receive(:toggle)
|
|
161
|
+
|
|
162
|
+
callbacks.before_save
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "does set delta to true if the instance is unchanged but new" do
|
|
166
|
+
allow(instance).to receive_messages(
|
|
167
|
+
:changed? => false,
|
|
168
|
+
:new_record? => true
|
|
169
|
+
)
|
|
143
170
|
|
|
144
|
-
processor.
|
|
171
|
+
expect(processor).to receive(:toggle)
|
|
145
172
|
|
|
146
173
|
callbacks.before_save
|
|
147
174
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module ActiveRecord
|
|
3
5
|
module Callbacks; end
|
|
@@ -17,12 +19,13 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
|
|
|
17
19
|
let(:klass) { double(:name => 'Article') }
|
|
18
20
|
let(:configuration) { double('configuration',
|
|
19
21
|
:settings => {'attribute_updates' => true},
|
|
20
|
-
:indices_for_references => [index]) }
|
|
22
|
+
:indices_for_references => [index], :index_set_class => set_class) }
|
|
21
23
|
let(:connection) { double('connection', :execute => '') }
|
|
22
24
|
let(:index) { double 'index', :name => 'article_core',
|
|
23
25
|
:sources => [source], :document_id_for_key => 3, :distributed? => false,
|
|
24
|
-
:type => 'plain'}
|
|
26
|
+
:type => 'plain', :primary_key => :id}
|
|
25
27
|
let(:source) { double('source', :attributes => []) }
|
|
28
|
+
let(:set_class) { double(:reference_name => :article) }
|
|
26
29
|
|
|
27
30
|
before :each do
|
|
28
31
|
stub_const 'ThinkingSphinx::Configuration',
|
|
@@ -30,7 +33,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
|
|
|
30
33
|
stub_const 'ThinkingSphinx::Connection', double
|
|
31
34
|
stub_const 'Riddle::Query', double(:update => 'SphinxQL')
|
|
32
35
|
|
|
33
|
-
ThinkingSphinx::Connection.
|
|
36
|
+
allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
|
|
34
37
|
|
|
35
38
|
source.attributes.replace([
|
|
36
39
|
double(:name => 'foo', :updateable? => true,
|
|
@@ -40,35 +43,49 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
|
|
|
40
43
|
double(:name => 'baz', :updateable? => false)
|
|
41
44
|
])
|
|
42
45
|
|
|
43
|
-
instance.
|
|
46
|
+
allow(instance).to receive_messages(
|
|
47
|
+
:changed => ['bar_column', 'baz'],
|
|
48
|
+
:bar_column => 7,
|
|
49
|
+
:saved_changes => {'bar_column' => [1, 2], 'baz' => [3, 4]}
|
|
50
|
+
)
|
|
44
51
|
end
|
|
45
52
|
|
|
46
53
|
it "does not send any updates to Sphinx if updates are disabled" do
|
|
47
54
|
configuration.settings['attribute_updates'] = false
|
|
48
55
|
|
|
49
|
-
connection.
|
|
56
|
+
expect(connection).not_to receive(:execute)
|
|
50
57
|
|
|
51
58
|
callbacks.after_update
|
|
52
59
|
end
|
|
53
60
|
|
|
54
61
|
it "builds an update query with only updateable attributes that have changed" do
|
|
55
|
-
Riddle::Query.
|
|
56
|
-
with('article_core', 3, 'bar' => 7).and_return('SphinxQL')
|
|
62
|
+
expect(Riddle::Query).to receive(:update).
|
|
63
|
+
with('article_core', 3, { 'bar' => 7 }).and_return('SphinxQL')
|
|
57
64
|
|
|
58
65
|
callbacks.after_update
|
|
59
66
|
end
|
|
60
67
|
|
|
61
68
|
it "sends the update query through to Sphinx" do
|
|
62
|
-
connection.
|
|
69
|
+
expect(connection).to receive(:execute).with('SphinxQL')
|
|
63
70
|
|
|
64
71
|
callbacks.after_update
|
|
65
72
|
end
|
|
66
73
|
|
|
67
74
|
it "doesn't care if the update fails at Sphinx's end" do
|
|
68
|
-
connection.
|
|
75
|
+
allow(connection).to receive(:execute).
|
|
69
76
|
and_raise(ThinkingSphinx::ConnectionError.new(''))
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
expect { callbacks.after_update }.not_to raise_error
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'does nothing if callbacks are suspended' do
|
|
82
|
+
ThinkingSphinx::Callbacks.suspend!
|
|
83
|
+
|
|
84
|
+
expect(connection).not_to receive(:execute)
|
|
85
|
+
|
|
86
|
+
callbacks.after_update
|
|
87
|
+
|
|
88
|
+
ThinkingSphinx::Callbacks.resume!
|
|
72
89
|
end
|
|
73
90
|
end
|
|
74
91
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::Column do
|
|
4
6
|
describe '#__name' do
|
|
5
7
|
it "returns the top item" do
|
|
6
8
|
column = ThinkingSphinx::ActiveRecord::Column.new(:content)
|
|
7
|
-
column.__name.
|
|
9
|
+
expect(column.__name).to eq(:content)
|
|
8
10
|
end
|
|
9
11
|
end
|
|
10
12
|
|
|
@@ -14,27 +16,27 @@ describe ThinkingSphinx::ActiveRecord::Column do
|
|
|
14
16
|
|
|
15
17
|
it "returns itself when it's a string column" do
|
|
16
18
|
column = ThinkingSphinx::ActiveRecord::Column.new('foo')
|
|
17
|
-
column.__replace(base, replacements).collect(&:__path).
|
|
18
|
-
|
|
19
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
|
20
|
+
to eq([['foo']])
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
it "returns itself when the base of the stack does not match" do
|
|
22
24
|
column = ThinkingSphinx::ActiveRecord::Column.new(:b, :c)
|
|
23
|
-
column.__replace(base, replacements).collect(&:__path).
|
|
24
|
-
|
|
25
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
|
26
|
+
to eq([[:b, :c]])
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
it "returns an array of new columns " do
|
|
28
30
|
column = ThinkingSphinx::ActiveRecord::Column.new(:a, :b, :e)
|
|
29
|
-
column.__replace(base, replacements).collect(&:__path).
|
|
30
|
-
|
|
31
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
|
32
|
+
to eq([[:a, :c, :e], [:a, :d, :e]])
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
describe '#__stack' do
|
|
35
37
|
it "returns all but the top item" do
|
|
36
38
|
column = ThinkingSphinx::ActiveRecord::Column.new(:users, :posts, :id)
|
|
37
|
-
column.__stack.
|
|
39
|
+
expect(column.__stack).to eq([:users, :posts])
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -43,28 +45,28 @@ describe ThinkingSphinx::ActiveRecord::Column do
|
|
|
43
45
|
|
|
44
46
|
it "shifts the current name to the stack" do
|
|
45
47
|
column.email
|
|
46
|
-
column.__stack.
|
|
48
|
+
expect(column.__stack).to eq([:user])
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
it "adds the new method call as the name" do
|
|
50
52
|
column.email
|
|
51
|
-
column.__name.
|
|
53
|
+
expect(column.__name).to eq(:email)
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
it "returns itself" do
|
|
55
|
-
column.email.
|
|
57
|
+
expect(column.email).to eq(column)
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
describe '#string?' do
|
|
60
62
|
it "is true when the name is a string" do
|
|
61
63
|
column = ThinkingSphinx::ActiveRecord::Column.new('content')
|
|
62
|
-
column.
|
|
64
|
+
expect(column).to be_a_string
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
it "is false when the name is a symbol" do
|
|
66
68
|
column = ThinkingSphinx::ActiveRecord::Column.new(:content)
|
|
67
|
-
column.
|
|
69
|
+
expect(column).not_to be_a_string
|
|
68
70
|
end
|
|
69
71
|
end
|
|
70
72
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe ThinkingSphinx::ActiveRecord::ColumnSQLPresenter do
|
|
6
|
+
describe '#with_table' do
|
|
7
|
+
let(:model) { double 'Model' }
|
|
8
|
+
let(:column) { double 'Column', :__name => 'column_name',
|
|
9
|
+
:__stack => [], :string? => false }
|
|
10
|
+
let(:adapter) { double 'Adapter' }
|
|
11
|
+
let(:associations) { double 'Associations' }
|
|
12
|
+
let(:path) { double 'Path',
|
|
13
|
+
:model => double(:column_names => ['column_name']) }
|
|
14
|
+
let(:presenter) { ThinkingSphinx::ActiveRecord::ColumnSQLPresenter.new(
|
|
15
|
+
model, column, adapter, associations
|
|
16
|
+
) }
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
stub_const 'Joiner::Path', double(:new => path)
|
|
20
|
+
allow(adapter).to receive(:quote) { |arg| "`#{arg}`" }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when there's no explicit db name" do
|
|
24
|
+
before { allow(associations).to receive_messages(:alias_for => 'table_name') }
|
|
25
|
+
|
|
26
|
+
it 'returns quoted table and column names' do
|
|
27
|
+
expect(presenter.with_table).to eq('`table_name`.`column_name`')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'when an eplicit db name is provided' do
|
|
32
|
+
before { allow(associations).to receive_messages(:alias_for => 'db_name.table_name') }
|
|
33
|
+
|
|
34
|
+
it 'returns properly quoted table name with column name' do
|
|
35
|
+
expect(presenter.with_table).to eq('`db_name`.`table_name`.`column_name`')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::AbstractAdapter do
|
|
@@ -9,23 +11,23 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::AbstractAdapter do
|
|
|
9
11
|
|
|
10
12
|
describe '#quote' do
|
|
11
13
|
it "uses the model's connection to quote columns" do
|
|
12
|
-
connection.
|
|
14
|
+
expect(connection).to receive(:quote_column_name).with('foo')
|
|
13
15
|
|
|
14
16
|
adapter.quote 'foo'
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
it "returns the quoted value" do
|
|
18
|
-
connection.
|
|
20
|
+
allow(connection).to receive_messages :quote_column_name => '"foo"'
|
|
19
21
|
|
|
20
|
-
adapter.quote('foo').
|
|
22
|
+
expect(adapter.quote('foo')).to eq('"foo"')
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
describe '#quoted_table_name' do
|
|
25
27
|
it "passes the method through to the model" do
|
|
26
|
-
model.
|
|
28
|
+
expect(model).to receive(:quoted_table_name).and_return('"articles"')
|
|
27
29
|
|
|
28
|
-
adapter.quoted_table_name.
|
|
30
|
+
expect(adapter.quoted_table_name).to eq('"articles"')
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter do
|
|
@@ -7,50 +9,62 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter do
|
|
|
7
9
|
let(:model) { double('model') }
|
|
8
10
|
|
|
9
11
|
it "returns 1 for true" do
|
|
10
|
-
adapter.boolean_value(true).
|
|
12
|
+
expect(adapter.boolean_value(true)).to eq(1)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
it "returns 0 for false" do
|
|
14
|
-
adapter.boolean_value(false).
|
|
16
|
+
expect(adapter.boolean_value(false)).to eq(0)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
describe '#cast_to_string' do
|
|
18
20
|
it "casts the clause to characters" do
|
|
19
|
-
adapter.cast_to_string('foo').
|
|
21
|
+
expect(adapter.cast_to_string('foo')).to eq("CAST(foo AS char)")
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
describe '#cast_to_timestamp' do
|
|
24
26
|
it "converts to unix timestamps" do
|
|
25
|
-
adapter.cast_to_timestamp('created_at').
|
|
26
|
-
|
|
27
|
+
expect(adapter.cast_to_timestamp('created_at')).
|
|
28
|
+
to eq('UNIX_TIMESTAMP(created_at)')
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
describe '#concatenate' do
|
|
31
33
|
it "concatenates with the given separator" do
|
|
32
|
-
adapter.concatenate('foo, bar, baz', ',').
|
|
33
|
-
|
|
34
|
+
expect(adapter.concatenate('foo, bar, baz', ',')).
|
|
35
|
+
to eq("CONCAT_WS(',', foo, bar, baz)")
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
describe '#convert_nulls' do
|
|
38
40
|
it "translates arguments to an IFNULL SQL call" do
|
|
39
|
-
adapter.convert_nulls('id', 5).
|
|
41
|
+
expect(adapter.convert_nulls('id', 5)).to eq('IFNULL(id, 5)')
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
describe '#convert_blank' do
|
|
44
46
|
it "translates arguments to a COALESCE NULLIF SQL call" do
|
|
45
|
-
adapter.convert_blank('id', 5).
|
|
47
|
+
expect(adapter.convert_blank('id', 5)).to eq("COALESCE(NULLIF(id, ''), 5)")
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
|
|
50
51
|
describe '#group_concatenate' do
|
|
51
52
|
it "group concatenates the clause with the given separator" do
|
|
52
|
-
adapter.group_concatenate('foo', ',').
|
|
53
|
-
|
|
53
|
+
expect(adapter.group_concatenate('foo', ',')).
|
|
54
|
+
to eq("GROUP_CONCAT(DISTINCT foo SEPARATOR ',')")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#utf8_query_pre' do
|
|
59
|
+
it "defaults to using utf8" do
|
|
60
|
+
expect(adapter.utf8_query_pre).to eq(["SET NAMES utf8"])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "allows custom values" do
|
|
64
|
+
ThinkingSphinx::Configuration.instance.settings['mysql_encoding'] =
|
|
65
|
+
'utf8mb4'
|
|
66
|
+
|
|
67
|
+
expect(adapter.utf8_query_pre).to eq(["SET NAMES utf8mb4"])
|
|
54
68
|
end
|
|
55
69
|
end
|
|
56
70
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter do
|
|
@@ -8,57 +10,57 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter do
|
|
|
8
10
|
|
|
9
11
|
describe '#boolean_value' do
|
|
10
12
|
it "returns 'TRUE' for true" do
|
|
11
|
-
adapter.boolean_value(true).
|
|
13
|
+
expect(adapter.boolean_value(true)).to eq('TRUE')
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
it "returns 'FALSE' for false" do
|
|
15
|
-
adapter.boolean_value(false).
|
|
17
|
+
expect(adapter.boolean_value(false)).to eq('FALSE')
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
describe '#cast_to_string' do
|
|
20
22
|
it "casts the clause to characters" do
|
|
21
|
-
adapter.cast_to_string('foo').
|
|
23
|
+
expect(adapter.cast_to_string('foo')).to eq('foo::varchar')
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
describe '#cast_to_timestamp' do
|
|
26
28
|
it "converts to int unix timestamps" do
|
|
27
|
-
adapter.cast_to_timestamp('created_at').
|
|
28
|
-
|
|
29
|
+
expect(adapter.cast_to_timestamp('created_at')).
|
|
30
|
+
to eq('extract(epoch from created_at)::int')
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
it "converts to bigint unix timestamps" do
|
|
32
34
|
ThinkingSphinx::Configuration.instance.settings['64bit_timestamps'] = true
|
|
33
35
|
|
|
34
|
-
adapter.cast_to_timestamp('created_at').
|
|
35
|
-
|
|
36
|
+
expect(adapter.cast_to_timestamp('created_at')).
|
|
37
|
+
to eq('extract(epoch from created_at)::bigint')
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
describe '#concatenate' do
|
|
40
42
|
it "concatenates with the given separator" do
|
|
41
|
-
adapter.concatenate('foo, bar, baz', ',').
|
|
42
|
-
|
|
43
|
+
expect(adapter.concatenate('foo, bar, baz', ',')).
|
|
44
|
+
to eq("COALESCE(foo, '') || ',' || COALESCE(bar, '') || ',' || COALESCE(baz, '')")
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
describe '#convert_nulls' do
|
|
47
49
|
it "translates arguments to a COALESCE SQL call" do
|
|
48
|
-
adapter.convert_nulls('id', 5).
|
|
50
|
+
expect(adapter.convert_nulls('id', 5)).to eq('COALESCE(id, 5)')
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
describe '#convert_blank' do
|
|
53
55
|
it "translates arguments to a COALESCE NULLIF SQL call" do
|
|
54
|
-
adapter.convert_blank('id', 5).
|
|
56
|
+
expect(adapter.convert_blank('id', 5)).to eq("COALESCE(NULLIF(id, ''), 5)")
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
describe '#group_concatenate' do
|
|
59
61
|
it "group concatenates the clause with the given separator" do
|
|
60
|
-
adapter.group_concatenate('foo', ',').
|
|
61
|
-
|
|
62
|
+
expect(adapter.group_concatenate('foo', ',')).
|
|
63
|
+
to eq("array_to_string(array_agg(DISTINCT foo), ',')")
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|