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.
Files changed (347) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +99 -0
  3. data/.github/actions/test/action.yml +46 -0
  4. data/.github/workflows/ci.yml +75 -0
  5. data/.gitignore +7 -2
  6. data/.travis.yml +31 -16
  7. data/Appraisals +68 -12
  8. data/CHANGELOG.markdown +782 -0
  9. data/Gemfile +13 -4
  10. data/Procfile.support +2 -0
  11. data/README.textile +41 -27
  12. data/Rakefile +2 -0
  13. data/bin/console +15 -0
  14. data/bin/loadsphinx +99 -0
  15. data/bin/testmatrix +48 -0
  16. data/lib/thinking/sphinx.rb +2 -0
  17. data/lib/thinking-sphinx.rb +2 -0
  18. data/lib/thinking_sphinx/active_record/association.rb +2 -0
  19. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +3 -1
  20. data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +2 -0
  21. data/lib/thinking_sphinx/active_record/association_proxy.rb +3 -2
  22. data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +3 -1
  23. data/lib/thinking_sphinx/active_record/attribute/type.rb +20 -4
  24. data/lib/thinking_sphinx/active_record/attribute/values.rb +2 -0
  25. data/lib/thinking_sphinx/active_record/attribute.rb +2 -0
  26. data/lib/thinking_sphinx/active_record/base.rb +43 -11
  27. data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
  28. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +15 -9
  29. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +20 -5
  30. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +18 -4
  31. data/lib/thinking_sphinx/active_record/column.rb +2 -0
  32. data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +7 -1
  33. data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +2 -0
  34. data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +9 -1
  35. data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +2 -0
  36. data/lib/thinking_sphinx/active_record/database_adapters.rb +3 -1
  37. data/lib/thinking_sphinx/active_record/depolymorph/association_reflection.rb +32 -0
  38. data/lib/thinking_sphinx/active_record/depolymorph/base_reflection.rb +32 -0
  39. data/lib/thinking_sphinx/active_record/depolymorph/conditions_reflection.rb +40 -0
  40. data/lib/thinking_sphinx/active_record/depolymorph/overridden_reflection.rb +50 -0
  41. data/lib/thinking_sphinx/active_record/depolymorph/scoped_reflection.rb +26 -0
  42. data/lib/thinking_sphinx/active_record/field.rb +2 -0
  43. data/lib/thinking_sphinx/active_record/filter_reflection.rb +13 -71
  44. data/lib/thinking_sphinx/active_record/index.rb +7 -5
  45. data/lib/thinking_sphinx/active_record/interpreter.rb +6 -4
  46. data/lib/thinking_sphinx/active_record/join_association.rb +5 -1
  47. data/lib/thinking_sphinx/active_record/log_subscriber.rb +22 -3
  48. data/lib/thinking_sphinx/active_record/polymorpher.rb +2 -0
  49. data/lib/thinking_sphinx/active_record/property.rb +2 -0
  50. data/lib/thinking_sphinx/active_record/property_query.rb +4 -1
  51. data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +2 -0
  52. data/lib/thinking_sphinx/active_record/simple_many_query.rb +2 -0
  53. data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
  54. data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +2 -0
  55. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +13 -0
  56. data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +2 -0
  57. data/lib/thinking_sphinx/active_record/sql_builder.rb +5 -18
  58. data/lib/thinking_sphinx/active_record/sql_source/template.rb +5 -3
  59. data/lib/thinking_sphinx/active_record/sql_source.rb +35 -9
  60. data/lib/thinking_sphinx/active_record.rb +14 -1
  61. data/lib/thinking_sphinx/attribute_types.rb +72 -0
  62. data/lib/thinking_sphinx/batched_search.rb +2 -0
  63. data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
  64. data/lib/thinking_sphinx/callbacks.rb +29 -0
  65. data/lib/thinking_sphinx/capistrano/v2.rb +2 -0
  66. data/lib/thinking_sphinx/capistrano/v3.rb +2 -0
  67. data/lib/thinking_sphinx/capistrano.rb +2 -0
  68. data/lib/thinking_sphinx/commander.rb +27 -0
  69. data/lib/thinking_sphinx/commands/base.rb +53 -0
  70. data/lib/thinking_sphinx/commands/clear_real_time.rb +22 -0
  71. data/lib/thinking_sphinx/commands/clear_sql.rb +18 -0
  72. data/lib/thinking_sphinx/commands/configure.rb +15 -0
  73. data/lib/thinking_sphinx/commands/index_real_time.rb +15 -0
  74. data/lib/thinking_sphinx/commands/index_sql.rb +25 -0
  75. data/lib/thinking_sphinx/commands/merge.rb +27 -0
  76. data/lib/thinking_sphinx/commands/merge_and_update.rb +57 -0
  77. data/lib/thinking_sphinx/commands/prepare.rb +15 -0
  78. data/lib/thinking_sphinx/commands/rotate.rb +13 -0
  79. data/lib/thinking_sphinx/commands/running.rb +15 -0
  80. data/lib/thinking_sphinx/commands/start_attached.rb +22 -0
  81. data/lib/thinking_sphinx/commands/start_detached.rb +21 -0
  82. data/lib/thinking_sphinx/commands/stop.rb +24 -0
  83. data/lib/thinking_sphinx/commands.rb +20 -0
  84. data/lib/thinking_sphinx/configuration/consistent_ids.rb +2 -0
  85. data/lib/thinking_sphinx/configuration/defaults.rb +2 -0
  86. data/lib/thinking_sphinx/configuration/distributed_indices.rb +3 -1
  87. data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
  88. data/lib/thinking_sphinx/configuration/minimum_fields.rb +17 -12
  89. data/lib/thinking_sphinx/configuration.rb +90 -74
  90. data/lib/thinking_sphinx/connection/client.rb +74 -0
  91. data/lib/thinking_sphinx/connection/jruby.rb +58 -0
  92. data/lib/thinking_sphinx/connection/mri.rb +26 -0
  93. data/lib/thinking_sphinx/connection.rb +13 -114
  94. data/lib/thinking_sphinx/core/field.rb +2 -0
  95. data/lib/thinking_sphinx/core/index.rb +22 -2
  96. data/lib/thinking_sphinx/core/interpreter.rb +2 -0
  97. data/lib/thinking_sphinx/core/property.rb +2 -0
  98. data/lib/thinking_sphinx/core/settings.rb +2 -0
  99. data/lib/thinking_sphinx/core.rb +2 -0
  100. data/lib/thinking_sphinx/deletion.rb +33 -13
  101. data/lib/thinking_sphinx/deltas/default_delta.rb +3 -1
  102. data/lib/thinking_sphinx/deltas/delete_job.rb +16 -4
  103. data/lib/thinking_sphinx/deltas/index_job.rb +14 -2
  104. data/lib/thinking_sphinx/deltas.rb +2 -0
  105. data/lib/thinking_sphinx/distributed/index.rb +25 -3
  106. data/lib/thinking_sphinx/distributed.rb +2 -0
  107. data/lib/thinking_sphinx/errors.rb +47 -3
  108. data/lib/thinking_sphinx/excerpter.rb +2 -0
  109. data/lib/thinking_sphinx/facet.rb +4 -3
  110. data/lib/thinking_sphinx/facet_search.rb +4 -2
  111. data/lib/thinking_sphinx/float_formatter.rb +2 -0
  112. data/lib/thinking_sphinx/frameworks/plain.rb +2 -0
  113. data/lib/thinking_sphinx/frameworks/rails.rb +2 -0
  114. data/lib/thinking_sphinx/frameworks.rb +2 -0
  115. data/lib/thinking_sphinx/guard/file.rb +3 -1
  116. data/lib/thinking_sphinx/guard/files.rb +2 -0
  117. data/lib/thinking_sphinx/guard/none.rb +7 -0
  118. data/lib/thinking_sphinx/guard.rb +3 -0
  119. data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
  120. data/lib/thinking_sphinx/index.rb +2 -0
  121. data/lib/thinking_sphinx/index_set.rb +27 -4
  122. data/lib/thinking_sphinx/indexing_strategies/all_at_once.rb +9 -0
  123. data/lib/thinking_sphinx/indexing_strategies/one_at_a_time.rb +16 -0
  124. data/lib/thinking_sphinx/interfaces/base.rb +13 -0
  125. data/lib/thinking_sphinx/interfaces/daemon.rb +27 -0
  126. data/lib/thinking_sphinx/interfaces/real_time.rb +46 -0
  127. data/lib/thinking_sphinx/interfaces/sql.rb +53 -0
  128. data/lib/thinking_sphinx/interfaces.rb +10 -0
  129. data/lib/thinking_sphinx/logger.rb +2 -0
  130. data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +6 -4
  131. data/lib/thinking_sphinx/masks/pagination_mask.rb +2 -0
  132. data/lib/thinking_sphinx/masks/scopes_mask.rb +8 -0
  133. data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +3 -1
  134. data/lib/thinking_sphinx/masks.rb +2 -0
  135. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +32 -9
  136. data/lib/thinking_sphinx/middlewares/geographer.rb +2 -0
  137. data/lib/thinking_sphinx/middlewares/glazier.rb +14 -1
  138. data/lib/thinking_sphinx/middlewares/ids_only.rb +2 -0
  139. data/lib/thinking_sphinx/middlewares/inquirer.rb +3 -1
  140. data/lib/thinking_sphinx/middlewares/middleware.rb +2 -0
  141. data/lib/thinking_sphinx/middlewares/sphinxql.rb +18 -16
  142. data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +3 -1
  143. data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +4 -2
  144. data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
  145. data/lib/thinking_sphinx/middlewares.rb +7 -3
  146. data/lib/thinking_sphinx/panes/attributes_pane.rb +2 -0
  147. data/lib/thinking_sphinx/panes/distance_pane.rb +2 -0
  148. data/lib/thinking_sphinx/panes/excerpts_pane.rb +2 -0
  149. data/lib/thinking_sphinx/panes/weight_pane.rb +3 -1
  150. data/lib/thinking_sphinx/panes.rb +2 -0
  151. data/lib/thinking_sphinx/processor.rb +71 -0
  152. data/lib/thinking_sphinx/query.rb +2 -0
  153. data/lib/thinking_sphinx/railtie.rb +29 -2
  154. data/lib/thinking_sphinx/rake_interface.rb +14 -69
  155. data/lib/thinking_sphinx/real_time/attribute.rb +9 -1
  156. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +17 -7
  157. data/lib/thinking_sphinx/real_time/field.rb +2 -0
  158. data/lib/thinking_sphinx/real_time/index/template.rb +19 -1
  159. data/lib/thinking_sphinx/real_time/index.rb +11 -5
  160. data/lib/thinking_sphinx/real_time/interpreter.rb +10 -6
  161. data/lib/thinking_sphinx/real_time/populator.rb +12 -14
  162. data/lib/thinking_sphinx/real_time/processor.rb +36 -0
  163. data/lib/thinking_sphinx/real_time/property.rb +3 -5
  164. data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
  165. data/lib/thinking_sphinx/real_time/transcriber.rb +63 -15
  166. data/lib/thinking_sphinx/real_time/translator.rb +39 -0
  167. data/lib/thinking_sphinx/real_time.rb +22 -1
  168. data/lib/thinking_sphinx/scopes.rb +6 -0
  169. data/lib/thinking_sphinx/search/batch_inquirer.rb +2 -0
  170. data/lib/thinking_sphinx/search/context.rb +11 -0
  171. data/lib/thinking_sphinx/search/glaze.rb +2 -0
  172. data/lib/thinking_sphinx/search/merger.rb +2 -0
  173. data/lib/thinking_sphinx/search/query.rb +9 -1
  174. data/lib/thinking_sphinx/search/stale_ids_exception.rb +7 -3
  175. data/lib/thinking_sphinx/search.rb +30 -2
  176. data/lib/thinking_sphinx/settings.rb +128 -0
  177. data/lib/thinking_sphinx/sinatra.rb +3 -1
  178. data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +19 -5
  179. data/lib/thinking_sphinx/tasks.rb +55 -28
  180. data/lib/thinking_sphinx/test.rb +3 -1
  181. data/lib/thinking_sphinx/utf8.rb +2 -0
  182. data/lib/thinking_sphinx/wildcard.rb +3 -1
  183. data/lib/thinking_sphinx/with_output.rb +13 -0
  184. data/lib/thinking_sphinx.rb +35 -4
  185. data/spec/acceptance/association_scoping_spec.rb +7 -5
  186. data/spec/acceptance/attribute_access_spec.rb +29 -12
  187. data/spec/acceptance/attribute_updates_spec.rb +5 -3
  188. data/spec/acceptance/batch_searching_spec.rb +6 -4
  189. data/spec/acceptance/big_integers_spec.rb +9 -7
  190. data/spec/acceptance/excerpts_spec.rb +11 -10
  191. data/spec/acceptance/facets_spec.rb +29 -16
  192. data/spec/acceptance/geosearching_spec.rb +22 -10
  193. data/spec/acceptance/grouping_by_attributes_spec.rb +30 -28
  194. data/spec/acceptance/index_options_spec.rb +18 -16
  195. data/spec/acceptance/indexing_spec.rb +5 -3
  196. data/spec/acceptance/merging_spec.rb +90 -0
  197. data/spec/acceptance/paginating_search_results_spec.rb +21 -3
  198. data/spec/acceptance/real_time_updates_spec.rb +103 -5
  199. data/spec/acceptance/remove_deleted_records_spec.rb +64 -8
  200. data/spec/acceptance/search_counts_spec.rb +4 -2
  201. data/spec/acceptance/search_for_just_ids_spec.rb +4 -2
  202. data/spec/acceptance/searching_across_models_spec.rb +15 -6
  203. data/spec/acceptance/searching_across_schemas_spec.rb +12 -10
  204. data/spec/acceptance/searching_on_fields_spec.rb +11 -9
  205. data/spec/acceptance/searching_with_filters_spec.rb +35 -20
  206. data/spec/acceptance/searching_with_sti_spec.rb +11 -9
  207. data/spec/acceptance/searching_within_a_model_spec.rb +44 -17
  208. data/spec/acceptance/sorting_search_results_spec.rb +21 -19
  209. data/spec/acceptance/spec_helper.rb +2 -13
  210. data/spec/acceptance/specifying_sql_spec.rb +118 -62
  211. data/spec/acceptance/sphinx_scopes_spec.rb +30 -21
  212. data/spec/acceptance/sql_deltas_spec.rb +35 -9
  213. data/spec/acceptance/support/database_cleaner.rb +3 -1
  214. data/spec/acceptance/support/sphinx_controller.rb +25 -9
  215. data/spec/acceptance/support/sphinx_helpers.rb +17 -2
  216. data/spec/acceptance/suspended_deltas_spec.rb +14 -12
  217. data/spec/fixtures/database.yml +1 -1
  218. data/spec/internal/app/indices/admin_person_index.rb +6 -0
  219. data/spec/internal/app/indices/album_index.rb +9 -0
  220. data/spec/internal/app/indices/animal_index.rb +2 -0
  221. data/spec/internal/app/indices/article_index.rb +10 -3
  222. data/spec/internal/app/indices/bird_index.rb +2 -0
  223. data/spec/internal/app/indices/book_index.rb +4 -1
  224. data/spec/internal/app/indices/car_index.rb +2 -0
  225. data/spec/internal/app/indices/city_index.rb +2 -0
  226. data/spec/internal/app/indices/colour_index.rb +7 -0
  227. data/spec/internal/app/indices/product_index.rb +3 -2
  228. data/spec/internal/app/indices/tee_index.rb +3 -1
  229. data/spec/internal/app/indices/user_index.rb +2 -0
  230. data/spec/internal/app/models/admin/person.rb +6 -0
  231. data/spec/internal/app/models/album.rb +25 -0
  232. data/spec/internal/app/models/animal.rb +3 -0
  233. data/spec/internal/app/models/article.rb +4 -0
  234. data/spec/internal/app/models/bird.rb +3 -0
  235. data/spec/internal/app/models/book.rb +9 -5
  236. data/spec/internal/app/models/car.rb +3 -1
  237. data/spec/internal/app/models/categorisation.rb +10 -1
  238. data/spec/internal/app/models/category.rb +2 -0
  239. data/spec/internal/app/models/city.rb +4 -0
  240. data/spec/internal/app/models/colour.rb +4 -0
  241. data/spec/internal/app/models/event.rb +2 -0
  242. data/spec/internal/app/models/flightless_bird.rb +2 -0
  243. data/spec/internal/app/models/genre.rb +2 -0
  244. data/spec/internal/app/models/hardcover.rb +2 -0
  245. data/spec/internal/app/models/mammal.rb +2 -0
  246. data/spec/internal/app/models/manufacturer.rb +2 -0
  247. data/spec/internal/app/models/product.rb +3 -1
  248. data/spec/internal/app/models/tag.rb +2 -0
  249. data/spec/internal/app/models/tagging.rb +2 -0
  250. data/spec/internal/app/models/tee.rb +7 -0
  251. data/spec/internal/app/models/tweet.rb +2 -0
  252. data/spec/internal/app/models/user.rb +4 -0
  253. data/spec/internal/config/database.yml +12 -1
  254. data/spec/internal/db/schema.rb +13 -1
  255. data/spec/spec_helper.rb +12 -1
  256. data/spec/support/json_column.rb +35 -0
  257. data/spec/support/multi_schema.rb +5 -1
  258. data/spec/support/mysql.rb +25 -0
  259. data/spec/support/sphinx_yaml_helpers.rb +8 -1
  260. data/spec/thinking_sphinx/active_record/association_spec.rb +3 -1
  261. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +43 -38
  262. data/spec/thinking_sphinx/active_record/base_spec.rb +31 -29
  263. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +81 -10
  264. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +56 -29
  265. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +27 -10
  266. data/spec/thinking_sphinx/active_record/column_spec.rb +15 -13
  267. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +39 -0
  268. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +7 -5
  269. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +26 -12
  270. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +15 -13
  271. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +50 -48
  272. data/spec/thinking_sphinx/active_record/field_spec.rb +9 -7
  273. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +113 -80
  274. data/spec/thinking_sphinx/active_record/index_spec.rb +41 -37
  275. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +62 -59
  276. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +16 -14
  277. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +69 -67
  278. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +146 -154
  279. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +185 -109
  280. data/spec/thinking_sphinx/attribute_types_spec.rb +52 -0
  281. data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +46 -0
  282. data/spec/thinking_sphinx/commands/clear_sql_spec.rb +52 -0
  283. data/spec/thinking_sphinx/commands/configure_spec.rb +31 -0
  284. data/spec/thinking_sphinx/commands/index_real_time_spec.rb +33 -0
  285. data/spec/thinking_sphinx/commands/index_sql_spec.rb +86 -0
  286. data/spec/thinking_sphinx/commands/merge_and_update_spec.rb +106 -0
  287. data/spec/thinking_sphinx/commands/merge_spec.rb +48 -0
  288. data/spec/thinking_sphinx/commands/prepare_spec.rb +31 -0
  289. data/spec/thinking_sphinx/commands/running_spec.rb +30 -0
  290. data/spec/thinking_sphinx/commands/start_detached_spec.rb +67 -0
  291. data/spec/thinking_sphinx/commands/stop_spec.rb +63 -0
  292. data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +60 -0
  293. data/spec/thinking_sphinx/configuration_spec.rb +247 -94
  294. data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
  295. data/spec/thinking_sphinx/connection_spec.rb +15 -13
  296. data/spec/thinking_sphinx/deletion_spec.rb +17 -17
  297. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +28 -21
  298. data/spec/thinking_sphinx/deltas_spec.rb +14 -12
  299. data/spec/thinking_sphinx/errors_spec.rb +59 -27
  300. data/spec/thinking_sphinx/excerpter_spec.rb +12 -9
  301. data/spec/thinking_sphinx/facet_search_spec.rb +24 -22
  302. data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
  303. data/spec/thinking_sphinx/index_set_spec.rb +59 -18
  304. data/spec/thinking_sphinx/index_spec.rb +28 -26
  305. data/spec/thinking_sphinx/interfaces/daemon_spec.rb +60 -0
  306. data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
  307. data/spec/thinking_sphinx/interfaces/sql_spec.rb +122 -0
  308. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +22 -20
  309. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +20 -18
  310. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +45 -21
  311. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +11 -9
  312. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +12 -9
  313. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +9 -7
  314. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +60 -58
  315. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +7 -4
  316. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +39 -17
  317. data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
  318. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +3 -1
  319. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +6 -4
  320. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +8 -6
  321. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +4 -2
  322. data/spec/thinking_sphinx/rake_interface_spec.rb +17 -235
  323. data/spec/thinking_sphinx/real_time/attribute_spec.rb +15 -13
  324. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +114 -28
  325. data/spec/thinking_sphinx/real_time/field_spec.rb +16 -14
  326. data/spec/thinking_sphinx/real_time/index_spec.rb +83 -32
  327. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +44 -42
  328. data/spec/thinking_sphinx/real_time/transcribe_instance_spec.rb +35 -0
  329. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +109 -0
  330. data/spec/thinking_sphinx/real_time/translator_spec.rb +17 -0
  331. data/spec/thinking_sphinx/scopes_spec.rb +11 -5
  332. data/spec/thinking_sphinx/search/glaze_spec.rb +17 -15
  333. data/spec/thinking_sphinx/search/query_spec.rb +19 -10
  334. data/spec/thinking_sphinx/search_spec.rb +30 -28
  335. data/spec/thinking_sphinx/wildcard_spec.rb +18 -11
  336. data/spec/thinking_sphinx_spec.rb +10 -7
  337. data/thinking-sphinx.gemspec +17 -10
  338. metadata +157 -49
  339. data/HISTORY +0 -248
  340. data/gemfiles/.gitignore +0 -1
  341. data/gemfiles/rails_3_2.gemfile +0 -11
  342. data/gemfiles/rails_4_0.gemfile +0 -11
  343. data/gemfiles/rails_4_1.gemfile +0 -11
  344. data/gemfiles/rails_4_2.gemfile +0 -11
  345. data/lib/thinking_sphinx/controller.rb +0 -10
  346. data/lib/thinking_sphinx/middlewares/utf8.rb +0 -27
  347. 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
- stub!(:=== => true)
18
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
19
- stub!(:adapter_for => adapter)
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
- should_receive(:adapter_for).with(model).and_return(adapter)
26
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
27
+ to receive(:adapter_for).with(model).and_return(adapter)
26
28
 
27
- source.adapter.should == 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).should include('sphinx_internal_id')
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).should include('sphinx_internal_class')
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).should include('sphinx_deleted')
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].should be_true
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.should_receive(:try).with(:new, adapter, {}).
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.should == 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.should_receive(:try).with(:new, adapter, {:opt_key => :opt_value})
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.should be_a_delta
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?.should be_true
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
- should include('sphinx_internal_class_name')
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.should == "'User'"
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.stub :quoted_table_name => '"users"', :quote => '"type"'
113
- adapter.stub(:convert_blank) { |clause, default|
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.stub :column_names => ['type'], :sti_name => 'User'
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
- should == "coalesce(nullif(\"users\".\"type\", ''), 'User')"
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.should == 'user_3'
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.should == 'people_2'
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, :offset => 12
184
+ source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
185
+ :offset => 12, :primary_key => model.primary_key || :id
141
186
 
142
- source.offset.should == 12
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?].should be_false
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?].should be_true
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.stub! :new => builder
168
- ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter.stub :new => presenter
169
- ThinkingSphinx::ActiveRecord::SQLSource::Template.stub :new => template
170
- ThinkingSphinx::Configuration.stub :instance => config
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.stub! :sql_query => 'select * from table'
238
+ allow(builder).to receive_messages :sql_query => 'select * from table'
175
239
 
176
240
  source.render
177
241
 
178
- source.sql_query.should == 'select * from table'
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.stub! :sql_query_range => 'select 0, 10 from table'
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.should == 'select 0, 10 from table'
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.stub! :sql_query_pre => ['Change Setting']
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.sql_query_post_index.should include('RESET DELTAS')
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.should include('title')
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.should include('title')
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.should include('title')
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.stub(
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.should include('query for title')
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.stub :declaration => 'count', :collection_type => :uint
303
+ allow(presenter).to receive_messages :declaration => 'count', :collection_type => :uint
248
304
 
249
305
  source.render
250
306
 
251
- source.sql_attr_uint.should include('count')
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.stub :declaration => 'published', :collection_type => :bool
312
+ allow(presenter).to receive_messages :declaration => 'published', :collection_type => :bool
257
313
 
258
314
  source.render
259
315
 
260
- source.sql_attr_bool.should include('published')
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.stub :declaration => 'name', :collection_type => :string
321
+ allow(presenter).to receive_messages :declaration => 'name', :collection_type => :string
266
322
 
267
323
  source.render
268
324
 
269
- source.sql_attr_string.should include('name')
325
+ expect(source.sql_attr_string).to include('name')
270
326
  end
271
327
 
272
- it "adds timestamp attributes to sql_attr_timestamp" do
328
+ it "adds timestamp attributes to sql_attr_uint" do
273
329
  source.attributes << double('attribute')
274
- presenter.stub :declaration => 'created_at',
275
- :collection_type => :timestamp
330
+ allow(presenter).to receive_messages :declaration => 'created_at',
331
+ :collection_type => :uint
276
332
 
277
333
  source.render
278
334
 
279
- source.sql_attr_timestamp.should include('created_at')
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.stub :declaration => 'rating', :collection_type => :float
340
+ allow(presenter).to receive_messages :declaration => 'rating', :collection_type => :float
285
341
 
286
342
  source.render
287
343
 
288
- source.sql_attr_float.should include('rating')
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.stub :declaration => 'super_id', :collection_type => :bigint
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.should include('super_id')
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.stub :declaration => 'name', :collection_type => :str2ordinal
358
+ allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2ordinal
303
359
 
304
360
  source.render
305
361
 
306
- source.sql_attr_str2ordinal.should include('name')
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.stub :declaration => 'uint tag_ids from field',
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.should include('uint tag_ids from field')
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.stub :declaration => 'name', :collection_type => :str2wordcount
377
+ allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2wordcount
322
378
 
323
379
  source.render
324
380
 
325
- source.sql_attr_str2wordcount.should include('name')
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.stub :declaration => 'json', :collection_type => :json
386
+ allow(presenter).to receive_messages :declaration => 'json', :collection_type => :json
331
387
 
332
388
  source.render
333
389
 
334
- source.sql_attr_json.should include('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.should == 'foo.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.should == '12.34.56.78'
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.should == 'localhost'
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.should == 'pat'
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.should == 'pat'
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.should == 'swordfish'
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.should == 'sword\#fish'
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.should == 'rails_app'
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.should == 5432
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.should == '/unix/socket'
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
- stub!(:=== => true)
407
- ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
408
- stub!(:=== => false)
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.should == 'mysql'
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
- stub!(:=== => false)
416
- ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
417
- stub!(:=== => true)
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.should == 'pgsql'
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
- stub!(:=== => false)
425
- ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
426
- stub!(:=== => false)
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
- lambda { source.type }.should raise_error
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