thinking-sphinx 3.2.0 → 3.3.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 (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +13 -0
  4. data/Gemfile +2 -1
  5. data/HISTORY +19 -0
  6. data/README.textile +3 -2
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +2 -1
  9. data/gemfiles/rails_4_1.gemfile +2 -1
  10. data/gemfiles/rails_4_2.gemfile +2 -1
  11. data/gemfiles/rails_5_0.gemfile +12 -0
  12. data/lib/thinking_sphinx.rb +2 -0
  13. data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
  15. data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/configuration.rb +3 -2
  19. data/lib/thinking_sphinx/connection.rb +23 -10
  20. data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
  21. data/lib/thinking_sphinx/errors.rb +25 -0
  22. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
  23. data/lib/thinking_sphinx/railtie.rb +1 -1
  24. data/lib/thinking_sphinx/rake_interface.rb +71 -23
  25. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
  26. data/lib/thinking_sphinx/real_time/populator.rb +3 -3
  27. data/lib/thinking_sphinx/tasks.rb +7 -8
  28. data/lib/thinking_sphinx/wildcard.rb +1 -1
  29. data/spec/acceptance/association_scoping_spec.rb +5 -5
  30. data/spec/acceptance/attribute_access_spec.rb +4 -4
  31. data/spec/acceptance/attribute_updates_spec.rb +3 -3
  32. data/spec/acceptance/batch_searching_spec.rb +4 -4
  33. data/spec/acceptance/big_integers_spec.rb +6 -6
  34. data/spec/acceptance/connection_spec.rb +23 -0
  35. data/spec/acceptance/excerpts_spec.rb +8 -8
  36. data/spec/acceptance/facets_spec.rb +13 -13
  37. data/spec/acceptance/geosearching_spec.rb +8 -8
  38. data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
  39. data/spec/acceptance/index_options_spec.rb +16 -16
  40. data/spec/acceptance/indexing_spec.rb +3 -3
  41. data/spec/acceptance/paginating_search_results_spec.rb +3 -3
  42. data/spec/acceptance/real_time_updates_spec.rb +4 -4
  43. data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
  44. data/spec/acceptance/search_counts_spec.rb +2 -2
  45. data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
  46. data/spec/acceptance/searching_across_models_spec.rb +6 -6
  47. data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
  48. data/spec/acceptance/searching_on_fields_spec.rb +9 -9
  49. data/spec/acceptance/searching_with_filters_spec.rb +16 -16
  50. data/spec/acceptance/searching_with_sti_spec.rb +9 -9
  51. data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
  52. data/spec/acceptance/sorting_search_results_spec.rb +6 -6
  53. data/spec/acceptance/specifying_sql_spec.rb +62 -62
  54. data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
  55. data/spec/acceptance/sql_deltas_spec.rb +7 -7
  56. data/spec/acceptance/support/database_cleaner.rb +1 -1
  57. data/spec/acceptance/support/sphinx_controller.rb +4 -1
  58. data/spec/acceptance/support/sphinx_helpers.rb +4 -0
  59. data/spec/acceptance/suspended_deltas_spec.rb +9 -9
  60. data/spec/internal/app/indices/article_index.rb +2 -2
  61. data/spec/internal/app/indices/book_index.rb +2 -1
  62. data/spec/internal/app/indices/product_index.rb +0 -2
  63. data/spec/internal/app/models/categorisation.rb +8 -1
  64. data/spec/spec_helper.rb +2 -0
  65. data/spec/support/json_column.rb +5 -1
  66. data/spec/support/multi_schema.rb +3 -1
  67. data/spec/support/sphinx_yaml_helpers.rb +1 -1
  68. data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
  69. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
  70. data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
  71. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
  72. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
  73. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
  74. data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
  75. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
  76. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
  77. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
  78. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
  79. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
  80. data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
  81. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
  82. data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
  83. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
  84. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
  85. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
  86. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
  87. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
  88. data/spec/thinking_sphinx/configuration_spec.rb +81 -81
  89. data/spec/thinking_sphinx/connection_spec.rb +13 -13
  90. data/spec/thinking_sphinx/deletion_spec.rb +11 -11
  91. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
  92. data/spec/thinking_sphinx/deltas_spec.rb +12 -12
  93. data/spec/thinking_sphinx/errors_spec.rb +30 -30
  94. data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
  95. data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
  96. data/spec/thinking_sphinx/index_set_spec.rb +7 -7
  97. data/spec/thinking_sphinx/index_spec.rb +24 -24
  98. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
  99. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
  100. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
  101. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
  102. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
  103. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
  104. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
  105. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
  106. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
  107. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
  108. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
  109. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
  110. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
  111. data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
  112. data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
  113. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
  114. data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
  115. data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
  116. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
  117. data/spec/thinking_sphinx/scopes_spec.rb +5 -5
  118. data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
  119. data/spec/thinking_sphinx/search/query_spec.rb +10 -10
  120. data/spec/thinking_sphinx/search_spec.rb +28 -28
  121. data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
  122. data/spec/thinking_sphinx_spec.rb +6 -6
  123. data/thinking-sphinx.gemspec +4 -4
  124. metadata +12 -9
@@ -1,6 +1,8 @@
1
1
  class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
2
2
  ThinkingSphinx::Middlewares::Middleware
3
3
 
4
+ NO_MODEL = Struct.new(:primary_key).new(:id).freeze
5
+
4
6
  def call(contexts)
5
7
  contexts.each do |context|
6
8
  Inner.new(context).call
@@ -42,6 +44,16 @@ class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
42
44
  }.uniq
43
45
  end
44
46
 
47
+ def primary_key
48
+ @primary_key ||= primary_key_for NO_MODEL
49
+ end
50
+
51
+ def primary_key_for(model)
52
+ model = NO_MODEL unless model.respond_to?(:primary_key)
53
+
54
+ context.configuration.settings['primary_key'] || model.primary_key || :id
55
+ end
56
+
45
57
  def reset_memos
46
58
  @model_names = nil
47
59
  @results_for_models = nil
@@ -49,7 +61,7 @@ class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
49
61
 
50
62
  def result_for(row)
51
63
  results_for_models[row['sphinx_internal_class']].detect { |record|
52
- record.id == row['sphinx_internal_id']
64
+ record.public_send(primary_key) == row['sphinx_internal_id']
53
65
  }
54
66
  end
55
67
 
@@ -57,7 +69,7 @@ class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
57
69
  @results_for_models ||= model_names.inject({}) do |hash, name|
58
70
  model = name.constantize
59
71
  hash[name] = model_relation_with_sql_options(model.unscoped).where(
60
- (context.configuration.settings[:primary_key] || model.primary_key || :id) => ids_for_model(name)
72
+ primary_key_for(model) => ids_for_model(name)
61
73
  )
62
74
 
63
75
  hash
@@ -1,6 +1,6 @@
1
1
  class ThinkingSphinx::Railtie < Rails::Railtie
2
2
  initializer 'thinking_sphinx.initialisation' do
3
- if defined?(ActiveRecord::Base)
3
+ ActiveSupport.on_load(:active_record) do
4
4
  ActiveRecord::Base.send :include, ThinkingSphinx::ActiveRecord::Base
5
5
  end
6
6
  end
@@ -1,4 +1,9 @@
1
1
  class ThinkingSphinx::RakeInterface
2
+ def initialize(options = {})
3
+ @options = options
4
+ @options[:verbose] = false if @options[:silent]
5
+ end
6
+
2
7
  def clear_all
3
8
  [
4
9
  configuration.indices_location,
@@ -9,6 +14,7 @@ class ThinkingSphinx::RakeInterface
9
14
  end
10
15
 
11
16
  def clear_real_time
17
+ configuration.preload_indices
12
18
  indices = configuration.indices.select { |index| index.type == 'rt' }
13
19
  indices.each do |index|
14
20
  index.render
@@ -20,7 +26,7 @@ class ThinkingSphinx::RakeInterface
20
26
  end
21
27
 
22
28
  def configure
23
- puts "Generating configuration to #{configuration.configuration_file}"
29
+ log "Generating configuration to #{configuration.configuration_file}"
24
30
  configuration.render_to_file
25
31
  end
26
32
 
@@ -36,6 +42,8 @@ class ThinkingSphinx::RakeInterface
36
42
  FileUtils.mkdir_p configuration.indices_location
37
43
  ThinkingSphinx.before_index_hooks.each { |hook| hook.call }
38
44
  controller.index :verbose => verbose
45
+ rescue Riddle::CommandFailedError => error
46
+ handle_command_failure 'indexing', error.command_result
39
47
  end
40
48
 
41
49
  def prepare
@@ -45,30 +53,18 @@ class ThinkingSphinx::RakeInterface
45
53
  FileUtils.mkdir_p configuration.indices_location
46
54
  end
47
55
 
48
- def start(options={})
49
- raise RuntimeError, 'searchd is already running' if controller.running?
56
+ def start
57
+ if running?
58
+ raise ThinkingSphinx::SphinxAlreadyRunning, 'searchd is already running'
59
+ end
50
60
 
51
61
  FileUtils.mkdir_p configuration.indices_location
52
62
 
53
- if options[:nodetach]
54
- unless pid = fork
55
- controller.start(options)
56
- end
57
- Signal.trap('TERM') { Process.kill(:TERM, pid); }
58
- Signal.trap('INT') { Process.kill(:TERM, pid); }
59
- Process.wait(pid)
60
- else
61
- controller.start(options)
62
- if controller.running?
63
- puts "Started searchd successfully (pid: #{controller.pid})."
64
- else
65
- puts "Failed to start searchd. Check the log files for more information."
66
- end
67
- end
63
+ options[:nodetach] ? start_attached : start_detached
68
64
  end
69
65
 
70
66
  def status
71
- if controller.running?
67
+ if running?
72
68
  puts "The Sphinx daemon searchd is currently running."
73
69
  else
74
70
  puts "The Sphinx daemon searchd is not currently running."
@@ -76,23 +72,75 @@ class ThinkingSphinx::RakeInterface
76
72
  end
77
73
 
78
74
  def stop
79
- unless controller.running?
80
- puts 'searchd is not currently running.' and return
75
+ unless running?
76
+ log 'searchd is not currently running.' and return
81
77
  end
82
78
 
83
79
  pid = controller.pid
84
- until controller.stop do
80
+ until !running? do
81
+ controller.stop options
85
82
  sleep(0.5)
86
83
  end
87
84
 
88
- puts "Stopped searchd daemon (pid: #{pid})."
85
+ log "Stopped searchd daemon (pid: #{pid})."
86
+ rescue Riddle::CommandFailedError => error
87
+ handle_command_failure 'stop', error.command_result
89
88
  end
90
89
 
91
90
  private
92
91
 
92
+ attr_reader :options
93
+
93
94
  delegate :controller, :to => :configuration
95
+ delegate :running?, :to => :controller
96
+
97
+ def command_output(output)
98
+ return "See above\n" if output.nil?
99
+
100
+ "\n\t" + output.gsub("\n", "\n\t")
101
+ end
94
102
 
95
103
  def configuration
96
104
  ThinkingSphinx::Configuration.instance
97
105
  end
106
+
107
+ def handle_command_failure(type, result)
108
+ puts <<-TXT
109
+
110
+ The Sphinx #{type} command failed:
111
+ Command: #{result.command}
112
+ Status: #{result.status}
113
+ Output: #{command_output result.output}
114
+ There may be more information about the failure in #{configuration.searchd.log}.
115
+ TXT
116
+ exit result.status
117
+ end
118
+
119
+ def log(message)
120
+ return if options[:silent]
121
+
122
+ puts message
123
+ end
124
+
125
+ def start_attached
126
+ unless pid = fork
127
+ controller.start :verbose => options[:verbose]
128
+ end
129
+
130
+ Signal.trap('TERM') { Process.kill(:TERM, pid); }
131
+ Signal.trap('INT') { Process.kill(:TERM, pid); }
132
+ Process.wait(pid)
133
+ end
134
+
135
+ def start_detached
136
+ result = controller.start :verbose => options[:verbose]
137
+
138
+ if running?
139
+ log "Started searchd successfully (pid: #{controller.pid})."
140
+ else
141
+ handle_command_failure 'start', result
142
+ end
143
+ rescue Riddle::CommandFailedError => error
144
+ handle_command_failure 'start', error.command_result
145
+ end
98
146
  end
@@ -3,14 +3,12 @@ class ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks
3
3
  @reference, @path, @block = reference, path, block
4
4
  end
5
5
 
6
- def after_save(instance)
7
- return unless real_time_indices? && callbacks_enabled?
6
+ def after_commit(instance)
7
+ persist_changes instance
8
+ end
8
9
 
9
- real_time_indices.each do |index|
10
- objects_for(instance).each do |object|
11
- ThinkingSphinx::RealTime::Transcriber.new(index).copy object
12
- end
13
- end
10
+ def after_save(instance)
11
+ persist_changes instance
14
12
  end
15
13
 
16
14
  private
@@ -40,6 +38,16 @@ class ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks
40
38
  Array results
41
39
  end
42
40
 
41
+ def persist_changes(instance)
42
+ return unless real_time_indices? && callbacks_enabled?
43
+
44
+ real_time_indices.each do |index|
45
+ objects_for(instance).each do |object|
46
+ ThinkingSphinx::RealTime::Transcriber.new(index).copy object
47
+ end
48
+ end
49
+ end
50
+
43
51
  def real_time_indices?
44
52
  real_time_indices.any?
45
53
  end
@@ -12,7 +12,7 @@ class ThinkingSphinx::RealTime::Populator
12
12
 
13
13
  remove_files
14
14
 
15
- scope.find_in_batches do |instances|
15
+ scope.find_in_batches(:batch_size => batch_size) do |instances|
16
16
  transcriber.copy *instances
17
17
  instrument 'populated', :instances => instances
18
18
  end
@@ -25,8 +25,8 @@ class ThinkingSphinx::RealTime::Populator
25
25
 
26
26
  attr_reader :index
27
27
 
28
- delegate :controller, :to => :configuration
29
- delegate :scope, :to => :index
28
+ delegate :controller, :batch_size, :to => :configuration
29
+ delegate :scope, :to => :index
30
30
 
31
31
  def configuration
32
32
  ThinkingSphinx::Configuration.instance
@@ -6,10 +6,7 @@ namespace :ts do
6
6
 
7
7
  desc 'Generate the Sphinx configuration file and process all indices'
8
8
  task :index => :environment do
9
- interface.index(
10
- ENV['INDEX_ONLY'] != 'true',
11
- !Rake.application.options.silent
12
- )
9
+ interface.index(ENV['INDEX_ONLY'] != 'true')
13
10
  end
14
11
 
15
12
  desc 'Clear out Sphinx files'
@@ -39,9 +36,7 @@ namespace :ts do
39
36
 
40
37
  desc 'Start the Sphinx daemon'
41
38
  task :start => :environment do
42
- options = {}
43
- options[:nodetach] = true if ENV['NODETACH'] == 'true'
44
- interface.start(options)
39
+ interface.start
45
40
  end
46
41
 
47
42
  desc 'Stop the Sphinx daemon'
@@ -55,6 +50,10 @@ namespace :ts do
55
50
  end
56
51
 
57
52
  def interface
58
- @interface ||= ThinkingSphinx::RakeInterface.new
53
+ @interface ||= ThinkingSphinx::RakeInterface.new(
54
+ :verbose => Rake::FileUtilsExt.verbose_flag,
55
+ :silent => Rake.application.options.silent,
56
+ :nodetach => (ENV['NODETACH'] == 'true')
57
+ )
59
58
  end
60
59
  end
@@ -14,7 +14,7 @@ class ThinkingSphinx::Wildcard
14
14
  query.gsub(extended_pattern) do
15
15
  pre, proper, post = $`, $&, $'
16
16
  # E.g. "@foo", "/2", "~3", but not as part of a token pattern
17
- is_operator = pre == '@' ||
17
+ is_operator = pre.match(%r{@$}) ||
18
18
  pre.match(%r{([^\\]+|\A)[~/]\Z}) ||
19
19
  pre.match(%r{(\W|^)@\([^\)]*$})
20
20
  # E.g. "foo bar", with quotes
@@ -9,7 +9,7 @@ describe 'Scoping association search calls by foreign keys', :live => true do
9
9
  dublin = Article.create :title => 'Guide to Dublin', :user => paul
10
10
  index
11
11
 
12
- pat.articles.search('Guide').to_a.should == [melbourne]
12
+ expect(pat.articles.search('Guide').to_a).to eq([melbourne])
13
13
  end
14
14
 
15
15
  it "limits id-only results to those matching the foreign key" do
@@ -19,7 +19,7 @@ describe 'Scoping association search calls by foreign keys', :live => true do
19
19
  dublin = Article.create :title => 'Guide to Dublin', :user => paul
20
20
  index
21
21
 
22
- pat.articles.search_for_ids('Guide').to_a.should == [melbourne.id]
22
+ expect(pat.articles.search_for_ids('Guide').to_a).to eq([melbourne.id])
23
23
  end
24
24
  end
25
25
 
@@ -31,7 +31,7 @@ describe 'Scoping association search calls by foreign keys', :live => true do
31
31
  audi = Manufacturer.create :name => 'Audi'
32
32
  r_eight = Car.create :name => 'R8 Spyder', :manufacturer => audi
33
33
 
34
- porsche.cars.search('Spyder').to_a.should == [spyder]
34
+ expect(porsche.cars.search('Spyder').to_a).to eq([spyder])
35
35
  end
36
36
 
37
37
  it "limits id-only results to those matching the foreign key" do
@@ -41,7 +41,7 @@ describe 'Scoping association search calls by foreign keys', :live => true do
41
41
  audi = Manufacturer.create :name => 'Audi'
42
42
  r_eight = Car.create :name => 'R8 Spyder', :manufacturer => audi
43
43
 
44
- porsche.cars.search_for_ids('Spyder').to_a.should == [spyder.id]
44
+ expect(porsche.cars.search_for_ids('Spyder').to_a).to eq([spyder.id])
45
45
  end
46
46
  end
47
47
 
@@ -57,7 +57,7 @@ describe 'Scoping association search calls by foreign keys', :live => true do
57
57
  pancakes.categories << flat
58
58
  waffles.categories << food
59
59
 
60
- flat.products.search('Low').to_a.should == [pancakes]
60
+ expect(flat.products.search('Low').to_a).to eq([pancakes])
61
61
  end
62
62
  end
63
63
  end
@@ -8,7 +8,7 @@ describe 'Accessing attributes directly via search results', :live => true do
8
8
  search = Book.search('gods')
9
9
  search.context[:panes] << ThinkingSphinx::Panes::AttributesPane
10
10
 
11
- search.first.sphinx_attributes['year'].should == 2001
11
+ expect(search.first.sphinx_attributes['year']).to eq(2001)
12
12
  end
13
13
 
14
14
  it "provides direct access to the search weight/relevance scores" do
@@ -19,7 +19,7 @@ describe 'Accessing attributes directly via search results', :live => true do
19
19
  :select => "*, #{ThinkingSphinx::SphinxQL.weight[:select]}"
20
20
  search.context[:panes] << ThinkingSphinx::Panes::WeightPane
21
21
 
22
- search.first.weight.should == 2500
22
+ expect(search.first.weight).to eq(2500)
23
23
  end
24
24
 
25
25
  it "can enumerate with the weight" do
@@ -34,8 +34,8 @@ describe 'Accessing attributes directly via search results', :live => true do
34
34
  search.each_with_weight do |result, weight|
35
35
  expectation = expectations.shift
36
36
 
37
- result.should == expectation.first
38
- weight.should == expectation.last
37
+ expect(result).to eq(expectation.first)
38
+ expect(weight).to eq(expectation.last)
39
39
  end
40
40
  end
41
41
  end
@@ -5,12 +5,12 @@ describe 'Update attributes automatically where possible', :live => true do
5
5
  article = Article.create :title => 'Pancakes', :published => false
6
6
  index
7
7
 
8
- Article.search('pancakes', :with => {:published => true}).should be_empty
8
+ expect(Article.search('pancakes', :with => {:published => true})).to be_empty
9
9
 
10
10
  article.published = true
11
11
  article.save
12
12
 
13
- Article.search('pancakes', :with => {:published => true}).to_a
14
- .should == [article]
13
+ expect(Article.search('pancakes', :with => {:published => true}).to_a)
14
+ .to eq([article])
15
15
  end
16
16
  end
@@ -12,10 +12,10 @@ describe 'Executing multiple searches in one Sphinx call', :live => true do
12
12
 
13
13
  batch.populate
14
14
 
15
- batch.searches.first.should include(pancakes)
16
- batch.searches.first.should_not include(waffles)
15
+ expect(batch.searches.first).to include(pancakes)
16
+ expect(batch.searches.first).not_to include(waffles)
17
17
 
18
- batch.searches.last.should include(waffles)
19
- batch.searches.last.should_not include(pancakes)
18
+ expect(batch.searches.last).to include(waffles)
19
+ expect(batch.searches.last).not_to include(pancakes)
20
20
  end
21
21
  end
@@ -21,17 +21,17 @@ describe '64 bit integer support' do
21
21
  [small_index, large_index, real_time_index]
22
22
  ).reconcile
23
23
 
24
- large_index.sources.first.attributes.detect { |attribute|
24
+ expect(large_index.sources.first.attributes.detect { |attribute|
25
25
  attribute.name == 'sphinx_internal_id'
26
- }.type.should == :bigint
26
+ }.type).to eq(:bigint)
27
27
 
28
- small_index.sources.first.attributes.detect { |attribute|
28
+ expect(small_index.sources.first.attributes.detect { |attribute|
29
29
  attribute.name == 'sphinx_internal_id'
30
- }.type.should == :bigint
30
+ }.type).to eq(:bigint)
31
31
 
32
- real_time_index.attributes.detect { |attribute|
32
+ expect(real_time_index.attributes.detect { |attribute|
33
33
  attribute.name == 'sphinx_internal_id'
34
- }.type.should == :bigint
34
+ }.type).to eq(:bigint)
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,23 @@
1
+ require 'acceptance/spec_helper'
2
+
3
+ RSpec.describe 'Connections', :live => true do
4
+ let(:maximum) { (2 ** 23) - 1 }
5
+ let(:query) { "SELECT * FROM book_core WHERE MATCH('')" }
6
+ let(:difference) { maximum - query.length }
7
+
8
+ it 'allows normal length queries through' do
9
+ expect {
10
+ ThinkingSphinx::Connection.take do |connection|
11
+ connection.execute query.insert(-3, 'a' * difference)
12
+ end
13
+ }.to_not raise_error#(ThinkingSphinx::QueryLengthError)
14
+ end
15
+
16
+ it 'does not allow overly long queries' do
17
+ expect {
18
+ ThinkingSphinx::Connection.take do |connection|
19
+ connection.execute query.insert(-3, 'a' * (difference + 1))
20
+ end
21
+ }.to raise_error(ThinkingSphinx::QueryLengthError)
22
+ end
23
+ end