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
@@ -22,21 +22,21 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
22
22
 
23
23
  describe '#call' do
24
24
  before :each do
25
- context.stub :search => search
26
- context.stub :configuration => configuration
27
- model.stub :unscoped => model
25
+ allow(context).to receive_messages :search => search
26
+ allow(context).to receive_messages :configuration => configuration
27
+ allow(model).to receive_messages :unscoped => model
28
28
  end
29
29
 
30
30
  it "translates records to ActiveRecord objects" do
31
31
  model_name = double('article', :constantize => model)
32
32
  instance = double('instance', :id => 24)
33
- model.stub :where => [instance]
33
+ allow(model).to receive_messages :where => [instance]
34
34
 
35
35
  context[:results] << raw_result(24, model_name)
36
36
 
37
37
  middleware.call [context]
38
38
 
39
- context[:results].should == [instance]
39
+ expect(context[:results]).to eq([instance])
40
40
  end
41
41
 
42
42
  it "only queries the model once for the given search results" do
@@ -46,7 +46,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
46
46
  context[:results] << raw_result(24, model_name)
47
47
  context[:results] << raw_result(42, model_name)
48
48
 
49
- model.should_receive(:where).once.and_return([instance_a, instance_b])
49
+ expect(model).to receive(:where).once.and_return([instance_a, instance_b])
50
50
 
51
51
  middleware.call [context]
52
52
  end
@@ -60,14 +60,14 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
60
60
  user_name = double('user name', :constantize => user_model)
61
61
  user = double('user instance', :id => 12)
62
62
 
63
- article_model.stub :unscoped => article_model
64
- user_model.stub :unscoped => user_model
63
+ allow(article_model).to receive_messages :unscoped => article_model
64
+ allow(user_model).to receive_messages :unscoped => user_model
65
65
 
66
66
  context[:results] << raw_result(24, article_name)
67
67
  context[:results] << raw_result(12, user_name)
68
68
 
69
- article_model.should_receive(:where).once.and_return([article])
70
- user_model.should_receive(:where).once.and_return([user])
69
+ expect(article_model).to receive(:where).once.and_return([article])
70
+ expect(user_model).to receive(:where).once.and_return([user])
71
71
 
72
72
  middleware.call [context]
73
73
  end
@@ -80,11 +80,11 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
80
80
  context[:results] << raw_result(2, model_name)
81
81
  context[:results] << raw_result(1, model_name)
82
82
 
83
- model.stub(:where => [instance_1, instance_2])
83
+ allow(model).to receive_messages(:where => [instance_1, instance_2])
84
84
 
85
85
  middleware.call [context]
86
86
 
87
- context[:results].should == [instance_2, instance_1]
87
+ expect(context[:results]).to eq([instance_2, instance_1])
88
88
  end
89
89
 
90
90
  it "returns objects in database order if a SQL order clause is supplied" do
@@ -95,20 +95,20 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
95
95
  context[:results] << raw_result(2, model_name)
96
96
  context[:results] << raw_result(1, model_name)
97
97
 
98
- model.stub(:order => model, :where => [instance_1, instance_2])
98
+ allow(model).to receive_messages(:order => model, :where => [instance_1, instance_2])
99
99
  search.options[:sql] = {:order => 'name DESC'}
100
100
 
101
101
  middleware.call [context]
102
102
 
103
- context[:results].should == [instance_1, instance_2]
103
+ expect(context[:results]).to eq([instance_1, instance_2])
104
104
  end
105
105
 
106
106
  it "handles model without primary key" do
107
107
  no_primary_key_model = double('no primary key model')
108
- no_primary_key_model.stub :unscoped => no_primary_key_model
108
+ allow(no_primary_key_model).to receive_messages :unscoped => no_primary_key_model
109
109
  model_name = double('article', :constantize => no_primary_key_model)
110
110
  instance = double('instance', :id => 1)
111
- no_primary_key_model.stub :where => [instance]
111
+ allow(no_primary_key_model).to receive_messages :where => [instance]
112
112
 
113
113
  context[:results] << raw_result(1, model_name)
114
114
 
@@ -119,7 +119,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
119
119
  let(:relation) { double('relation', :where => []) }
120
120
 
121
121
  before :each do
122
- model.stub :unscoped => relation
122
+ allow(model).to receive_messages :unscoped => relation
123
123
 
124
124
  model_name = double('article', :constantize => model)
125
125
  context[:results] << raw_result(1, model_name)
@@ -128,7 +128,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
128
128
  it "passes through SQL include options to the relation" do
129
129
  search.options[:sql] = {:include => :association}
130
130
 
131
- relation.should_receive(:includes).with(:association).
131
+ expect(relation).to receive(:includes).with(:association).
132
132
  and_return(relation)
133
133
 
134
134
  middleware.call [context]
@@ -137,7 +137,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
137
137
  it "passes through SQL join options to the relation" do
138
138
  search.options[:sql] = {:joins => :association}
139
139
 
140
- relation.should_receive(:joins).with(:association).and_return(relation)
140
+ expect(relation).to receive(:joins).with(:association).and_return(relation)
141
141
 
142
142
  middleware.call [context]
143
143
  end
@@ -145,7 +145,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
145
145
  it "passes through SQL order options to the relation" do
146
146
  search.options[:sql] = {:order => 'name DESC'}
147
147
 
148
- relation.should_receive(:order).with('name DESC').and_return(relation)
148
+ expect(relation).to receive(:order).with('name DESC').and_return(relation)
149
149
 
150
150
  middleware.call [context]
151
151
  end
@@ -153,7 +153,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
153
153
  it "passes through SQL select options to the relation" do
154
154
  search.options[:sql] = {:select => :column}
155
155
 
156
- relation.should_receive(:select).with(:column).and_return(relation)
156
+ expect(relation).to receive(:select).with(:column).and_return(relation)
157
157
 
158
158
  middleware.call [context]
159
159
  end
@@ -161,7 +161,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
161
161
  it "passes through SQL group options to the relation" do
162
162
  search.options[:sql] = {:group => :column}
163
163
 
164
- relation.should_receive(:group).with(:column).and_return(relation)
164
+ expect(relation).to receive(:group).with(:column).and_return(relation)
165
165
 
166
166
  middleware.call [context]
167
167
  end
@@ -16,7 +16,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
16
16
  before :each do
17
17
  stub_const 'ThinkingSphinx::Panes::DistancePane', double
18
18
 
19
- context.stub :search => search
19
+ allow(context).to receive_messages :search => search
20
20
  end
21
21
 
22
22
  describe '#call' do
@@ -26,7 +26,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
26
26
  end
27
27
 
28
28
  it "doesn't add anything if :geo is nil" do
29
- sphinx_sql.should_not_receive(:prepend_values)
29
+ expect(sphinx_sql).not_to receive(:prepend_values)
30
30
 
31
31
  middleware.call [context]
32
32
  end
@@ -38,7 +38,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
38
38
  end
39
39
 
40
40
  it "adds the geodist function when given a :geo option" do
41
- sphinx_sql.should_receive(:prepend_values).
41
+ expect(sphinx_sql).to receive(:prepend_values).
42
42
  with('GEODIST(0.1, 0.2, lat, lng) AS geodist').
43
43
  and_return(sphinx_sql)
44
44
 
@@ -46,18 +46,18 @@ describe ThinkingSphinx::Middlewares::Geographer do
46
46
  end
47
47
 
48
48
  it "adds the distance pane" do
49
- sphinx_sql.stub :prepend_values => sphinx_sql
49
+ allow(sphinx_sql).to receive_messages :prepend_values => sphinx_sql
50
50
 
51
51
  middleware.call [context]
52
52
 
53
- context[:panes].should include(ThinkingSphinx::Panes::DistancePane)
53
+ expect(context[:panes]).to include(ThinkingSphinx::Panes::DistancePane)
54
54
  end
55
55
 
56
56
  it "respects :latitude_attr and :longitude_attr options" do
57
57
  search.options[:latitude_attr] = 'side_to_side'
58
58
  search.options[:longitude_attr] = 'up_or_down'
59
59
 
60
- sphinx_sql.should_receive(:prepend_values).
60
+ expect(sphinx_sql).to receive(:prepend_values).
61
61
  with('GEODIST(0.1, 0.2, side_to_side, up_or_down) AS geodist').
62
62
  and_return(sphinx_sql)
63
63
 
@@ -68,7 +68,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
68
68
  context[:indices] << double('index',
69
69
  :unique_attribute_names => ['latitude'], :name => 'an_index')
70
70
 
71
- sphinx_sql.should_receive(:prepend_values).
71
+ expect(sphinx_sql).to receive(:prepend_values).
72
72
  with('GEODIST(0.1, 0.2, latitude, lng) AS geodist').
73
73
  and_return(sphinx_sql)
74
74
 
@@ -79,7 +79,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
79
79
  context[:indices] << double('index',
80
80
  :unique_attribute_names => ['longitude'], :name => 'an_index')
81
81
 
82
- sphinx_sql.should_receive(:prepend_values).
82
+ expect(sphinx_sql).to receive(:prepend_values).
83
83
  with('GEODIST(0.1, 0.2, lat, longitude) AS geodist').
84
84
  and_return(sphinx_sql)
85
85
 
@@ -89,7 +89,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
89
89
  it "handles very small values" do
90
90
  search.options[:geo] = [0.0000001, 0.00000000002]
91
91
 
92
- sphinx_sql.should_receive(:prepend_values).
92
+ expect(sphinx_sql).to receive(:prepend_values).
93
93
  with('GEODIST(0.0000001, 0.00000000002, lat, lng) AS geodist').
94
94
  and_return(sphinx_sql)
95
95
 
@@ -22,7 +22,7 @@ describe ThinkingSphinx::Middlewares::Glazier do
22
22
  before :each do
23
23
  stub_const 'ThinkingSphinx::Search::Glaze', double(:new => glazed_result)
24
24
 
25
- context.stub :search => search
25
+ allow(context).to receive_messages :search => search
26
26
  end
27
27
 
28
28
  context 'No panes provided' do
@@ -33,7 +33,7 @@ describe ThinkingSphinx::Middlewares::Glazier do
33
33
  it "leaves the results as they are" do
34
34
  middleware.call [context]
35
35
 
36
- context[:results].should == [result]
36
+ expect(context[:results]).to eq([result])
37
37
  end
38
38
  end
39
39
 
@@ -47,11 +47,11 @@ describe ThinkingSphinx::Middlewares::Glazier do
47
47
  it "replaces each result with a glazed version" do
48
48
  middleware.call [context]
49
49
 
50
- context[:results].should == [glazed_result]
50
+ expect(context[:results]).to eq([glazed_result])
51
51
  end
52
52
 
53
53
  it "creates a glazed result for each result" do
54
- ThinkingSphinx::Search::Glaze.should_receive(:new).
54
+ expect(ThinkingSphinx::Search::Glaze).to receive(:new).
55
55
  with(context, result, raw_result, [pane_class]).
56
56
  and_return(glazed_result)
57
57
 
@@ -16,7 +16,7 @@ describe ThinkingSphinx::Middlewares::Inquirer do
16
16
 
17
17
  before :each do
18
18
  batch_class = double
19
- batch_class.stub(:new).and_return(batch_inquirer)
19
+ allow(batch_class).to receive(:new).and_return(batch_inquirer)
20
20
 
21
21
  stub_const 'Riddle::Query', double(:meta => 'SHOW META')
22
22
  stub_const 'ThinkingSphinx::Search::BatchInquirer', batch_class
@@ -24,8 +24,8 @@ describe ThinkingSphinx::Middlewares::Inquirer do
24
24
 
25
25
  describe '#call' do
26
26
  it "passes through the SphinxQL from a Riddle::Query::Select object" do
27
- batch_inquirer.should_receive(:append_query).with('SELECT * FROM index')
28
- batch_inquirer.should_receive(:append_query).with('SHOW META')
27
+ expect(batch_inquirer).to receive(:append_query).with('SELECT * FROM index')
28
+ expect(batch_inquirer).to receive(:append_query).with('SHOW META')
29
29
 
30
30
  middleware.call [context]
31
31
  end
@@ -33,19 +33,19 @@ describe ThinkingSphinx::Middlewares::Inquirer do
33
33
  it "sets up the raw results" do
34
34
  middleware.call [context]
35
35
 
36
- context[:raw].should == [:raw]
36
+ expect(context[:raw]).to eq([:raw])
37
37
  end
38
38
 
39
39
  it "sets up the meta results as a hash" do
40
40
  middleware.call [context]
41
41
 
42
- context[:meta].should == {'meta' => 'value'}
42
+ expect(context[:meta]).to eq({'meta' => 'value'})
43
43
  end
44
44
 
45
45
  it "uses the raw values as the initial results" do
46
46
  middleware.call [context]
47
47
 
48
- context[:results].should == [:raw]
48
+ expect(context[:results]).to eq([:raw])
49
49
  end
50
50
 
51
51
  context "with mysql2 result" do
@@ -63,7 +63,7 @@ describe ThinkingSphinx::Middlewares::Inquirer do
63
63
  it "converts the results into an array" do
64
64
  middleware.call [context]
65
65
 
66
- context[:results].should be_a Array
66
+ expect(context[:results]).to be_a Array
67
67
  end
68
68
  end
69
69
  end
@@ -36,7 +36,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
36
36
  stub_const 'Riddle::Query::Select', double(:new => sphinx_sql)
37
37
  stub_const 'ThinkingSphinx::Search::Query', double(:new => query)
38
38
 
39
- context.stub :search => search, :configuration => configuration
39
+ allow(context).to receive_messages :search => search, :configuration => configuration
40
40
  end
41
41
 
42
42
  describe '#call' do
@@ -46,7 +46,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
46
46
  double('index', :name => 'user_core', :options => {})
47
47
  ]
48
48
 
49
- sphinx_sql.should_receive(:from).with('`article_core`', '`user_core`').
49
+ expect(sphinx_sql).to receive(:from).with('`article_core`', '`user_core`').
50
50
  and_return(sphinx_sql)
51
51
 
52
52
  middleware.call [context]
@@ -57,9 +57,9 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
57
57
  :name => 'User')
58
58
  search.options[:classes] = [klass]
59
59
  search.options[:indices] = ['user_core']
60
- index_set.first.stub :reference => :user
60
+ allow(index_set.first).to receive_messages :reference => :user
61
61
 
62
- set_class.should_receive(:new).
62
+ expect(set_class).to receive(:new).
63
63
  with(:classes => [klass], :indices => ['user_core']).
64
64
  and_return(index_set)
65
65
 
@@ -75,19 +75,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
75
75
  end
76
76
 
77
77
  it "generates a Sphinx query from the provided keyword and conditions" do
78
- search.stub :query => 'tasty'
78
+ allow(search).to receive_messages :query => 'tasty'
79
79
  search.options[:conditions] = {:title => 'pancakes'}
80
80
 
81
- ThinkingSphinx::Search::Query.should_receive(:new).
81
+ expect(ThinkingSphinx::Search::Query).to receive(:new).
82
82
  with('tasty', {:title => 'pancakes'}, anything).and_return(query)
83
83
 
84
84
  middleware.call [context]
85
85
  end
86
86
 
87
87
  it "matches on the generated query" do
88
- query.stub :to_s => 'waffles'
88
+ allow(query).to receive_messages :to_s => 'waffles'
89
89
 
90
- sphinx_sql.should_receive(:matching).with('waffles')
90
+ expect(sphinx_sql).to receive(:matching).with('waffles')
91
91
 
92
92
  middleware.call [context]
93
93
  end
@@ -95,15 +95,15 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
95
95
  it "requests a starred query if the :star option is set to true" do
96
96
  search.options[:star] = true
97
97
 
98
- ThinkingSphinx::Search::Query.should_receive(:new).
98
+ expect(ThinkingSphinx::Search::Query).to receive(:new).
99
99
  with(anything, anything, true).and_return(query)
100
100
 
101
101
  middleware.call [context]
102
102
  end
103
103
 
104
104
  it "doesn't append a field condition by default" do
105
- ThinkingSphinx::Search::Query.should_receive(:new) do |query, conditions, star|
106
- conditions[:sphinx_internal_class_name].should be_nil
105
+ expect(ThinkingSphinx::Search::Query).to receive(:new) do |query, conditions, star|
106
+ expect(conditions[:sphinx_internal_class_name]).to be_nil
107
107
  query
108
108
  end
109
109
 
@@ -113,12 +113,12 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
113
113
  it "doesn't append a field condition if all classes match index references" do
114
114
  model = double('model', :connection => double,
115
115
  :ancestors => [ActiveRecord::Base], :name => 'Animal')
116
- index_set.first.stub :reference => :animal
116
+ allow(index_set.first).to receive_messages :reference => :animal
117
117
 
118
118
  search.options[:classes] = [model]
119
119
 
120
- ThinkingSphinx::Search::Query.should_receive(:new) do |query, conditions, star|
121
- conditions[:sphinx_internal_class_name].should be_nil
120
+ expect(ThinkingSphinx::Search::Query).to receive(:new) do |query, conditions, star|
121
+ expect(conditions[:sphinx_internal_class_name]).to be_nil
122
122
  query
123
123
  end
124
124
 
@@ -132,19 +132,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
132
132
  def self.name; 'Cat'; end
133
133
  def self.inheritance_column; 'type'; end
134
134
  end
135
- supermodel.stub :connection => db_connection, :column_names => ['type']
135
+ allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
136
136
  submodel = Class.new(supermodel) do
137
137
  def self.name; 'Lion'; end
138
138
  def self.inheritance_column; 'type'; end
139
139
  def self.table_name; 'cats'; end
140
140
  end
141
- submodel.stub :connection => db_connection, :column_names => ['type'],
141
+ allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
142
142
  :descendants => []
143
- index_set.first.stub :reference => :cat
143
+ allow(index_set.first).to receive_messages :reference => :cat
144
144
 
145
145
  search.options[:classes] = [submodel]
146
146
 
147
- ThinkingSphinx::Search::Query.should_receive(:new).with(anything,
147
+ expect(ThinkingSphinx::Search::Query).to receive(:new).with(anything,
148
148
  hash_including(:sphinx_internal_class_name => '(Lion)'), anything).
149
149
  and_return(query)
150
150
 
@@ -158,19 +158,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
158
158
  def self.name; 'Animals::Cat'; end
159
159
  def self.inheritance_column; 'type'; end
160
160
  end
161
- supermodel.stub :connection => db_connection, :column_names => ['type']
161
+ allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
162
162
  submodel = Class.new(supermodel) do
163
163
  def self.name; 'Animals::Lion'; end
164
164
  def self.inheritance_column; 'type'; end
165
165
  def self.table_name; 'cats'; end
166
166
  end
167
- submodel.stub :connection => db_connection, :column_names => ['type'],
167
+ allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
168
168
  :descendants => []
169
- index_set.first.stub :reference => :"animals/cat"
169
+ allow(index_set.first).to receive_messages :reference => :"animals/cat"
170
170
 
171
171
  search.options[:classes] = [submodel]
172
172
 
173
- ThinkingSphinx::Search::Query.should_receive(:new).with(anything,
173
+ expect(ThinkingSphinx::Search::Query).to receive(:new).with(anything,
174
174
  hash_including(:sphinx_internal_class_name => '("Animals::Lion")'), anything).
175
175
  and_return(query)
176
176
 
@@ -180,12 +180,12 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
180
180
  it "does not query the database for subclasses if :skip_sti is set to true" do
181
181
  model = double('model', :connection => double,
182
182
  :ancestors => [ActiveRecord::Base], :name => 'Animal')
183
- index_set.first.stub :reference => :animal
183
+ allow(index_set.first).to receive_messages :reference => :animal
184
184
 
185
185
  search.options[:classes] = [model]
186
186
  search.options[:skip_sti] = true
187
187
 
188
- model.connection.should_not_receive(:select_values)
188
+ expect(model.connection).not_to receive(:select_values)
189
189
 
190
190
  middleware.call [context]
191
191
  end
@@ -197,15 +197,15 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
197
197
  def self.name; 'Cat'; end
198
198
  def self.inheritance_column; 'type'; end
199
199
  end
200
- supermodel.stub :connection => db_connection, :column_names => ['type']
200
+ allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
201
201
  submodel = Class.new(supermodel) do
202
202
  def self.name; 'Lion'; end
203
203
  def self.inheritance_column; 'type'; end
204
204
  def self.table_name; 'cats'; end
205
205
  end
206
- submodel.stub :connection => db_connection, :column_names => ['type'],
206
+ allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
207
207
  :descendants => []
208
- index_set.first.stub :reference => :cat
208
+ allow(index_set.first).to receive_messages :reference => :cat
209
209
 
210
210
  search.options[:classes] = [submodel]
211
211
 
@@ -213,7 +213,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
213
213
  end
214
214
 
215
215
  it "filters out deleted values by default" do
216
- sphinx_sql.should_receive(:where).with(:sphinx_deleted => false).
216
+ expect(sphinx_sql).to receive(:where).with(:sphinx_deleted => false).
217
217
  and_return(sphinx_sql)
218
218
 
219
219
  middleware.call [context]
@@ -222,7 +222,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
222
222
  it "appends boolean attribute filters to the query" do
223
223
  search.options[:with] = {:visible => true}
224
224
 
225
- sphinx_sql.should_receive(:where).with(hash_including(:visible => true)).
225
+ expect(sphinx_sql).to receive(:where).with(hash_including(:visible => true)).
226
226
  and_return(sphinx_sql)
227
227
 
228
228
  middleware.call [context]
@@ -231,7 +231,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
231
231
  it "appends exclusive filters to the query" do
232
232
  search.options[:without] = {:tag_ids => [2, 4, 8]}
233
233
 
234
- sphinx_sql.should_receive(:where_not).
234
+ expect(sphinx_sql).to receive(:where_not).
235
235
  with(hash_including(:tag_ids => [2, 4, 8])).and_return(sphinx_sql)
236
236
 
237
237
  middleware.call [context]
@@ -240,7 +240,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
240
240
  it "appends the without_ids option as an exclusive filter" do
241
241
  search.options[:without_ids] = [1, 4, 9]
242
242
 
243
- sphinx_sql.should_receive(:where_not).
243
+ expect(sphinx_sql).to receive(:where_not).
244
244
  with(hash_including(:sphinx_internal_id => [1, 4, 9])).
245
245
  and_return(sphinx_sql)
246
246
 
@@ -250,7 +250,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
250
250
  it "appends MVA matches with all values" do
251
251
  search.options[:with_all] = {:tag_ids => [1, 7]}
252
252
 
253
- sphinx_sql.should_receive(:where_all).
253
+ expect(sphinx_sql).to receive(:where_all).
254
254
  with(:tag_ids => [1, 7]).and_return(sphinx_sql)
255
255
 
256
256
  middleware.call [context]
@@ -259,7 +259,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
259
259
  it "appends MVA matches without all of the given values" do
260
260
  search.options[:without_all] = {:tag_ids => [1, 7]}
261
261
 
262
- sphinx_sql.should_receive(:where_not_all).
262
+ expect(sphinx_sql).to receive(:where_not_all).
263
263
  with(:tag_ids => [1, 7]).and_return(sphinx_sql)
264
264
 
265
265
  middleware.call [context]
@@ -268,7 +268,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
268
268
  it "appends order clauses to the query" do
269
269
  search.options[:order] = 'created_at ASC'
270
270
 
271
- sphinx_sql.should_receive(:order_by).with('created_at ASC').
271
+ expect(sphinx_sql).to receive(:order_by).with('created_at ASC').
272
272
  and_return(sphinx_sql)
273
273
 
274
274
  middleware.call [context]
@@ -277,7 +277,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
277
277
  it "presumes attributes given as symbols should be sorted ascendingly" do
278
278
  search.options[:order] = :updated_at
279
279
 
280
- sphinx_sql.should_receive(:order_by).with('updated_at ASC').
280
+ expect(sphinx_sql).to receive(:order_by).with('updated_at ASC').
281
281
  and_return(sphinx_sql)
282
282
 
283
283
  middleware.call [context]
@@ -285,10 +285,10 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
285
285
 
286
286
  it "appends a group by clause to the query" do
287
287
  search.options[:group_by] = :foreign_id
288
- search.stub :masks => []
289
- sphinx_sql.stub :values => sphinx_sql
288
+ allow(search).to receive_messages :masks => []
289
+ allow(sphinx_sql).to receive_messages :values => sphinx_sql
290
290
 
291
- sphinx_sql.should_receive(:group_by).with('foreign_id').
291
+ expect(sphinx_sql).to receive(:group_by).with('foreign_id').
292
292
  and_return(sphinx_sql)
293
293
 
294
294
  middleware.call [context]
@@ -297,24 +297,24 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
297
297
  it "appends a sort within group clause to the query" do
298
298
  search.options[:order_group_by] = :title
299
299
 
300
- sphinx_sql.should_receive(:order_within_group_by).with('title ASC').
300
+ expect(sphinx_sql).to receive(:order_within_group_by).with('title ASC').
301
301
  and_return(sphinx_sql)
302
302
 
303
303
  middleware.call [context]
304
304
  end
305
305
 
306
306
  it "uses the provided offset" do
307
- search.stub :offset => 50
307
+ allow(search).to receive_messages :offset => 50
308
308
 
309
- sphinx_sql.should_receive(:offset).with(50).and_return(sphinx_sql)
309
+ expect(sphinx_sql).to receive(:offset).with(50).and_return(sphinx_sql)
310
310
 
311
311
  middleware.call [context]
312
312
  end
313
313
 
314
314
  it "uses the provided limit" do
315
- search.stub :per_page => 24
315
+ allow(search).to receive_messages :per_page => 24
316
316
 
317
- sphinx_sql.should_receive(:limit).with(24).and_return(sphinx_sql)
317
+ expect(sphinx_sql).to receive(:limit).with(24).and_return(sphinx_sql)
318
318
 
319
319
  middleware.call [context]
320
320
  end
@@ -322,7 +322,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
322
322
  it "adds the provided select statement" do
323
323
  search.options[:select] = 'foo as bar'
324
324
 
325
- sphinx_sql.should_receive(:values).with('foo as bar').
325
+ expect(sphinx_sql).to receive(:values).with('foo as bar').
326
326
  and_return(sphinx_sql)
327
327
 
328
328
  middleware.call [context]
@@ -331,7 +331,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
331
331
  it "adds the provided group-best count" do
332
332
  search.options[:group_best] = 5
333
333
 
334
- sphinx_sql.should_receive(:group_best).with(5).and_return(sphinx_sql)
334
+ expect(sphinx_sql).to receive(:group_best).with(5).and_return(sphinx_sql)
335
335
 
336
336
  middleware.call [context]
337
337
  end
@@ -339,7 +339,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
339
339
  it "adds the provided having clause" do
340
340
  search.options[:having] = 'foo > 1'
341
341
 
342
- sphinx_sql.should_receive(:having).with('foo > 1').and_return(sphinx_sql)
342
+ expect(sphinx_sql).to receive(:having).with('foo > 1').and_return(sphinx_sql)
343
343
 
344
344
  middleware.call [context]
345
345
  end
@@ -347,8 +347,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
347
347
  it "uses any provided field weights" do
348
348
  search.options[:field_weights] = {:title => 3}
349
349
 
350
- sphinx_sql.should_receive(:with_options) do |options|
351
- options[:field_weights].should == {:title => 3}
350
+ expect(sphinx_sql).to receive(:with_options) do |options|
351
+ expect(options[:field_weights]).to eq({:title => 3})
352
352
  sphinx_sql
353
353
  end
354
354
 
@@ -358,7 +358,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
358
358
  it "uses index-defined field weights if they're available" do
359
359
  index_set.first.options[:field_weights] = {:title => 3}
360
360
 
361
- sphinx_sql.should_receive(:with_options).with(
361
+ expect(sphinx_sql).to receive(:with_options).with(
362
362
  hash_including(:field_weights => {:title => 3})
363
363
  ).and_return(sphinx_sql)
364
364
 
@@ -368,7 +368,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
368
368
  it "uses index-defined max matches if it's available" do
369
369
  index_set.first.options[:max_matches] = 100
370
370
 
371
- sphinx_sql.should_receive(:with_options).with(
371
+ expect(sphinx_sql).to receive(:with_options).with(
372
372
  hash_including(:max_matches => 100)
373
373
  ).and_return(sphinx_sql)
374
374
 
@@ -378,7 +378,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
378
378
  it "uses configuration-level max matches if set" do
379
379
  configuration.settings['max_matches'] = 120
380
380
 
381
- sphinx_sql.should_receive(:with_options).with(
381
+ expect(sphinx_sql).to receive(:with_options).with(
382
382
  hash_including(:max_matches => 120)
383
383
  ).and_return(sphinx_sql)
384
384
 
@@ -388,8 +388,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
388
388
  it "uses any given ranker option" do
389
389
  search.options[:ranker] = 'proximity'
390
390
 
391
- sphinx_sql.should_receive(:with_options) do |options|
392
- options[:ranker].should == 'proximity'
391
+ expect(sphinx_sql).to receive(:with_options) do |options|
392
+ expect(options[:ranker]).to eq('proximity')
393
393
  sphinx_sql
394
394
  end
395
395