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
@@ -7,11 +7,11 @@ describe ThinkingSphinx::RealTime::Attribute do
7
7
  describe '#name' do
8
8
  it "uses the provided option by default" do
9
9
  attribute = ThinkingSphinx::RealTime::Attribute.new column, :as => :foo
10
- attribute.name.should == 'foo'
10
+ expect(attribute.name).to eq('foo')
11
11
  end
12
12
 
13
13
  it "falls back to the column's name" do
14
- attribute.name.should == 'created_at'
14
+ expect(attribute.name).to eq('created_at')
15
15
  end
16
16
  end
17
17
 
@@ -21,34 +21,34 @@ describe ThinkingSphinx::RealTime::Attribute do
21
21
  let(:parent) { klass.new 'the parent name', nil }
22
22
 
23
23
  it "returns the column's name if it's a string" do
24
- column.stub :__name => 'value'
24
+ allow(column).to receive_messages :__name => 'value'
25
25
 
26
- attribute.translate(object).should == 'value'
26
+ expect(attribute.translate(object)).to eq('value')
27
27
  end
28
28
 
29
29
  it "returns the column's name if it's an integer" do
30
- column.stub :__name => 404
30
+ allow(column).to receive_messages :__name => 404
31
31
 
32
- attribute.translate(object).should == 404
32
+ expect(attribute.translate(object)).to eq(404)
33
33
  end
34
34
 
35
35
  it "returns the object's method matching the column's name" do
36
- object.stub :created_at => 'a time'
36
+ allow(object).to receive_messages :created_at => 'a time'
37
37
 
38
- attribute.translate(object).should == 'a time'
38
+ expect(attribute.translate(object)).to eq('a time')
39
39
  end
40
40
 
41
41
  it "uses the column's stack to navigate through the object tree" do
42
- column.stub :__name => :name, :__stack => [:parent]
42
+ allow(column).to receive_messages :__name => :name, :__stack => [:parent]
43
43
 
44
- attribute.translate(object).should == 'the parent name'
44
+ expect(attribute.translate(object)).to eq('the parent name')
45
45
  end
46
46
 
47
47
  it "returns zero if any element in the object tree is nil" do
48
- column.stub :__name => :name, :__stack => [:parent]
48
+ allow(column).to receive_messages :__name => :name, :__stack => [:parent]
49
49
  object.parent = nil
50
50
 
51
- attribute.translate(object).should be_zero
51
+ expect(attribute.translate(object)).to be_zero
52
52
  end
53
53
  end
54
54
 
@@ -56,7 +56,7 @@ describe ThinkingSphinx::RealTime::Attribute do
56
56
  it "returns the given type option" do
57
57
  attribute = ThinkingSphinx::RealTime::Attribute.new column,
58
58
  :type => :string
59
- attribute.type.should == :string
59
+ expect(attribute.type).to eq(:string)
60
60
  end
61
61
  end
62
62
  end
@@ -13,11 +13,11 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
13
13
  let(:connection) { double('connection', :execute => true) }
14
14
 
15
15
  before :each do
16
- ThinkingSphinx::Configuration.stub :instance => config
17
- ThinkingSphinx::Connection.stub_chain(:pool, :take).and_yield connection
16
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
17
+ allow(ThinkingSphinx::Connection).to receive_message_chain(:pool, :take).and_yield connection
18
18
  end
19
19
 
20
- describe '#after_save' do
20
+ describe '#after_save, #after_commit' do
21
21
  let(:insert) { double('insert', :to_sql => 'REPLACE INTO my_index') }
22
22
  let(:time) { 1.day.ago }
23
23
  let(:field) { double('field', :name => 'name', :translate => 'Foo') }
@@ -25,14 +25,14 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
25
25
  :translate => time) }
26
26
 
27
27
  before :each do
28
- ThinkingSphinx::Configuration.stub :instance => config
29
- Riddle::Query::Insert.stub :new => insert
30
- insert.stub :replace! => insert
31
- index.stub :fields => [field], :attributes => [attribute]
28
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
29
+ allow(Riddle::Query::Insert).to receive_messages :new => insert
30
+ allow(insert).to receive_messages :replace! => insert
31
+ allow(index).to receive_messages :fields => [field], :attributes => [attribute]
32
32
  end
33
33
 
34
34
  it "creates an insert statement with all fields and attributes" do
35
- Riddle::Query::Insert.should_receive(:new).
35
+ expect(Riddle::Query::Insert).to receive(:new).
36
36
  with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
37
37
  and_return(insert)
38
38
 
@@ -40,17 +40,37 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
40
40
  end
41
41
 
42
42
  it "switches the insert to a replace statement" do
43
- insert.should_receive(:replace!).and_return(insert)
43
+ expect(insert).to receive(:replace!).and_return(insert)
44
44
 
45
45
  callbacks.after_save instance
46
46
  end
47
47
 
48
48
  it "sends the insert through to the server" do
49
- connection.should_receive(:execute).with('REPLACE INTO my_index')
49
+ expect(connection).to receive(:execute).with('REPLACE INTO my_index')
50
50
 
51
51
  callbacks.after_save instance
52
52
  end
53
53
 
54
+ it "creates an insert statement with all fields and attributes" do
55
+ expect(Riddle::Query::Insert).to receive(:new).
56
+ with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
57
+ and_return(insert)
58
+
59
+ callbacks.after_commit instance
60
+ end
61
+
62
+ it "switches the insert to a replace statement" do
63
+ expect(insert).to receive(:replace!).and_return(insert)
64
+
65
+ callbacks.after_commit instance
66
+ end
67
+
68
+ it "sends the insert through to the server" do
69
+ expect(connection).to receive(:execute).with('REPLACE INTO my_index')
70
+
71
+ callbacks.after_commit instance
72
+ end
73
+
54
74
  context 'with a given path' do
55
75
  let(:callbacks) {
56
76
  ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks.new(
@@ -61,7 +81,7 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
61
81
  let(:user) { double('user', :id => 13, :persisted? => true) }
62
82
 
63
83
  it "creates an insert statement with all fields and attributes" do
64
- Riddle::Query::Insert.should_receive(:new).
84
+ expect(Riddle::Query::Insert).to receive(:new).
65
85
  with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
66
86
  and_return(insert)
67
87
 
@@ -69,16 +89,36 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
69
89
  end
70
90
 
71
91
  it "gets the document id for the user object" do
72
- index.should_receive(:document_id_for_key).with(13).and_return(123)
92
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
73
93
 
74
94
  callbacks.after_save instance
75
95
  end
76
96
 
77
97
  it "translates values for the user object" do
78
- field.should_receive(:translate).with(user).and_return('Foo')
98
+ expect(field).to receive(:translate).with(user).and_return('Foo')
79
99
 
80
100
  callbacks.after_save instance
81
101
  end
102
+
103
+ it "creates an insert statement with all fields and attributes" do
104
+ expect(Riddle::Query::Insert).to receive(:new).
105
+ with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
106
+ and_return(insert)
107
+
108
+ callbacks.after_commit instance
109
+ end
110
+
111
+ it "gets the document id for the user object" do
112
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
113
+
114
+ callbacks.after_commit instance
115
+ end
116
+
117
+ it "translates values for the user object" do
118
+ expect(field).to receive(:translate).with(user).and_return('Foo')
119
+
120
+ callbacks.after_commit instance
121
+ end
82
122
  end
83
123
 
84
124
  context 'with a path returning multiple objects' do
@@ -93,7 +133,7 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
93
133
  let(:user_b) { double('user', :id => 14, :persisted? => true) }
94
134
 
95
135
  it "creates insert statements with all fields and attributes" do
96
- Riddle::Query::Insert.should_receive(:new).twice.
136
+ expect(Riddle::Query::Insert).to receive(:new).twice.
97
137
  with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
98
138
  and_return(insert)
99
139
 
@@ -101,18 +141,40 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
101
141
  end
102
142
 
103
143
  it "gets the document id for each reader" do
104
- index.should_receive(:document_id_for_key).with(13).and_return(123)
105
- index.should_receive(:document_id_for_key).with(14).and_return(123)
144
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
145
+ expect(index).to receive(:document_id_for_key).with(14).and_return(123)
106
146
 
107
147
  callbacks.after_save instance
108
148
  end
109
149
 
110
150
  it "translates values for each reader" do
111
- field.should_receive(:translate).with(user_a).and_return('Foo')
112
- field.should_receive(:translate).with(user_b).and_return('Foo')
151
+ expect(field).to receive(:translate).with(user_a).and_return('Foo')
152
+ expect(field).to receive(:translate).with(user_b).and_return('Foo')
113
153
 
114
154
  callbacks.after_save instance
115
155
  end
156
+
157
+ it "creates insert statements with all fields and attributes" do
158
+ expect(Riddle::Query::Insert).to receive(:new).twice.
159
+ with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
160
+ and_return(insert)
161
+
162
+ callbacks.after_commit instance
163
+ end
164
+
165
+ it "gets the document id for each reader" do
166
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
167
+ expect(index).to receive(:document_id_for_key).with(14).and_return(123)
168
+
169
+ callbacks.after_commit instance
170
+ end
171
+
172
+ it "translates values for each reader" do
173
+ expect(field).to receive(:translate).with(user_a).and_return('Foo')
174
+ expect(field).to receive(:translate).with(user_b).and_return('Foo')
175
+
176
+ callbacks.after_commit instance
177
+ end
116
178
  end
117
179
 
118
180
  context 'with a block instead of a path' do
@@ -127,7 +189,7 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
127
189
  let(:user_b) { double('user', :id => 14, :persisted? => true) }
128
190
 
129
191
  it "creates insert statements with all fields and attributes" do
130
- Riddle::Query::Insert.should_receive(:new).twice.
192
+ expect(Riddle::Query::Insert).to receive(:new).twice.
131
193
  with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
132
194
  and_return(insert)
133
195
 
@@ -135,18 +197,40 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
135
197
  end
136
198
 
137
199
  it "gets the document id for each reader" do
138
- index.should_receive(:document_id_for_key).with(13).and_return(123)
139
- index.should_receive(:document_id_for_key).with(14).and_return(123)
200
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
201
+ expect(index).to receive(:document_id_for_key).with(14).and_return(123)
140
202
 
141
203
  callbacks.after_save instance
142
204
  end
143
205
 
144
206
  it "translates values for each reader" do
145
- field.should_receive(:translate).with(user_a).and_return('Foo')
146
- field.should_receive(:translate).with(user_b).and_return('Foo')
207
+ expect(field).to receive(:translate).with(user_a).and_return('Foo')
208
+ expect(field).to receive(:translate).with(user_b).and_return('Foo')
147
209
 
148
210
  callbacks.after_save instance
149
211
  end
212
+
213
+ it "creates insert statements with all fields and attributes" do
214
+ expect(Riddle::Query::Insert).to receive(:new).twice.
215
+ with('my_index', ['id', 'name', 'created_at'], [[123, 'Foo', time]]).
216
+ and_return(insert)
217
+
218
+ callbacks.after_commit instance
219
+ end
220
+
221
+ it "gets the document id for each reader" do
222
+ expect(index).to receive(:document_id_for_key).with(13).and_return(123)
223
+ expect(index).to receive(:document_id_for_key).with(14).and_return(123)
224
+
225
+ callbacks.after_commit instance
226
+ end
227
+
228
+ it "translates values for each reader" do
229
+ expect(field).to receive(:translate).with(user_a).and_return('Foo')
230
+ expect(field).to receive(:translate).with(user_b).and_return('Foo')
231
+
232
+ callbacks.after_commit instance
233
+ end
150
234
  end
151
235
  end
152
236
  end
@@ -6,11 +6,11 @@ describe ThinkingSphinx::RealTime::Field do
6
6
 
7
7
  describe '#column' do
8
8
  it 'returns the provided Column object' do
9
- field.column.should == column
9
+ expect(field.column).to eq(column)
10
10
  end
11
11
 
12
12
  it 'translates symbols to Column objects' do
13
- ThinkingSphinx::ActiveRecord::Column.should_receive(:new).with(:title).
13
+ expect(ThinkingSphinx::ActiveRecord::Column).to receive(:new).with(:title).
14
14
  and_return(column)
15
15
 
16
16
  ThinkingSphinx::RealTime::Field.new :title
@@ -20,11 +20,11 @@ describe ThinkingSphinx::RealTime::Field do
20
20
  describe '#name' do
21
21
  it "uses the provided option by default" do
22
22
  field = ThinkingSphinx::RealTime::Field.new column, :as => :foo
23
- field.name.should == 'foo'
23
+ expect(field.name).to eq('foo')
24
24
  end
25
25
 
26
26
  it "falls back to the column's name" do
27
- field.name.should == 'created_at'
27
+ expect(field.name).to eq('created_at')
28
28
  end
29
29
  end
30
30
 
@@ -34,34 +34,34 @@ describe ThinkingSphinx::RealTime::Field do
34
34
  let(:parent) { klass.new 'the parent name', nil }
35
35
 
36
36
  it "returns the column's name if it's a string" do
37
- column.stub :__name => 'value'
37
+ allow(column).to receive_messages :__name => 'value'
38
38
 
39
- field.translate(object).should == 'value'
39
+ expect(field.translate(object)).to eq('value')
40
40
  end
41
41
 
42
42
  it "returns the column's name as a string if it's an integer" do
43
- column.stub :__name => 404
43
+ allow(column).to receive_messages :__name => 404
44
44
 
45
- field.translate(object).should == '404'
45
+ expect(field.translate(object)).to eq('404')
46
46
  end
47
47
 
48
48
  it "returns the object's method matching the column's name" do
49
- object.stub :created_at => 'a time'
49
+ allow(object).to receive_messages :created_at => 'a time'
50
50
 
51
- field.translate(object).should == 'a time'
51
+ expect(field.translate(object)).to eq('a time')
52
52
  end
53
53
 
54
54
  it "uses the column's stack to navigate through the object tree" do
55
- column.stub :__name => :name, :__stack => [:parent]
55
+ allow(column).to receive_messages :__name => :name, :__stack => [:parent]
56
56
 
57
- field.translate(object).should == 'the parent name'
57
+ expect(field.translate(object)).to eq('the parent name')
58
58
  end
59
59
 
60
60
  it "returns a blank string if any element in the object tree is nil" do
61
- column.stub :__name => :name, :__stack => [:parent]
61
+ allow(column).to receive_messages :__name => :name, :__stack => [:parent]
62
62
  object.parent = nil
63
63
 
64
- field.translate(object).should == ''
64
+ expect(field.translate(object)).to eq('')
65
65
  end
66
66
  end
67
67
  end
@@ -2,46 +2,45 @@ require 'spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::RealTime::Index do
4
4
  let(:index) { ThinkingSphinx::RealTime::Index.new :user }
5
- let(:indices_path) { double('indices path', :join => '') }
6
5
  let(:config) { double('config', :settings => {},
7
- :indices_location => indices_path, :next_offset => 8) }
6
+ :indices_location => 'location', :next_offset => 8) }
8
7
 
9
8
  before :each do
10
- ThinkingSphinx::Configuration.stub :instance => config
9
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
11
10
  end
12
11
 
13
12
  describe '#attributes' do
14
13
  it "has the internal id attribute by default" do
15
- index.attributes.collect(&:name).should include('sphinx_internal_id')
14
+ expect(index.attributes.collect(&:name)).to include('sphinx_internal_id')
16
15
  end
17
16
 
18
17
  it "has the class name attribute by default" do
19
- index.attributes.collect(&:name).should include('sphinx_internal_class')
18
+ expect(index.attributes.collect(&:name)).to include('sphinx_internal_class')
20
19
  end
21
20
 
22
21
  it "has the internal deleted attribute by default" do
23
- index.attributes.collect(&:name).should include('sphinx_deleted')
22
+ expect(index.attributes.collect(&:name)).to include('sphinx_deleted')
24
23
  end
25
24
  end
26
25
 
27
26
  describe '#delta?' do
28
27
  it "always returns false" do
29
- index.should_not be_delta
28
+ expect(index).not_to be_delta
30
29
  end
31
30
  end
32
31
 
33
32
  describe '#document_id_for_key' do
34
33
  it "calculates the document id based on offset and number of indices" do
35
- config.stub_chain(:indices, :count).and_return(5)
36
- config.stub :next_offset => 7
34
+ allow(config).to receive_message_chain(:indices, :count).and_return(5)
35
+ allow(config).to receive_messages :next_offset => 7
37
36
 
38
- index.document_id_for_key(123).should == 622
37
+ expect(index.document_id_for_key(123)).to eq(622)
39
38
  end
40
39
  end
41
40
 
42
41
  describe '#fields' do
43
42
  it "has the internal class field by default" do
44
- index.fields.collect(&:name).should include('sphinx_internal_class_name')
43
+ expect(index.fields.collect(&:name)).to include('sphinx_internal_class_name')
45
44
  end
46
45
  end
47
46
 
@@ -53,14 +52,14 @@ describe ThinkingSphinx::RealTime::Index do
53
52
  end
54
53
 
55
54
  it "interprets the definition block" do
56
- ThinkingSphinx::RealTime::Interpreter.should_receive(:translate!).
55
+ expect(ThinkingSphinx::RealTime::Interpreter).to receive(:translate!).
57
56
  with(index, block)
58
57
 
59
58
  index.interpret_definition!
60
59
  end
61
60
 
62
61
  it "only interprets the definition block once" do
63
- ThinkingSphinx::RealTime::Interpreter.should_receive(:translate!).
62
+ expect(ThinkingSphinx::RealTime::Interpreter).to receive(:translate!).
64
63
  once
65
64
 
66
65
  index.interpret_definition!
@@ -72,13 +71,13 @@ describe ThinkingSphinx::RealTime::Index do
72
71
  let(:model) { double('model') }
73
72
 
74
73
  it "translates symbol references to model class" do
75
- ActiveSupport::Inflector.stub(:constantize => model)
74
+ allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
76
75
 
77
- index.model.should == model
76
+ expect(index.model).to eq(model)
78
77
  end
79
78
 
80
79
  it "memoizes the result" do
81
- ActiveSupport::Inflector.should_receive(:constantize).with('User').once.
80
+ expect(ActiveSupport::Inflector).to receive(:constantize).with('User').once.
82
81
  and_return(model)
83
82
 
84
83
  index.model
@@ -88,7 +87,7 @@ describe ThinkingSphinx::RealTime::Index do
88
87
 
89
88
  describe '#morphology' do
90
89
  before :each do
91
- pending
90
+ skip
92
91
  end
93
92
 
94
93
  context 'with a render' do
@@ -98,7 +97,7 @@ describe ThinkingSphinx::RealTime::Index do
98
97
  rescue Riddle::Configuration::ConfigurationError
99
98
  end
100
99
 
101
- index.morphology.should be_nil
100
+ expect(index.morphology).to be_nil
102
101
  end
103
102
 
104
103
  it "reads from the settings file if provided" do
@@ -109,7 +108,7 @@ describe ThinkingSphinx::RealTime::Index do
109
108
  rescue Riddle::Configuration::ConfigurationError
110
109
  end
111
110
 
112
- index.morphology.should == 'stem_en'
111
+ expect(index.morphology).to eq('stem_en')
113
112
  end
114
113
  end
115
114
  end
@@ -117,21 +116,21 @@ describe ThinkingSphinx::RealTime::Index do
117
116
  describe '#name' do
118
117
  it "always uses the core suffix" do
119
118
  index = ThinkingSphinx::RealTime::Index.new :user
120
- index.name.should == 'user_core'
119
+ expect(index.name).to eq('user_core')
121
120
  end
122
121
  end
123
122
 
124
123
  describe '#offset' do
125
124
  before :each do
126
- config.stub :next_offset => 4
125
+ allow(config).to receive_messages :next_offset => 4
127
126
  end
128
127
 
129
128
  it "uses the next offset value from the configuration" do
130
- index.offset.should == 4
129
+ expect(index.offset).to eq(4)
131
130
  end
132
131
 
133
132
  it "uses the reference to get a unique offset" do
134
- config.should_receive(:next_offset).with(:user).and_return(2)
133
+ expect(config).to receive(:next_offset).with(:user).and_return(2)
135
134
 
136
135
  index.offset
137
136
  end
@@ -139,11 +138,11 @@ describe ThinkingSphinx::RealTime::Index do
139
138
 
140
139
  describe '#render' do
141
140
  before :each do
142
- FileUtils.stub :mkdir_p => true
141
+ allow(FileUtils).to receive_messages :mkdir_p => true
143
142
  end
144
143
 
145
144
  it "interprets the provided definition" do
146
- index.should_receive(:interpret_definition!).at_least(:once)
145
+ expect(index).to receive(:interpret_definition!).at_least(:once)
147
146
 
148
147
  begin
149
148
  index.render
@@ -157,23 +156,23 @@ describe ThinkingSphinx::RealTime::Index do
157
156
  let(:model) { double('model') }
158
157
 
159
158
  it "returns the model by default" do
160
- ActiveSupport::Inflector.stub(:constantize => model)
159
+ allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
161
160
 
162
- index.scope.should == model
161
+ expect(index.scope).to eq(model)
163
162
  end
164
163
 
165
164
  it "returns the evaluated scope if provided" do
166
165
  index.scope = lambda { :foo }
167
166
 
168
- index.scope.should == :foo
167
+ expect(index.scope).to eq(:foo)
169
168
  end
170
169
  end
171
170
 
172
171
  describe '#unique_attribute_names' do
173
172
  it "returns all attribute names" do
174
- index.unique_attribute_names.should == [
173
+ expect(index.unique_attribute_names).to eq([
175
174
  'sphinx_internal_id', 'sphinx_internal_class', 'sphinx_deleted'
176
- ]
175
+ ])
177
176
  end
178
177
  end
179
178
  end