thinking-sphinx 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -8,9 +8,9 @@ describe ThinkingSphinx::Connection do
8
8
  let(:translated_error) { ThinkingSphinx::SphinxError.new }
9
9
 
10
10
  before :each do
11
- ThinkingSphinx::Connection.stub :pool => pool
12
- ThinkingSphinx::SphinxError.stub :new_from_mysql => translated_error
13
- pool.stub(:take).and_yield(connection)
11
+ allow(ThinkingSphinx::Connection).to receive_messages :pool => pool
12
+ allow(ThinkingSphinx::SphinxError).to receive_messages :new_from_mysql => translated_error
13
+ allow(pool).to receive(:take).and_yield(connection)
14
14
 
15
15
  error.statement = 'SELECT * FROM article_core'
16
16
  translated_error.statement = 'SELECT * FROM article_core'
@@ -18,41 +18,41 @@ describe ThinkingSphinx::Connection do
18
18
 
19
19
  it "yields a connection from the pool" do
20
20
  ThinkingSphinx::Connection.take do |c|
21
- c.should == connection
21
+ expect(c).to eq(connection)
22
22
  end
23
23
  end
24
24
 
25
25
  it "retries errors once" do
26
26
  tries = 0
27
27
 
28
- lambda {
28
+ expect {
29
29
  ThinkingSphinx::Connection.take do |c|
30
30
  tries += 1
31
31
  raise error if tries < 2
32
32
  end
33
- }.should_not raise_error
33
+ }.not_to raise_error
34
34
  end
35
35
 
36
36
  it "retries errors twice" do
37
37
  tries = 0
38
38
 
39
- lambda {
39
+ expect {
40
40
  ThinkingSphinx::Connection.take do |c|
41
41
  tries += 1
42
42
  raise error if tries < 3
43
43
  end
44
- }.should_not raise_error
44
+ }.not_to raise_error
45
45
  end
46
46
 
47
47
  it "raises a translated error if it fails three times" do
48
48
  tries = 0
49
49
 
50
- lambda {
50
+ expect {
51
51
  ThinkingSphinx::Connection.take do |c|
52
52
  tries += 1
53
53
  raise error if tries < 4
54
54
  end
55
- }.should raise_error(ThinkingSphinx::SphinxError)
55
+ }.to raise_error(ThinkingSphinx::SphinxError)
56
56
  end
57
57
 
58
58
  [ThinkingSphinx::SyntaxError, ThinkingSphinx::ParseError].each do |klass|
@@ -60,9 +60,9 @@ describe ThinkingSphinx::Connection do
60
60
  let(:translated_error) { klass.new }
61
61
 
62
62
  it "raises the error" do
63
- lambda {
63
+ expect {
64
64
  ThinkingSphinx::Connection.take { |c| raise error }
65
- }.should raise_error(klass)
65
+ }.to raise_error(klass)
66
66
  end
67
67
 
68
68
  it "does not yield the connection more than once" do
@@ -77,7 +77,7 @@ describe ThinkingSphinx::Connection do
77
77
  #
78
78
  end
79
79
 
80
- yields.should == 1
80
+ expect(yields).to eq(1)
81
81
  end
82
82
  end
83
83
  end
@@ -7,13 +7,13 @@ describe ThinkingSphinx::Deletion do
7
7
  :document_id_for_key => 14, :type => 'plain', :distributed? => false) }
8
8
 
9
9
  before :each do
10
- ThinkingSphinx::Connection.stub(:take).and_yield(connection)
11
- Riddle::Query.stub :update => 'UPDATE STATEMENT'
10
+ allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
11
+ allow(Riddle::Query).to receive_messages :update => 'UPDATE STATEMENT'
12
12
  end
13
13
 
14
14
  context 'index is SQL-backed' do
15
15
  it "updates the deleted flag to false" do
16
- connection.should_receive(:execute).with <<-SQL
16
+ expect(connection).to receive(:execute).with <<-SQL
17
17
  UPDATE foo_core
18
18
  SET sphinx_deleted = 1
19
19
  WHERE id IN (14)
@@ -23,34 +23,34 @@ WHERE id IN (14)
23
23
  end
24
24
 
25
25
  it "doesn't care about Sphinx errors" do
26
- connection.stub(:execute).
26
+ allow(connection).to receive(:execute).
27
27
  and_raise(ThinkingSphinx::ConnectionError.new(''))
28
28
 
29
- lambda {
29
+ expect {
30
30
  ThinkingSphinx::Deletion.perform index, 7
31
- }.should_not raise_error
31
+ }.not_to raise_error
32
32
  end
33
33
  end
34
34
 
35
35
  context "index is real-time" do
36
36
  before :each do
37
- index.stub :type => 'rt'
37
+ allow(index).to receive_messages :type => 'rt'
38
38
  end
39
39
 
40
40
  it "deletes the record to false" do
41
- connection.should_receive(:execute).
41
+ expect(connection).to receive(:execute).
42
42
  with('DELETE FROM foo_core WHERE id = 14')
43
43
 
44
44
  ThinkingSphinx::Deletion.perform index, 7
45
45
  end
46
46
 
47
47
  it "doesn't care about Sphinx errors" do
48
- connection.stub(:execute).
48
+ allow(connection).to receive(:execute).
49
49
  and_raise(ThinkingSphinx::ConnectionError.new(''))
50
50
 
51
- lambda {
51
+ expect {
52
52
  ThinkingSphinx::Deletion.perform index, 7
53
- }.should_not raise_error
53
+ }.not_to raise_error
54
54
  end
55
55
  end
56
56
  end
@@ -9,11 +9,11 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
9
9
  describe '#clause' do
10
10
  context 'for a delta source' do
11
11
  before :each do
12
- adapter.stub :boolean_value => 't'
12
+ allow(adapter).to receive_messages :boolean_value => 't'
13
13
  end
14
14
 
15
15
  it "limits results to those flagged as deltas" do
16
- delta.clause(true).should == "articles.delta = t"
16
+ expect(delta.clause(true)).to eq("articles.delta = t")
17
17
  end
18
18
  end
19
19
  end
@@ -25,42 +25,42 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
25
25
  let(:instance) { double('instance', :id => 7) }
26
26
 
27
27
  before :each do
28
- ThinkingSphinx::Connection.stub(:take).and_yield(connection)
29
- Riddle::Query.stub :update => 'UPDATE STATEMENT'
28
+ allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
29
+ allow(Riddle::Query).to receive_messages :update => 'UPDATE STATEMENT'
30
30
  end
31
31
 
32
32
  it "updates the deleted flag to false" do
33
- connection.should_receive(:execute).with('UPDATE STATEMENT')
33
+ expect(connection).to receive(:execute).with('UPDATE STATEMENT')
34
34
 
35
35
  delta.delete index, instance
36
36
  end
37
37
 
38
38
  it "builds the update query for the given index" do
39
- Riddle::Query.should_receive(:update).
39
+ expect(Riddle::Query).to receive(:update).
40
40
  with('foo_core', anything, anything).and_return('')
41
41
 
42
42
  delta.delete index, instance
43
43
  end
44
44
 
45
45
  it "builds the update query for the sphinx document id" do
46
- Riddle::Query.should_receive(:update).
46
+ expect(Riddle::Query).to receive(:update).
47
47
  with(anything, 14, anything).and_return('')
48
48
 
49
49
  delta.delete index, instance
50
50
  end
51
51
 
52
52
  it "builds the update query for setting sphinx_deleted to true" do
53
- Riddle::Query.should_receive(:update).
53
+ expect(Riddle::Query).to receive(:update).
54
54
  with(anything, anything, :sphinx_deleted => true).and_return('')
55
55
 
56
56
  delta.delete index, instance
57
57
  end
58
58
 
59
59
  it "doesn't care about Sphinx errors" do
60
- connection.stub(:execute).
60
+ allow(connection).to receive(:execute).
61
61
  and_raise(ThinkingSphinx::ConnectionError.new(''))
62
62
 
63
- lambda { delta.delete index, instance }.should_not raise_error
63
+ expect { delta.delete index, instance }.not_to raise_error
64
64
  end
65
65
  end
66
66
 
@@ -70,11 +70,11 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
70
70
  let(:controller) { double('controller') }
71
71
 
72
72
  before :each do
73
- ThinkingSphinx::Configuration.stub :instance => config
73
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
74
74
  end
75
75
 
76
76
  it "indexes the given index" do
77
- controller.should_receive(:index).with('foo_delta', :verbose => true)
77
+ expect(controller).to receive(:index).with('foo_delta', :verbose => false)
78
78
 
79
79
  delta.index double('index', :name => 'foo_delta')
80
80
  end
@@ -82,9 +82,9 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
82
82
 
83
83
  describe '#reset_query' do
84
84
  it "updates the table to set delta flags to false" do
85
- adapter.stub(:boolean_value) { |value| value ? 't' : 'f' }
86
- delta.reset_query.
87
- should == 'UPDATE articles SET delta = f WHERE delta = t'
85
+ allow(adapter).to receive(:boolean_value) { |value| value ? 't' : 'f' }
86
+ expect(delta.reset_query).
87
+ to eq('UPDATE articles SET delta = f WHERE delta = t')
88
88
  end
89
89
  end
90
90
 
@@ -92,7 +92,7 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
92
92
  let(:instance) { double('instance') }
93
93
 
94
94
  it "sets instance's delta flag to true" do
95
- instance.should_receive(:delta=).with(true)
95
+ expect(instance).to receive(:delta=).with(true)
96
96
 
97
97
  delta.toggle(instance)
98
98
  end
@@ -102,15 +102,15 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
102
102
  let(:instance) { double('instance') }
103
103
 
104
104
  it "returns the delta flag value when true" do
105
- instance.stub! :delta? => true
105
+ allow(instance).to receive_messages :delta? => true
106
106
 
107
- delta.toggled?(instance).should be_true
107
+ expect(delta.toggled?(instance)).to be_truthy
108
108
  end
109
109
 
110
110
  it "returns the delta flag value when false" do
111
- instance.stub! :delta? => false
111
+ allow(instance).to receive_messages :delta? => false
112
112
 
113
- delta.toggled?(instance).should be_false
113
+ expect(delta.toggled?(instance)).to be_falsey
114
114
  end
115
115
  end
116
116
  end
@@ -3,19 +3,19 @@ require 'spec_helper'
3
3
  describe ThinkingSphinx::Deltas do
4
4
  describe '.processor_for' do
5
5
  it "returns the default processor class when given true" do
6
- ThinkingSphinx::Deltas.processor_for(true).
7
- should == ThinkingSphinx::Deltas::DefaultDelta
6
+ expect(ThinkingSphinx::Deltas.processor_for(true)).
7
+ to eq(ThinkingSphinx::Deltas::DefaultDelta)
8
8
  end
9
9
 
10
10
  it "returns the class when given one" do
11
11
  klass = Class.new
12
- ThinkingSphinx::Deltas.processor_for(klass).should == klass
12
+ expect(ThinkingSphinx::Deltas.processor_for(klass)).to eq(klass)
13
13
  end
14
14
 
15
15
  it "instantiates a class from the name as a string" do
16
- ThinkingSphinx::Deltas.
17
- processor_for('ThinkingSphinx::Deltas::DefaultDelta').
18
- should == ThinkingSphinx::Deltas::DefaultDelta
16
+ expect(ThinkingSphinx::Deltas.
17
+ processor_for('ThinkingSphinx::Deltas::DefaultDelta')).
18
+ to eq(ThinkingSphinx::Deltas::DefaultDelta)
19
19
  end
20
20
  end
21
21
 
@@ -29,7 +29,7 @@ describe ThinkingSphinx::Deltas do
29
29
  let(:processor) { double('processor', :index => true) }
30
30
 
31
31
  before :each do
32
- ThinkingSphinx::Configuration.stub :instance => config
32
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
33
33
  end
34
34
 
35
35
  it "executes the given block" do
@@ -39,12 +39,12 @@ describe ThinkingSphinx::Deltas do
39
39
  variable = :bar
40
40
  end
41
41
 
42
- variable.should == :bar
42
+ expect(variable).to eq(:bar)
43
43
  end
44
44
 
45
45
  it "suspends deltas within the block" do
46
46
  ThinkingSphinx::Deltas.suspend :user do
47
- ThinkingSphinx::Deltas.should be_suspended
47
+ expect(ThinkingSphinx::Deltas).to be_suspended
48
48
  end
49
49
  end
50
50
 
@@ -53,11 +53,11 @@ describe ThinkingSphinx::Deltas do
53
53
  #
54
54
  end
55
55
 
56
- ThinkingSphinx::Deltas.should_not be_suspended
56
+ expect(ThinkingSphinx::Deltas).not_to be_suspended
57
57
  end
58
58
 
59
59
  it "processes the delta indices for the given reference" do
60
- processor.should_receive(:index).with(delta_index)
60
+ expect(processor).to receive(:index).with(delta_index)
61
61
 
62
62
  ThinkingSphinx::Deltas.suspend :user do
63
63
  #
@@ -65,7 +65,7 @@ describe ThinkingSphinx::Deltas do
65
65
  end
66
66
 
67
67
  it "does not process the core indices for the given reference" do
68
- processor.should_not_receive(:index).with(core_index)
68
+ expect(processor).not_to receive(:index).with(core_index)
69
69
 
70
70
  ThinkingSphinx::Deltas.suspend :user do
71
71
  #
@@ -6,73 +6,73 @@ describe ThinkingSphinx::SphinxError do
6
6
  :backtrace => ['foo', 'bar'] }
7
7
 
8
8
  it "translates syntax errors" do
9
- error.stub :message => 'index foo: syntax error: something is wrong'
9
+ allow(error).to receive_messages :message => 'index foo: syntax error: something is wrong'
10
10
 
11
- ThinkingSphinx::SphinxError.new_from_mysql(error).
12
- should be_a(ThinkingSphinx::SyntaxError)
11
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
12
+ to be_a(ThinkingSphinx::SyntaxError)
13
13
  end
14
14
 
15
15
  it "translates parse errors" do
16
- error.stub :message => 'index foo: parse error: something is wrong'
16
+ allow(error).to receive_messages :message => 'index foo: parse error: something is wrong'
17
17
 
18
- ThinkingSphinx::SphinxError.new_from_mysql(error).
19
- should be_a(ThinkingSphinx::ParseError)
18
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
19
+ to be_a(ThinkingSphinx::ParseError)
20
20
  end
21
21
 
22
22
  it "translates query errors" do
23
- error.stub :message => 'index foo: query error: something is wrong'
23
+ allow(error).to receive_messages :message => 'index foo: query error: something is wrong'
24
24
 
25
- ThinkingSphinx::SphinxError.new_from_mysql(error).
26
- should be_a(ThinkingSphinx::QueryError)
25
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
26
+ to be_a(ThinkingSphinx::QueryError)
27
27
  end
28
28
 
29
29
  it "translates connection errors" do
30
- error.stub :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
30
+ allow(error).to receive_messages :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
31
31
 
32
- ThinkingSphinx::SphinxError.new_from_mysql(error).
33
- should be_a(ThinkingSphinx::ConnectionError)
32
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
33
+ to be_a(ThinkingSphinx::ConnectionError)
34
34
  end
35
35
 
36
36
  it 'translates out-of-bounds errors' do
37
- error.stub :message => "offset out of bounds (offset=1001, max_matches=1000)"
37
+ allow(error).to receive_messages :message => "offset out of bounds (offset=1001, max_matches=1000)"
38
38
 
39
- ThinkingSphinx::SphinxError.new_from_mysql(error).
40
- should be_a(ThinkingSphinx::OutOfBoundsError)
39
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
40
+ to be_a(ThinkingSphinx::OutOfBoundsError)
41
41
  end
42
42
 
43
43
  it 'prefixes the connection error message' do
44
- error.stub :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
44
+ allow(error).to receive_messages :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
45
45
 
46
- ThinkingSphinx::SphinxError.new_from_mysql(error).message.
47
- should == "Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (61)"
46
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error).message).
47
+ to eq("Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (61)")
48
48
  end
49
49
 
50
50
  it "translates jdbc connection errors" do
51
- error.stub :message => "Communications link failure"
51
+ allow(error).to receive_messages :message => "Communications link failure"
52
52
 
53
- ThinkingSphinx::SphinxError.new_from_mysql(error).
54
- should be_a(ThinkingSphinx::ConnectionError)
53
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
54
+ to be_a(ThinkingSphinx::ConnectionError)
55
55
  end
56
56
 
57
57
  it 'prefixes the jdbc connection error message' do
58
- error.stub :message => "Communications link failure"
58
+ allow(error).to receive_messages :message => "Communications link failure"
59
59
 
60
- ThinkingSphinx::SphinxError.new_from_mysql(error).message.
61
- should == "Error connecting to Sphinx via the MySQL protocol. Communications link failure"
60
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error).message).
61
+ to eq("Error connecting to Sphinx via the MySQL protocol. Communications link failure")
62
62
  end
63
63
 
64
64
  it "defaults to sphinx errors" do
65
- error.stub :message => 'index foo: unknown error: something is wrong'
65
+ allow(error).to receive_messages :message => 'index foo: unknown error: something is wrong'
66
66
 
67
- ThinkingSphinx::SphinxError.new_from_mysql(error).
68
- should be_a(ThinkingSphinx::SphinxError)
67
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
68
+ to be_a(ThinkingSphinx::SphinxError)
69
69
  end
70
70
 
71
71
  it "keeps the original error's backtrace" do
72
- error.stub :message => 'index foo: unknown error: something is wrong'
72
+ allow(error).to receive_messages :message => 'index foo: unknown error: something is wrong'
73
73
 
74
- ThinkingSphinx::SphinxError.new_from_mysql(error).
75
- backtrace.should == error.backtrace
74
+ expect(ThinkingSphinx::SphinxError.new_from_mysql(error).
75
+ backtrace).to eq(error.backtrace)
76
76
  end
77
77
  end
78
78
  end
@@ -7,13 +7,13 @@ describe ThinkingSphinx::Excerpter do
7
7
  }
8
8
 
9
9
  before :each do
10
- ThinkingSphinx::Connection.stub(:take).and_yield(connection)
11
- Riddle::Query.stub :snippets => 'CALL SNIPPETS'
10
+ allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
11
+ allow(Riddle::Query).to receive_messages :snippets => 'CALL SNIPPETS'
12
12
  end
13
13
 
14
14
  describe '#excerpt!' do
15
15
  it "generates a snippets call" do
16
- Riddle::Query.should_receive(:snippets).
16
+ expect(Riddle::Query).to receive(:snippets).
17
17
  with('all of the words', 'index', 'all words',
18
18
  ThinkingSphinx::Excerpter::DefaultOptions).
19
19
  and_return('CALL SNIPPETS')
@@ -25,7 +25,7 @@ describe ThinkingSphinx::Excerpter do
25
25
  excerpter = ThinkingSphinx::Excerpter.new('index', 'all words',
26
26
  :before_match => '<b>', :chunk_separator => ' -- ')
27
27
 
28
- Riddle::Query.should_receive(:snippets).
28
+ expect(Riddle::Query).to receive(:snippets).
29
29
  with('all of the words', 'index', 'all words',
30
30
  :before_match => '<b>', :after_match => '</span>',
31
31
  :chunk_separator => ' -- ').
@@ -35,16 +35,16 @@ describe ThinkingSphinx::Excerpter do
35
35
  end
36
36
 
37
37
  it "sends the snippets call to Sphinx" do
38
- connection.should_receive(:execute).with('CALL SNIPPETS').
38
+ expect(connection).to receive(:execute).with('CALL SNIPPETS').
39
39
  and_return([{'snippet' => ''}])
40
40
 
41
41
  excerpter.excerpt!('all of the words')
42
42
  end
43
43
 
44
44
  it "returns the first value returned by Sphinx" do
45
- connection.stub :execute => [{'snippet' => 'some highlighted words'}]
45
+ allow(connection).to receive_messages :execute => [{'snippet' => 'some highlighted words'}]
46
46
 
47
- excerpter.excerpt!('all of the words').should == 'some highlighted words'
47
+ expect(excerpter.excerpt!('all of the words')).to eq('some highlighted words')
48
48
  end
49
49
  end
50
50
  end