sunspot 2.0.0 → 2.5.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 (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +10 -0
  7. data/lib/sunspot.rb +55 -17
  8. data/lib/sunspot/adapters.rb +68 -18
  9. data/lib/sunspot/batcher.rb +1 -1
  10. data/lib/sunspot/configuration.rb +4 -2
  11. data/lib/sunspot/data_extractor.rb +36 -6
  12. data/lib/sunspot/dsl.rb +4 -3
  13. data/lib/sunspot/dsl/adjustable.rb +2 -2
  14. data/lib/sunspot/dsl/field_query.rb +69 -16
  15. data/lib/sunspot/dsl/field_stats.rb +25 -0
  16. data/lib/sunspot/dsl/fields.rb +28 -8
  17. data/lib/sunspot/dsl/fulltext.rb +9 -1
  18. data/lib/sunspot/dsl/group.rb +118 -0
  19. data/lib/sunspot/dsl/paginatable.rb +4 -1
  20. data/lib/sunspot/dsl/scope.rb +19 -10
  21. data/lib/sunspot/dsl/search.rb +1 -1
  22. data/lib/sunspot/dsl/spellcheckable.rb +14 -0
  23. data/lib/sunspot/dsl/standard_query.rb +63 -35
  24. data/lib/sunspot/field.rb +76 -4
  25. data/lib/sunspot/field_factory.rb +60 -11
  26. data/lib/sunspot/indexer.rb +70 -18
  27. data/lib/sunspot/query.rb +5 -4
  28. data/lib/sunspot/query/abstract_field_facet.rb +0 -2
  29. data/lib/sunspot/query/abstract_fulltext.rb +76 -0
  30. data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
  31. data/lib/sunspot/query/bbox.rb +5 -1
  32. data/lib/sunspot/query/common_query.rb +31 -6
  33. data/lib/sunspot/query/composite_fulltext.rb +58 -8
  34. data/lib/sunspot/query/date_field_json_facet.rb +25 -0
  35. data/lib/sunspot/query/dismax.rb +25 -71
  36. data/lib/sunspot/query/field_json_facet.rb +19 -0
  37. data/lib/sunspot/query/field_list.rb +15 -0
  38. data/lib/sunspot/query/field_stats.rb +61 -0
  39. data/lib/sunspot/query/function_query.rb +1 -2
  40. data/lib/sunspot/query/geo.rb +1 -1
  41. data/lib/sunspot/query/geofilt.rb +8 -3
  42. data/lib/sunspot/query/group.rb +46 -0
  43. data/lib/sunspot/query/group_query.rb +17 -0
  44. data/lib/sunspot/query/join.rb +88 -0
  45. data/lib/sunspot/query/more_like_this.rb +1 -1
  46. data/lib/sunspot/query/pagination.rb +12 -4
  47. data/lib/sunspot/query/range_json_facet.rb +28 -0
  48. data/lib/sunspot/query/restriction.rb +99 -13
  49. data/lib/sunspot/query/sort.rb +41 -0
  50. data/lib/sunspot/query/sort_composite.rb +7 -0
  51. data/lib/sunspot/query/spellcheck.rb +19 -0
  52. data/lib/sunspot/query/standard_query.rb +24 -2
  53. data/lib/sunspot/query/text_field_boost.rb +1 -3
  54. data/lib/sunspot/schema.rb +12 -3
  55. data/lib/sunspot/search.rb +4 -2
  56. data/lib/sunspot/search/abstract_search.rb +93 -43
  57. data/lib/sunspot/search/cursor_paginated_collection.rb +32 -0
  58. data/lib/sunspot/search/field_facet.rb +4 -4
  59. data/lib/sunspot/search/field_json_facet.rb +33 -0
  60. data/lib/sunspot/search/field_stats.rb +21 -0
  61. data/lib/sunspot/search/hit.rb +6 -1
  62. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  63. data/lib/sunspot/search/json_facet_row.rb +40 -0
  64. data/lib/sunspot/search/json_facet_stats.rb +23 -0
  65. data/lib/sunspot/search/paginated_collection.rb +1 -0
  66. data/lib/sunspot/search/query_group.rb +74 -0
  67. data/lib/sunspot/search/standard_search.rb +70 -3
  68. data/lib/sunspot/search/stats_facet.rb +25 -0
  69. data/lib/sunspot/search/stats_json_row.rb +82 -0
  70. data/lib/sunspot/search/stats_row.rb +68 -0
  71. data/lib/sunspot/session.rb +62 -37
  72. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
  73. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
  74. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +2 -2
  75. data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +1 -1
  76. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +4 -2
  77. data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +1 -1
  78. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +6 -4
  79. data/lib/sunspot/setup.rb +42 -0
  80. data/lib/sunspot/type.rb +20 -0
  81. data/lib/sunspot/util.rb +78 -14
  82. data/lib/sunspot/version.rb +1 -1
  83. data/spec/api/adapters_spec.rb +40 -15
  84. data/spec/api/batcher_spec.rb +15 -15
  85. data/spec/api/binding_spec.rb +3 -3
  86. data/spec/api/class_set_spec.rb +6 -6
  87. data/spec/api/data_extractor_spec.rb +39 -0
  88. data/spec/api/hit_enumerable_spec.rb +32 -9
  89. data/spec/api/indexer/attributes_spec.rb +35 -30
  90. data/spec/api/indexer/batch_spec.rb +8 -7
  91. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  92. data/spec/api/indexer/fixed_fields_spec.rb +16 -11
  93. data/spec/api/indexer/fulltext_spec.rb +8 -8
  94. data/spec/api/indexer/removal_spec.rb +24 -14
  95. data/spec/api/indexer_spec.rb +2 -2
  96. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  97. data/spec/api/query/connectives_examples.rb +26 -14
  98. data/spec/api/query/dsl_spec.rb +24 -6
  99. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  100. data/spec/api/query/faceting_examples.rb +80 -61
  101. data/spec/api/query/fulltext_examples.rb +194 -40
  102. data/spec/api/query/function_spec.rb +116 -13
  103. data/spec/api/query/geo_examples.rb +8 -12
  104. data/spec/api/query/group_spec.rb +27 -5
  105. data/spec/api/query/highlighting_examples.rb +26 -26
  106. data/spec/api/query/join_spec.rb +19 -0
  107. data/spec/api/query/more_like_this_spec.rb +40 -27
  108. data/spec/api/query/ordering_pagination_examples.rb +37 -23
  109. data/spec/api/query/scope_examples.rb +39 -39
  110. data/spec/api/query/spatial_examples.rb +3 -3
  111. data/spec/api/query/spellcheck_examples.rb +20 -0
  112. data/spec/api/query/standard_spec.rb +3 -1
  113. data/spec/api/query/stats_examples.rb +66 -0
  114. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  115. data/spec/api/query/types_spec.rb +4 -4
  116. data/spec/api/search/cursor_paginated_collection_spec.rb +35 -0
  117. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  118. data/spec/api/search/faceting_spec.rb +55 -52
  119. data/spec/api/search/highlighting_spec.rb +7 -7
  120. data/spec/api/search/hits_spec.rb +43 -29
  121. data/spec/api/search/paginated_collection_spec.rb +19 -18
  122. data/spec/api/search/results_spec.rb +13 -13
  123. data/spec/api/search/search_spec.rb +3 -3
  124. data/spec/api/search/stats_spec.rb +94 -0
  125. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +23 -16
  126. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +16 -4
  127. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  128. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +11 -11
  129. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +15 -14
  130. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +3 -3
  131. data/spec/api/session_proxy/spec_helper.rb +1 -1
  132. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +40 -26
  133. data/spec/api/session_spec.rb +78 -38
  134. data/spec/api/sunspot_spec.rb +7 -4
  135. data/spec/helpers/integration_helper.rb +11 -1
  136. data/spec/helpers/query_helper.rb +1 -1
  137. data/spec/helpers/search_helper.rb +30 -0
  138. data/spec/integration/atomic_updates_spec.rb +58 -0
  139. data/spec/integration/dynamic_fields_spec.rb +31 -20
  140. data/spec/integration/faceting_spec.rb +252 -39
  141. data/spec/integration/field_grouping_spec.rb +47 -15
  142. data/spec/integration/field_lists_spec.rb +57 -0
  143. data/spec/integration/geospatial_spec.rb +34 -8
  144. data/spec/integration/highlighting_spec.rb +8 -8
  145. data/spec/integration/indexing_spec.rb +7 -6
  146. data/spec/integration/join_spec.rb +45 -0
  147. data/spec/integration/keyword_search_spec.rb +68 -38
  148. data/spec/integration/local_search_spec.rb +4 -4
  149. data/spec/integration/more_like_this_spec.rb +7 -7
  150. data/spec/integration/scoped_search_spec.rb +193 -74
  151. data/spec/integration/spellcheck_spec.rb +119 -0
  152. data/spec/integration/stats_spec.rb +88 -0
  153. data/spec/integration/stored_fields_spec.rb +1 -1
  154. data/spec/integration/test_pagination.rb +4 -4
  155. data/spec/integration/unicode_spec.rb +1 -1
  156. data/spec/mocks/adapters.rb +36 -0
  157. data/spec/mocks/connection.rb +5 -3
  158. data/spec/mocks/photo.rb +32 -1
  159. data/spec/mocks/post.rb +18 -3
  160. data/spec/spec_helper.rb +13 -8
  161. data/sunspot.gemspec +6 -4
  162. data/tasks/rdoc.rake +22 -14
  163. metadata +101 -44
  164. data/lib/sunspot/dsl/field_group.rb +0 -57
  165. data/lib/sunspot/query/field_group.rb +0 -37
data/lib/sunspot/type.rb CHANGED
@@ -375,6 +375,26 @@ module Sunspot
375
375
  end
376
376
  end
377
377
 
378
+ class DateRangeType < DateType
379
+ def indexed_name(name)
380
+ "#{name}_dr"
381
+ end
382
+
383
+ def to_indexed(value)
384
+ if value.respond_to?(:first) && value.respond_to?(:last)
385
+ "[#{super value.first} TO #{super value.last}]"
386
+ else
387
+ super value
388
+ end
389
+ end
390
+
391
+ def cast(value)
392
+ return super unless m = value.match(/^\[(?<start>.+) TO (?<end>.+)\]$/)
393
+ Range.new super(m[:start]), super(m[:end])
394
+ end
395
+ end
396
+ register DateRangeType, Range
397
+
378
398
  class ClassType < AbstractType
379
399
  def indexed_name(name) #:nodoc:
380
400
  'class_name'
data/lib/sunspot/util.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  module Sunspot
2
- #
2
+ #
3
3
  # The Sunspot::Util module provides utility methods used elsewhere in the
4
4
  # library.
5
5
  #
6
6
  module Util #:nodoc:
7
7
  class <<self
8
- #
8
+ #
9
9
  # Get all of the superclasses for a given class, including the class
10
10
  # itself.
11
- #
11
+ #
12
12
  # ==== Parameters
13
13
  #
14
14
  # clazz<Class>:: class for which to get superclasses
@@ -23,7 +23,7 @@ module Sunspot
23
23
  superclasses
24
24
  end
25
25
 
26
- #
26
+ #
27
27
  # Convert a string to snake case
28
28
  #
29
29
  # ==== Parameters
@@ -38,7 +38,7 @@ module Sunspot
38
38
  string.scan(/(^|[A-Z])([^A-Z]+)/).map! { |word| word.join.downcase }.join('_')
39
39
  end
40
40
 
41
- #
41
+ #
42
42
  # Convert a string to camel case
43
43
  #
44
44
  # ==== Parameters
@@ -53,7 +53,23 @@ module Sunspot
53
53
  string.split('_').map! { |word| word.capitalize }.join
54
54
  end
55
55
 
56
- #
56
+ #
57
+ # Convert snake case string to method case (Java style)
58
+ #
59
+ # ==== Parameters
60
+ #
61
+ # string<String>:: String to convert to method case
62
+ #
63
+ # ==== Returns
64
+ #
65
+ # String:: String in method case
66
+ #
67
+ def method_case(string)
68
+ first = true
69
+ string.split('_').map! { |word| word = first ? word : word.capitalize; first = false; word }.join
70
+ end
71
+
72
+ #
57
73
  # Get a constant from a fully qualified name
58
74
  #
59
75
  # ==== Parameters
@@ -70,13 +86,13 @@ module Sunspot
70
86
  end
71
87
  end
72
88
 
73
- #
89
+ #
74
90
  # Evaluate the given proc in the context of the given object if the
75
91
  # block's arity is non-positive, or by passing the given object as an
76
92
  # argument if it is negative.
77
- #
93
+ #
78
94
  # ==== Parameters
79
- #
95
+ #
80
96
  # object<Object>:: Object to pass to the proc
81
97
  #
82
98
  def instance_eval_or_call(object, &block)
@@ -108,7 +124,7 @@ module Sunspot
108
124
  end
109
125
  end
110
126
 
111
- #
127
+ #
112
128
  # When generating boosts, Solr requires that the values be in standard
113
129
  # (not scientific) notation. We would like to ensure a minimum number of
114
130
  # significant digits (i.e., digits that are not prefix zeros) for small
@@ -122,7 +138,7 @@ module Sunspot
122
138
  end
123
139
  end
124
140
 
125
- #
141
+ #
126
142
  # Perform a deep merge of hashes, returning the result as a new hash.
127
143
  # See #deep_merge_into for rules used to merge the hashes
128
144
  #
@@ -139,7 +155,7 @@ module Sunspot
139
155
  deep_merge_into({}, left, right)
140
156
  end
141
157
 
142
- #
158
+ #
143
159
  # Perform a deep merge of the right hash into the left hash
144
160
  #
145
161
  # ==== Parameters
@@ -155,9 +171,49 @@ module Sunspot
155
171
  deep_merge_into(left, left, right)
156
172
  end
157
173
 
174
+ #
175
+ # Escapes characters for the Solr query parser
176
+ #
177
+ # ==== Parameters
178
+ #
179
+ # string<String>:: String to escape
180
+ #
181
+ # ==== Returns
182
+ #
183
+ # String:: escaped string
184
+ #
185
+ def escape(value)
186
+ # RSolr.solr_escape doesn't handle spaces or period chars,
187
+ # which do need to be escaped
188
+ RSolr.solr_escape(value).gsub(/([\s\.])/, '\\\\\1')
189
+ end
190
+
191
+ def parse_json_facet(field_name, options, setup)
192
+ field = setup.field(field_name)
193
+ if options[:time_range]
194
+ unless field.type.is_a?(Sunspot::Type::TimeType)
195
+ raise(
196
+ ArgumentError,
197
+ ':time_range can only be specified for Date or Time fields'
198
+ )
199
+ end
200
+ Sunspot::Query::DateFieldJsonFacet.new(field, options, setup)
201
+ elsif options[:range]
202
+ unless [Sunspot::Type::TimeType, Sunspot::Type::FloatType, Sunspot::Type::IntegerType ].find{|type| field.type.is_a?(type)}
203
+ raise(
204
+ ArgumentError,
205
+ ':range can only be specified for date or numeric fields'
206
+ )
207
+ end
208
+ Sunspot::Query::RangeJsonFacet.new(field, options, setup)
209
+ else
210
+ Sunspot::Query::FieldJsonFacet.new(field, options, setup)
211
+ end
212
+ end
213
+
158
214
  private
159
215
 
160
- #
216
+ #
161
217
  # Deep merge two hashes into a third hash, using rules that produce nice
162
218
  # merged parameter hashes. The rules are as follows, for a given key:
163
219
  #
@@ -224,7 +280,15 @@ module Sunspot
224
280
  end
225
281
 
226
282
  def id
227
- @__calling_context__.__send__(:id)
283
+ begin
284
+ @__calling_context__.__send__(:id)
285
+ rescue ::NoMethodError => e
286
+ begin
287
+ @__receiver__.__send__(:id)
288
+ rescue ::NoMethodError
289
+ raise(e)
290
+ end
291
+ end
228
292
  end
229
293
 
230
294
  # Special case due to `Kernel#sub`'s existence
@@ -1,3 +1,3 @@
1
1
  module Sunspot
2
- VERSION = '2.0.0'
2
+ VERSION = '2.5.0'
3
3
  end
@@ -2,33 +2,58 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Sunspot::Adapters::InstanceAdapter do
4
4
  it "finds adapter by superclass" do
5
- Sunspot::Adapters::InstanceAdapter::for(Model).should be(AbstractModelInstanceAdapter)
5
+ expect(Sunspot::Adapters::InstanceAdapter::for(Model)).to be(AbstractModelInstanceAdapter)
6
6
  end
7
7
 
8
8
  it "finds adapter by mixin" do
9
- Sunspot::Adapters::InstanceAdapter::for(MixModel).should be(MixInModelInstanceAdapter)
9
+ expect(Sunspot::Adapters::InstanceAdapter::for(MixModel)).to be(MixInModelInstanceAdapter)
10
10
  end
11
11
 
12
12
  it 'throws NoAdapterError if anonymous module passed in' do
13
- lambda do
13
+ expect do
14
14
  Sunspot::Adapters::InstanceAdapter::for(Module.new)
15
- end.should raise_error(Sunspot::NoAdapterError)
15
+ end.to raise_error(Sunspot::NoAdapterError)
16
+ end
17
+
18
+ it "registers adapters found by ancestor lookup with the descendant class" do
19
+ expect(Sunspot::Adapters::InstanceAdapter::registered_adapter_for(UnseenModel)).to be(nil)
20
+ Sunspot::Adapters::InstanceAdapter::for(UnseenModel)
21
+ expect(Sunspot::Adapters::InstanceAdapter::registered_adapter_for(UnseenModel)).to be(AbstractModelInstanceAdapter)
22
+ end
23
+
24
+ it "appends ID prefix when configured" do
25
+ expect(AbstractModelInstanceAdapter.new(ModelWithPrefixId.new).index_id).to eq "USERDATA!ModelWithPrefixId 1"
26
+ end
27
+
28
+ it "supports nested ID prefixes" do
29
+ expect(AbstractModelInstanceAdapter.
30
+ new(ModelWithNestedPrefixId.new).index_id).to eq "USER!USERDATA!ModelWithNestedPrefixId 1"
31
+ end
32
+
33
+ it "doesn't appends ID prefix when not configured" do
34
+ expect(AbstractModelInstanceAdapter.new(ModelWithoutPrefixId.new).index_id).to eq "ModelWithoutPrefixId 1"
16
35
  end
17
36
  end
18
37
 
19
38
  describe Sunspot::Adapters::DataAccessor do
20
39
  it "finds adapter by superclass" do
21
- Sunspot::Adapters::DataAccessor::for(Model).should be(AbstractModelDataAccessor)
40
+ expect(Sunspot::Adapters::DataAccessor::for(Model)).to be(AbstractModelDataAccessor)
22
41
  end
23
42
 
24
43
  it "finds adapter by mixin" do
25
- Sunspot::Adapters::DataAccessor::for(MixModel).should be(MixInModelDataAccessor)
44
+ expect(Sunspot::Adapters::DataAccessor::for(MixModel)).to be(MixInModelDataAccessor)
26
45
  end
27
46
 
28
47
  it 'throws NoAdapterError if anonymous module passed in' do
29
- lambda do
48
+ expect do
30
49
  Sunspot::Adapters::DataAccessor::for(Module.new)
31
- end.should raise_error(Sunspot::NoAdapterError)
50
+ end.to raise_error(Sunspot::NoAdapterError)
51
+ end
52
+
53
+ it "registers adapters found by ancestor lookup with the descendant class" do
54
+ expect(Sunspot::Adapters::DataAccessor::registered_accessor_for(UnseenModel)).to be(nil)
55
+ Sunspot::Adapters::DataAccessor::for(UnseenModel)
56
+ expect(Sunspot::Adapters::DataAccessor::registered_accessor_for(UnseenModel)).to be(AbstractModelDataAccessor)
32
57
  end
33
58
  end
34
59
 
@@ -39,30 +64,30 @@ describe Sunspot::Adapters::Registry do
39
64
  let(:mixin_accessor){ Sunspot::Adapters::DataAccessor::for(MixModel) }
40
65
 
41
66
  it "registers and retrieves a data accessor for abstractclass" do
42
- registry.retrieve(AbstractModel).should be_a(abstractclass_accessor)
67
+ expect(registry.retrieve(AbstractModel)).to be_a(abstractclass_accessor)
43
68
  end
44
69
 
45
70
  it "registers and retrieves a data accessor for superclass" do
46
- registry.retrieve(Model).should be_a(superclass_accessor)
71
+ expect(registry.retrieve(Model)).to be_a(superclass_accessor)
47
72
  end
48
73
 
49
74
  it "registers and retrieves a data accessor for mixin" do
50
- registry.retrieve(MixModel).should be_a(mixin_accessor)
75
+ expect(registry.retrieve(MixModel)).to be_a(mixin_accessor)
51
76
  end
52
77
 
53
78
  it "injects inherited attributes" do
54
- AbstractModelDataAccessor.any_instance.stub(:inherited_attributes).and_return([:to_be_injected])
79
+ allow_any_instance_of(AbstractModelDataAccessor).to receive(:inherited_attributes).and_return([:to_be_injected])
55
80
  in_registry_data_accessor = registry.retrieve(AbstractModel)
56
81
  in_registry_data_accessor.to_be_injected = "value"
57
- registry.retrieve(Model).to_be_injected.should == "value"
82
+ expect(registry.retrieve(Model).to_be_injected).to eq("value")
58
83
  end
59
84
 
60
85
  it "not overrides inherited attributes" do
61
- AbstractModelDataAccessor.any_instance.stub(:inherited_attributes).and_return([:to_be_injected])
86
+ allow_any_instance_of(AbstractModelDataAccessor).to receive(:inherited_attributes).and_return([:to_be_injected])
62
87
  parent_data_accessor = registry.retrieve(AbstractModel)
63
88
  current_data_accessor = registry.retrieve(Model)
64
89
  parent_data_accessor.to_be_injected = "value"
65
90
  current_data_accessor.to_be_injected = "safe-value"
66
- registry.retrieve(Model).to_be_injected.should == "safe-value"
91
+ expect(registry.retrieve(Model).to_be_injected).to eq("safe-value")
67
92
  end
68
93
  end
@@ -2,12 +2,12 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Sunspot::Batcher do
4
4
  it "includes Enumerable" do
5
- described_class.should include Enumerable
5
+ expect(described_class).to include Enumerable
6
6
  end
7
7
 
8
8
  describe "#each" do
9
9
  let(:current) { [:foo, :bar] }
10
- before { subject.stub(:current).and_return current }
10
+ before { allow(subject).to receive(:current).and_return current }
11
11
 
12
12
  it "iterates over current" do
13
13
  yielded_values = []
@@ -16,25 +16,25 @@ describe Sunspot::Batcher do
16
16
  yielded_values << value
17
17
  end
18
18
 
19
- yielded_values.should eq current
19
+ expect(yielded_values).to eq current
20
20
  end
21
21
  end
22
22
 
23
23
  describe "adding to current batch" do
24
24
  it "#push pushes to current" do
25
25
  subject.push :foo
26
- subject.current.should include :foo
26
+ expect(subject.current).to include :foo
27
27
  end
28
28
 
29
29
  it "#<< pushes to current" do
30
30
  subject.push :foo
31
- subject.current.should include :foo
31
+ expect(subject.current).to include :foo
32
32
  end
33
33
 
34
34
  it "#concat concatinates on current batch" do
35
35
  subject << :foo
36
36
  subject.concat [:bar, :mix]
37
- should include :foo, :bar, :mix
37
+ is_expected.to include :foo, :bar, :mix
38
38
  end
39
39
  end
40
40
 
@@ -46,7 +46,7 @@ describe Sunspot::Batcher do
46
46
  end
47
47
 
48
48
  it "is empty by default" do
49
- subject.current.should be_empty
49
+ expect(subject.current).to be_empty
50
50
  end
51
51
  end
52
52
 
@@ -58,7 +58,7 @@ describe Sunspot::Batcher do
58
58
  end
59
59
 
60
60
  it "returns the same as last time" do
61
- subject.current.should eq subject.current
61
+ expect(subject.current).to eq subject.current
62
62
  end
63
63
  end
64
64
  end
@@ -71,7 +71,7 @@ describe Sunspot::Batcher do
71
71
  it "changes current" do
72
72
  subject << :foo
73
73
  subject.start_new
74
- should_not include :foo
74
+ is_expected.not_to include :foo
75
75
  end
76
76
  end
77
77
 
@@ -88,25 +88,25 @@ describe Sunspot::Batcher do
88
88
  it "changes current" do
89
89
  subject << :foo
90
90
  subject.end_current
91
- should_not include :foo
91
+ is_expected.not_to include :foo
92
92
  end
93
93
 
94
94
  it "returns current" do
95
95
  subject << :foo
96
- subject.end_current.should include :foo
96
+ expect(subject.end_current).to include :foo
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
101
  describe "#batching?" do
102
102
  it "is false when depth is 0" do
103
- subject.should_receive(:depth).and_return 0
104
- should_not be_batching
103
+ expect(subject).to receive(:depth).and_return 0
104
+ is_expected.not_to be_batching
105
105
  end
106
106
 
107
107
  it "is true when depth is more than 0" do
108
- subject.should_receive(:depth).and_return 1
109
- should be_batching
108
+ expect(subject).to receive(:depth).and_return 1
109
+ is_expected.to be_batching
110
110
  end
111
111
  end
112
112
  end
@@ -6,7 +6,7 @@ describe "DSL bindings" do
6
6
  session.search(Post) do
7
7
  value = test_method
8
8
  end
9
- value.should == 'value'
9
+ expect(value).to eq('value')
10
10
  end
11
11
 
12
12
  it 'should give access to calling context\'s id method in search DSL' do
@@ -14,7 +14,7 @@ describe "DSL bindings" do
14
14
  session.search(Post) do
15
15
  value = id
16
16
  end
17
- value.should == 16
17
+ expect(value).to eq(16)
18
18
  end
19
19
 
20
20
  it 'should give access to calling context\'s methods in nested DSL block' do
@@ -24,7 +24,7 @@ describe "DSL bindings" do
24
24
  value = test_method
25
25
  end
26
26
  end
27
- value.should == 'value'
27
+ expect(value).to eq('value')
28
28
  end
29
29
 
30
30
  it 'should give access to calling context\'s methods in double-nested DSL block' do
@@ -2,23 +2,23 @@ require "spec_helper"
2
2
 
3
3
  describe Sunspot::ClassSet do
4
4
  it "is enumerable" do
5
- class1, class2 = stub(:name => "Class1"), stub(:name => "Class2")
5
+ class1, class2 = double(:name => "Class1"), double(:name => "Class2")
6
6
 
7
7
  set = described_class.new
8
8
  set << class1 << class2
9
9
 
10
- set.to_a.should =~ [class1, class2]
10
+ expect(set.to_a).to match_array([class1, class2])
11
11
  end
12
12
 
13
13
  it "replaces classes with the same name" do
14
14
  set = described_class.new
15
15
 
16
- class1 = stub(:name => "Class1")
16
+ class1 = double(:name => "Class1")
17
17
  set << class1
18
- set.to_a.should == [class1]
18
+ expect(set.to_a).to eq([class1])
19
19
 
20
- class1_dup = stub(:name => "Class1")
20
+ class1_dup = double(:name => "Class1")
21
21
  set << class1_dup
22
- set.to_a.should == [class1_dup]
22
+ expect(set.to_a).to eq([class1_dup])
23
23
  end
24
24
  end