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