sunspot_rails 2.2.0 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e0ce283378203c1a9f3bdccf1670ee3f10ff7e55
4
+ data.tar.gz: 9c888704f1b8150db2ec3f3f2c8f18caabb3b051
5
+ SHA512:
6
+ metadata.gz: 630ae3479120da9bc341c3a6b4a0bd5c170c44bbab0b00329901f871344ec07f59834c6d8b7dee519f7145b7478705a6c65391c9a91179da9a673e87871dba8d
7
+ data.tar.gz: 6b8d86ad3397a93422b5eb67401aa682ebf2a498c7bef90e45d8eadf0479ff0a7839402f1555ed02b8c96d6260ec16d0a44a2e2ec8628ae0691674eabef0aad6
@@ -8,12 +8,14 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
12
+ gem 'test-unit', '~> 3.2.0' if RUBY_VERSION >= '2.2.0'
11
13
  end
12
14
 
13
15
  group :postgres do
14
- gem 'pg'
16
+ gem 'pg'
15
17
  end
16
18
 
17
19
  group :sqlite do
18
- gem 'sqlite3', '~> 1.3.7'
19
- end
20
+ gem 'sqlite3', '~> 1.3.7'
21
+ end
@@ -8,12 +8,14 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
12
+ gem 'test-unit', '~> 3.2.0' if RUBY_VERSION >= '2.2.0'
11
13
  end
12
14
 
13
15
  group :postgres do
14
- gem 'pg'
16
+ gem 'pg'
15
17
  end
16
18
 
17
19
  group :sqlite do
18
- gem 'sqlite3', '~> 1.3.7'
19
- end
20
+ gem 'sqlite3', '~> 1.3.7'
21
+ end
@@ -8,12 +8,14 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
12
+ gem 'test-unit', '~> 3.2.0' if RUBY_VERSION >= '2.2.0'
11
13
  end
12
14
 
13
15
  group :postgres do
14
- gem 'pg'
16
+ gem 'pg'
15
17
  end
16
18
 
17
19
  group :sqlite do
18
- gem 'sqlite3', '~> 1.3.7'
19
- end
20
+ gem 'sqlite3', '~> 1.3.7'
21
+ end
@@ -1,20 +1,25 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 4.0.0'
4
+ if SystemRubyVersion.new.to_s =~ /1.9/
5
+ gem 'mime-types', '~> 2.99.0'
6
+ end
4
7
 
5
8
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
6
9
  gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
7
10
  gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
11
 
9
12
  group :test do
10
- gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
13
+ gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
11
14
  gem 'rspec-rails', '~> 2.14.0'
15
+ gem 'progress_bar', '~> 1.0.5', require: false
16
+ gem 'test-unit', '~> 3.2.0' if RUBY_VERSION >= '2.2.0'
12
17
  end
13
18
 
14
19
  group :postgres do
15
- gem 'pg'
20
+ gem 'pg'
16
21
  end
17
22
 
18
23
  group :sqlite do
19
- gem 'sqlite3', '~> 1.3.7'
20
- end
24
+ gem 'sqlite3', '~> 1.3.7'
25
+ end
@@ -0,0 +1,24 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.0'
4
+ if SystemRubyVersion.new.to_s =~ /1.9/
5
+ gem 'mime-types', '~> 2.99.0'
6
+ end
7
+
8
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
9
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
10
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
11
+
12
+ group :test do
13
+ gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
14
+ gem 'rspec-rails', '~> 2.14.0'
15
+ gem 'progress_bar', '~> 1.0.5', require: false
16
+ end
17
+
18
+ group :postgres do
19
+ gem 'pg'
20
+ end
21
+
22
+ group :sqlite do
23
+ gem 'sqlite3', '~> 1.3.7'
24
+ end
@@ -0,0 +1,24 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.2.0'
4
+ if SystemRubyVersion.new.to_s =~ /1.9/
5
+ gem 'mime-types', '~> 2.99.0'
6
+ end
7
+
8
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
9
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
10
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
11
+
12
+ group :test do
13
+ gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
14
+ gem 'rspec-rails', '~> 2.14.0'
15
+ gem 'progress_bar', '~> 1.0.5', require: false
16
+ end
17
+
18
+ group :postgres do
19
+ gem 'pg'
20
+ end
21
+
22
+ group :sqlite do
23
+ gem 'sqlite3', '~> 1.3.7'
24
+ end
@@ -52,6 +52,7 @@ module Sunspot #:nodoc:
52
52
  ).to_s
53
53
  config.solr.read_timeout = sunspot_rails_configuration.read_timeout
54
54
  config.solr.open_timeout = sunspot_rails_configuration.open_timeout
55
+ config.solr.proxy = sunspot_rails_configuration.proxy
55
56
  config
56
57
  end
57
58
 
@@ -66,6 +67,7 @@ module Sunspot #:nodoc:
66
67
  ).to_s
67
68
  config.solr.read_timeout = sunspot_rails_configuration.read_timeout
68
69
  config.solr.open_timeout = sunspot_rails_configuration.open_timeout
70
+ config.solr.proxy = sunspot_rails_configuration.proxy
69
71
  config
70
72
  end
71
73
  end
@@ -21,11 +21,12 @@ module Sunspot #:nodoc:
21
21
  class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
22
22
  # options for the find
23
23
  attr_accessor :include
24
+ attr_accessor :scopes
24
25
  attr_reader :select
25
26
 
26
27
  def initialize(clazz)
27
28
  super(clazz)
28
- @inherited_attributes = [:include, :select]
29
+ @inherited_attributes = [:include, :select, :scopes]
29
30
  end
30
31
 
31
32
  #
@@ -77,6 +78,9 @@ module Sunspot #:nodoc:
77
78
  scope = relation
78
79
  scope = scope.includes(@include) if @include.present?
79
80
  scope = scope.select(@select) if @select.present?
81
+ Array.wrap(@scopes).each do |s|
82
+ scope = scope.send(s)
83
+ end
80
84
  scope
81
85
  end
82
86
 
@@ -12,10 +12,10 @@ module Sunspot #:nodoc:
12
12
  # solr:
13
13
  # hostname: localhost
14
14
  # port: 8982
15
- # min_memory: 512M
16
- # max_memory: 1G
15
+ # memory: 1G
17
16
  # solr_jar: /some/path/solr15/start.jar
18
17
  # bind_address: 0.0.0.0
18
+ # proxy: false
19
19
  # disabled: false
20
20
  # test:
21
21
  # solr:
@@ -24,6 +24,7 @@ module Sunspot #:nodoc:
24
24
  # log_level: OFF
25
25
  # open_timeout: 0.5
26
26
  # read_timeout: 2
27
+ # proxy: false
27
28
  # production:
28
29
  # solr:
29
30
  # scheme: http
@@ -36,6 +37,7 @@ module Sunspot #:nodoc:
36
37
  # solr_home: /some/path
37
38
  # open_timeout: 0.5
38
39
  # read_timeout: 2
40
+ # proxy: http://proxy.com:12345
39
41
  # master_solr:
40
42
  # hostname: localhost
41
43
  # port: 8982
@@ -247,10 +249,6 @@ module Sunspot #:nodoc:
247
249
  @log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location )
248
250
  end
249
251
 
250
- def data_path
251
- @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
252
- end
253
-
254
252
  def pid_dir
255
253
  @pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
256
254
  end
@@ -277,22 +275,15 @@ module Sunspot #:nodoc:
277
275
  #
278
276
  # Solr start jar
279
277
  #
280
- def solr_jar
281
- @solr_jar ||= user_configuration_from_key('solr', 'solr_jar')
282
- end
283
-
284
- #
285
- # Minimum java heap size for Solr instance
286
- #
287
- def min_memory
288
- @min_memory ||= user_configuration_from_key('solr', 'min_memory')
278
+ def solr_executable
279
+ @solr_executable ||= user_configuration_from_key('solr', 'solr_executable')
289
280
  end
290
281
 
291
282
  #
292
- # Maximum java heap size for Solr instance
283
+ # java heap size for Solr instance
293
284
  #
294
- def max_memory
295
- @max_memory ||= user_configuration_from_key('solr', 'max_memory')
285
+ def memory
286
+ @memory ||= user_configuration_from_key('solr', 'memory')
296
287
  end
297
288
 
298
289
  #
@@ -310,6 +301,10 @@ module Sunspot #:nodoc:
310
301
  @open_timeout ||= user_configuration_from_key('solr', 'open_timeout')
311
302
  end
312
303
 
304
+ def proxy
305
+ @proxy ||= user_configuration_from_key('solr', 'proxy')
306
+ end
307
+
313
308
  #
314
309
  # Whether or not to disable Solr.
315
310
  # Defaults to false.
@@ -134,6 +134,8 @@ module Sunspot #:nodoc:
134
134
  alias_method :index, :solr_index unless method_defined? :index
135
135
  alias_method :index_orphans, :solr_index_orphans unless method_defined? :index_orphans
136
136
  alias_method :clean_index_orphans, :solr_clean_index_orphans unless method_defined? :clean_index_orphans
137
+ alias_method :atomic_update, :solr_atomic_update unless method_defined? :atomic_update
138
+ alias_method :atomic_update!, :solr_atomic_update! unless method_defined? :atomic_update!
137
139
  end
138
140
  end
139
141
  #
@@ -257,9 +259,9 @@ module Sunspot #:nodoc:
257
259
  if options[:batch_size].to_i > 0
258
260
  batch_counter = 0
259
261
  self.includes(options[:include]).find_in_batches(options.slice(:batch_size, :start)) do |records|
260
-
262
+
261
263
  solr_benchmark(options[:batch_size], batch_counter += 1) do
262
- Sunspot.index(records.select { |model| model.indexable? })
264
+ Sunspot.index(records.select(&:indexable?))
263
265
  Sunspot.commit if options[:batch_commit]
264
266
  end
265
267
 
@@ -273,6 +275,46 @@ module Sunspot #:nodoc:
273
275
  Sunspot.commit unless options[:batch_commit]
274
276
  end
275
277
 
278
+ #
279
+ # Update properties of existing records in the Solr index.
280
+ # Atomic updates available only for the stored properties.
281
+ #
282
+ # ==== Updates (passed as a hash)
283
+ #
284
+ # updates should be specified as a hash, where key - is the object ID
285
+ # and values is hash with property name/values to be updated.
286
+ #
287
+ # ==== Examples
288
+ #
289
+ # class Post < ActiveRecord::Base
290
+ # searchable do
291
+ # string :title, stored: true
292
+ # string :description, stored: true
293
+ # end
294
+ # end
295
+ #
296
+ # post1 = Post.create(title: 'A Title', description: nil)
297
+ #
298
+ # # update single property
299
+ # Post.atomic_update(post1.id => {description: 'New post description'})
300
+ #
301
+ # ==== Notice
302
+ # all non-stored properties in Solr index will be lost after update.
303
+ # Read Solr wiki page: https://wiki.apache.org/solr/Atomic_Updates
304
+ def solr_atomic_update(updates = {})
305
+ Sunspot.atomic_update(self, updates)
306
+ end
307
+
308
+ #
309
+ # Update properties of existing records in the Solr index atomically, and
310
+ # immediately commits.
311
+ #
312
+ # See #solr_atomic_update for information on options, etc.
313
+ #
314
+ def solr_atomic_update!(updates = {})
315
+ Sunspot.atomic_update!(self, updates)
316
+ end
317
+
276
318
  #
277
319
  # Return the IDs of records of this class that are indexed in Solr but
278
320
  # do not exist in the database. Under normal circumstances, this should
@@ -282,8 +324,7 @@ module Sunspot #:nodoc:
282
324
  #
283
325
  # ==== Options (passed as a hash)
284
326
  #
285
- # batch_size<Integer>:: Batch size with which to load records. Passing
286
- # Default is 1000 (from ActiveRecord).
327
+ # batch_size<Integer>:: Override default batch size with which to load records.
287
328
  #
288
329
  # ==== Returns
289
330
  #
@@ -294,7 +335,7 @@ module Sunspot #:nodoc:
294
335
  solr_page = 0
295
336
  solr_ids = []
296
337
  while (solr_page = solr_page.next)
297
- ids = solr_search_ids { paginate(:page => solr_page, :per_page => 1000) }.to_a
338
+ ids = solr_search_ids { paginate(:page => solr_page, :per_page => batch_size) }.to_a
298
339
  break if ids.empty?
299
340
  solr_ids.concat ids
300
341
  end
@@ -310,8 +351,7 @@ module Sunspot #:nodoc:
310
351
  #
311
352
  # ==== Options (passed as a hash)
312
353
  #
313
- # batch_size<Integer>:: Batch size with which to load records
314
- # Default is 50
354
+ # batch_size<Integer>:: Override default batch size with which to load records
315
355
  #
316
356
  def solr_clean_index_orphans(opts={})
317
357
  solr_index_orphans(opts).each do |id|
@@ -334,15 +374,15 @@ module Sunspot #:nodoc:
334
374
  end
335
375
 
336
376
  def solr_execute_search(options = {})
337
- options.assert_valid_keys(:include, :select)
377
+ inherited_attributes = [:include, :select, :scopes]
378
+ options.assert_valid_keys(*inherited_attributes)
338
379
  search = yield
339
380
  unless options.empty?
340
381
  search.build do |query|
341
- if options[:include]
342
- query.data_accessor_for(self).include = options[:include]
343
- end
344
- if options[:select]
345
- query.data_accessor_for(self).select = options[:select]
382
+ inherited_attributes.each do |attr|
383
+ if options[attr]
384
+ query.data_accessor_for(self).send("#{attr}=", options[attr])
385
+ end
346
386
  end
347
387
  end
348
388
  end
@@ -378,6 +418,8 @@ module Sunspot #:nodoc:
378
418
  alias_method :remove_from_index!, :solr_remove_from_index! unless method_defined? :remove_from_index!
379
419
  alias_method :more_like_this, :solr_more_like_this unless method_defined? :more_like_this
380
420
  alias_method :more_like_this_ids, :solr_more_like_this_ids unless method_defined? :more_like_this_ids
421
+ alias_method :atomic_update, :solr_atomic_update unless method_defined? :atomic_update
422
+ alias_method :atomic_update!, :solr_atomic_update! unless method_defined? :atomic_update!
381
423
  end
382
424
  end
383
425
  #
@@ -398,6 +440,23 @@ module Sunspot #:nodoc:
398
440
  def solr_index!
399
441
  Sunspot.index!(self)
400
442
  end
443
+
444
+ #
445
+ # Updates specified model properties in Solr.
446
+ # Unlike ClassMethods#solr_atomic_update you dont need to pass object id,
447
+ # you only need to pass hash with property changes
448
+ #
449
+ def solr_atomic_update(updates = {})
450
+ Sunspot.atomic_update(self.class, self.id => updates)
451
+ end
452
+
453
+ #
454
+ # Updates specified model properties in Solr and immediately commit.
455
+ # See #solr_atomic_update
456
+ #
457
+ def solr_atomic_update!(updates = {})
458
+ Sunspot.atomic_update!(self.class, self.id => updates)
459
+ end
401
460
 
402
461
  #
403
462
  # Remove the model from the Solr index. Using the defaults, this should
@@ -2,32 +2,21 @@ module Sunspot
2
2
  module Rails
3
3
  class Server < Sunspot::Solr::Server
4
4
 
5
- #
5
+ #
6
6
  # Directory in which to store PID files
7
7
  #
8
8
  def pid_dir
9
9
  configuration.pid_dir || File.join(::Rails.root, 'tmp', 'pids')
10
10
  end
11
11
 
12
- #
12
+ #
13
13
  # Name of the PID file
14
14
  #
15
15
  def pid_file
16
16
  "sunspot-solr-#{::Rails.env}.pid"
17
17
  end
18
18
 
19
- #
20
- # Directory to store lucene index data files
21
- #
22
- # ==== Returns
23
19
  #
24
- # String:: data_path
25
- #
26
- def solr_data_dir
27
- configuration.data_path
28
- end
29
-
30
- #
31
20
  # Directory to use for Solr home.
32
21
  #
33
22
  def solr_home
@@ -37,18 +26,18 @@ module Sunspot
37
26
  #
38
27
  # Solr start jar
39
28
  #
40
- def solr_jar
41
- configuration.solr_jar || super
29
+ def solr_executable
30
+ configuration.solr_executable || super
42
31
  end
43
32
 
44
- #
33
+ #
45
34
  # Address on which to run Solr
46
35
  #
47
36
  def bind_address
48
37
  configuration.bind_address
49
38
  end
50
39
 
51
- #
40
+ #
52
41
  # Port on which to run Solr
53
42
  #
54
43
  def port
@@ -59,25 +48,18 @@ module Sunspot
59
48
  configuration.log_level
60
49
  end
61
50
 
62
- #
51
+ #
63
52
  # Log file for Solr. File is in the rails log/ directory.
64
53
  #
65
54
  def log_file
66
55
  File.join(::Rails.root, 'log', "sunspot-solr-#{::Rails.env}.log")
67
56
  end
68
57
 
69
- #
70
- # Minimum Java heap size for Solr
71
58
  #
72
- def min_memory
73
- configuration.min_memory
74
- end
75
-
76
- #
77
- # Maximum Java heap size for Solr
59
+ # Java heap size for Solr
78
60
  #
79
- def max_memory
80
- configuration.max_memory
61
+ def memory
62
+ configuration.memory
81
63
  end
82
64
 
83
65
  private
@@ -17,6 +17,12 @@ module Sunspot
17
17
  def index!(*objects)
18
18
  end
19
19
 
20
+ def atomic_update(clazz, updates = {})
21
+ end
22
+
23
+ def atomic_update!(clazz, updates = {})
24
+ end
25
+
20
26
  def remove(*objects)
21
27
  end
22
28
 
@@ -110,6 +116,10 @@ module Sunspot
110
116
  DataAccessorStub.new
111
117
  end
112
118
 
119
+ def stats(name)
120
+ StatsStub.new
121
+ end
122
+
113
123
  def execute
114
124
  self
115
125
  end
@@ -148,6 +158,7 @@ module Sunspot
148
158
  def previous_page
149
159
  nil
150
160
  end
161
+ alias :prev_page :previous_page
151
162
 
152
163
  def next_page
153
164
  nil
@@ -171,6 +182,49 @@ module Sunspot
171
182
 
172
183
  end
173
184
 
185
+ class StatsStub
186
+ def min
187
+ 0
188
+ end
189
+
190
+ def max
191
+ 100
192
+ end
193
+
194
+ def count
195
+ 30
196
+ end
197
+
198
+ def sum
199
+ 500
200
+ end
201
+
202
+ def missing
203
+ 3
204
+ end
205
+
206
+ def sum_of_squares
207
+ 5000
208
+ end
209
+
210
+ def mean
211
+ 50
212
+ end
213
+
214
+ def standard_deviation
215
+ 20
216
+ end
217
+
218
+ def facets
219
+ []
220
+ end
221
+
222
+ def facet(name)
223
+ FacetStub.new
224
+ end
225
+
226
+ end
227
+
174
228
  end
175
229
  end
176
230
  end
@@ -49,6 +49,8 @@ namespace :sunspot do
49
49
  reindex_options[:progress_bar] = ProgressBar.new(total_documents)
50
50
  rescue LoadError => e
51
51
  $stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
52
+ rescue ProgressBar::ArgumentError => e
53
+ $stdout.puts "You have no data in the database. Reindexing does nothing here."
52
54
  rescue Exception => e
53
55
  $stderr.puts "Error using progress bar: #{e.message}"
54
56
  end unless args[:silence]
@@ -22,6 +22,10 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
22
22
  @config.userinfo.should be_nil
23
23
  end
24
24
 
25
+ it "should not set a proxy" do
26
+ @config.proxy.should be_nil
27
+ end
28
+
25
29
  describe "port" do
26
30
  it "should default to port 8981 in test" do
27
31
  ::Rails.stub(:env => 'test')
@@ -67,11 +71,6 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
67
71
  @config.solr_home.should == '/some/path/solr'
68
72
  end
69
73
 
70
- it "should handle the 'data_path' property when not set" do
71
- Rails.should_receive(:root).at_least(1).and_return('/some/path')
72
- @config.data_path.should == '/some/path/solr/data/test'
73
- end
74
-
75
74
  it "should handle the 'pid_dir' property when not set" do
76
75
  Rails.should_receive(:root).at_least(1).and_return('/some/path')
77
76
  @config.pid_dir.should == '/some/path/solr/pids/test'
@@ -136,10 +135,6 @@ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
136
135
  @config.solr_home.should == '/my_superior_path'
137
136
  end
138
137
 
139
- it "should handle the 'data_path' property when set" do
140
- @config.data_path.should == '/my_superior_path/data'
141
- end
142
-
143
138
  it "should handle the 'pid_dir' property when set" do
144
139
  @config.pid_dir.should == '/my_superior_path/pids'
145
140
  end
@@ -167,11 +162,15 @@ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
167
162
  it "should handle the 'open_timeout' property when set" do
168
163
  @config.open_timeout.should == 0.5
169
164
  end
165
+
166
+ it "should handle the 'proxy' property when set" do
167
+ @config.proxy.should == 'http://proxy.com:12345'
168
+ end
170
169
  end
171
170
 
172
171
  describe Sunspot::Rails::Configuration, "with auto_index_callback and auto_remove_callback set" do
173
172
  before do
174
- ::Rails.stub!(:env => 'config_commit_test')
173
+ ::Rails.stub(:env => 'config_commit_test')
175
174
  @config = Sunspot::Rails::Configuration.new
176
175
  end
177
176
 
@@ -165,6 +165,22 @@ describe 'ActiveRecord mixin' do
165
165
  end.results.first.attribute_names.sort.should == ['body', 'id', 'title']
166
166
  end
167
167
 
168
+ it 'should use the scoped option from search call to data accessor' do
169
+ Post.search(:scopes => [:includes_location]) do
170
+ with :title, 'Test Post'
171
+ end.data_accessor_for(Post).scopes.should == [:includes_location]
172
+ end
173
+
174
+ it 'should use the scopes option on the data accessor when specified' do
175
+ @post.update_attribute(:location, Location.create)
176
+ post = Post.search do
177
+ with :title, 'Test Post'
178
+ data_accessor_for(Post).scopes = [:includes_location]
179
+ end.results.first
180
+
181
+ (Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).should be_true # Rails 3.1 removed "loaded_#{association}" method
182
+ end
183
+
168
184
  it 'should gracefully handle nonexistent records' do
169
185
  post2 = Post.create!(:title => 'Test Post')
170
186
  post2.index!
@@ -10,4 +10,8 @@ class Post < ActiveRecord::Base
10
10
  text :body, :more_like_this => true
11
11
  location :location
12
12
  end
13
+
14
+ scope :includes_location, -> {
15
+ includes(:location)
16
+ }
13
17
  end
@@ -17,12 +17,12 @@ config_test:
17
17
  port: 1234
18
18
  path: /solr/idx
19
19
  log_level: WARNING
20
- data_path: /my_superior_path/data
21
20
  pid_dir: /my_superior_path/pids
22
21
  solr_home: /my_superior_path
23
22
  bind_address: 127.0.0.1
24
23
  read_timeout: 2
25
24
  open_timeout: 0.5
25
+ proxy: http://proxy.com:12345
26
26
  auto_commit_after_request: false
27
27
  auto_commit_after_delete_request: true
28
28
  config_disabled_test:
@@ -30,6 +30,12 @@ describe 'sunspot namespace rake task' do
30
30
 
31
31
  run_rake_task("sunspot:reindex", '', "Post+Author", true)
32
32
  end
33
+
34
+ it "should raise exception when all tables of sunspot models are empty" do
35
+ STDOUT.should_receive(:puts).with("You have no data in the database. Reindexing does nothing here.")
36
+ empty_tables
37
+ run_rake_task("sunspot:reindex")
38
+ end
33
39
  end
34
40
  end
35
41
 
@@ -16,10 +16,6 @@ describe Sunspot::Rails::Server do
16
16
  @server.pid_path.should == File.join(@server.pid_dir, 'sunspot-solr-test.pid')
17
17
  end
18
18
 
19
- it "sets the correct Solr data dir" do
20
- @server.solr_data_dir.should == File.join(@solr_home, 'data', 'test')
21
- end
22
-
23
19
  it "sets the correct port" do
24
20
  @server.port.should == 8983
25
21
  end
@@ -10,7 +10,7 @@ describe 'specs with Sunspot stubbed' do
10
10
  end
11
11
 
12
12
  it 'should batch' do
13
- foo = mock('Foo')
13
+ foo = double('Foo')
14
14
  block = lambda { foo.bar }
15
15
 
16
16
  foo.should_receive(:bar)
@@ -28,6 +28,16 @@ describe 'specs with Sunspot stubbed' do
28
28
  @post.index!
29
29
  end
30
30
 
31
+ it 'should not send atomic_update to session' do
32
+ @session.should_not_receive(:atomic_update)
33
+ @post.index
34
+ end
35
+
36
+ it 'should not send atomic_update! to session' do
37
+ @session.should_not_receive(:atomic_update!)
38
+ @post.index!
39
+ end
40
+
31
41
  it 'should not send commit to session' do
32
42
  @session.should_not_receive(:commit)
33
43
  Sunspot.commit
@@ -154,5 +164,32 @@ describe 'specs with Sunspot stubbed' do
154
164
  @accessor.should respond_to(:include, :include=)
155
165
  end
156
166
  end
167
+
168
+ describe '#stats' do
169
+ before do
170
+ @stats = @search.stats(:price)
171
+ end
172
+
173
+ it 'should response to all the available data methods' do
174
+ @stats.should respond_to(
175
+ :min,
176
+ :max,
177
+ :count,
178
+ :sum,
179
+ :missing,
180
+ :sum_of_squares,
181
+ :mean,
182
+ :standard_deviation)
183
+ end
184
+
185
+ it 'should return empty results for a given facet' do
186
+ @stats.facet(:category_id).rows.should == []
187
+ end
188
+
189
+ it 'should return empty array if listing facets' do
190
+ @stats.facets.should == []
191
+ end
192
+
193
+ end
157
194
  end
158
195
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
5
- prerelease:
4
+ version: 2.2.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mat Brown
@@ -27,12 +26,11 @@ authors:
27
26
  autorequire:
28
27
  bindir: bin
29
28
  cert_chain: []
30
- date: 2015-04-09 00:00:00.000000000 Z
29
+ date: 2016-09-01 00:00:00.000000000 Z
31
30
  dependencies:
32
31
  - !ruby/object:Gem::Dependency
33
32
  name: rails
34
33
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
34
  requirements:
37
35
  - - ">="
38
36
  - !ruby/object:Gem::Version
@@ -40,7 +38,6 @@ dependencies:
40
38
  type: :runtime
41
39
  prerelease: false
42
40
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
41
  requirements:
45
42
  - - ">="
46
43
  - !ruby/object:Gem::Version
@@ -48,23 +45,20 @@ dependencies:
48
45
  - !ruby/object:Gem::Dependency
49
46
  name: sunspot
50
47
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
48
  requirements:
53
49
  - - '='
54
50
  - !ruby/object:Gem::Version
55
- version: 2.2.0
51
+ version: 2.2.6
56
52
  type: :runtime
57
53
  prerelease: false
58
54
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
55
  requirements:
61
56
  - - '='
62
57
  - !ruby/object:Gem::Version
63
- version: 2.2.0
58
+ version: 2.2.6
64
59
  - !ruby/object:Gem::Dependency
65
60
  name: nokogiri
66
61
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
62
  requirements:
69
63
  - - ">="
70
64
  - !ruby/object:Gem::Version
@@ -72,7 +66,6 @@ dependencies:
72
66
  type: :runtime
73
67
  prerelease: false
74
68
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
69
  requirements:
77
70
  - - ">="
78
71
  - !ruby/object:Gem::Version
@@ -80,7 +73,6 @@ dependencies:
80
73
  - !ruby/object:Gem::Dependency
81
74
  name: rspec
82
75
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
76
  requirements:
85
77
  - - "~>"
86
78
  - !ruby/object:Gem::Version
@@ -88,7 +80,6 @@ dependencies:
88
80
  type: :development
89
81
  prerelease: false
90
82
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
83
  requirements:
93
84
  - - "~>"
94
85
  - !ruby/object:Gem::Version
@@ -96,7 +87,6 @@ dependencies:
96
87
  - !ruby/object:Gem::Dependency
97
88
  name: rspec-rails
98
89
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
90
  requirements:
101
91
  - - "~>"
102
92
  - !ruby/object:Gem::Version
@@ -104,7 +94,6 @@ dependencies:
104
94
  type: :development
105
95
  prerelease: false
106
96
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
97
  requirements:
109
98
  - - "~>"
110
99
  - !ruby/object:Gem::Version
@@ -138,6 +127,8 @@ files:
138
127
  - gemfiles/rails-3.1.0
139
128
  - gemfiles/rails-3.2.0
140
129
  - gemfiles/rails-4.0.0
130
+ - gemfiles/rails-4.1.0
131
+ - gemfiles/rails-4.2.0
141
132
  - generators/sunspot/sunspot_generator.rb
142
133
  - generators/sunspot/templates/sunspot.yml
143
134
  - install.rb
@@ -193,6 +184,7 @@ files:
193
184
  homepage: http://github.com/outoftime/sunspot/tree/master/sunspot_rails
194
185
  licenses:
195
186
  - MIT
187
+ metadata: {}
196
188
  post_install_message:
197
189
  rdoc_options:
198
190
  - "--webcvs=http://github.com/outoftime/sunspot/tree/master/%s"
@@ -203,22 +195,20 @@ rdoc_options:
203
195
  require_paths:
204
196
  - lib
205
197
  required_ruby_version: !ruby/object:Gem::Requirement
206
- none: false
207
198
  requirements:
208
199
  - - ">="
209
200
  - !ruby/object:Gem::Version
210
201
  version: '0'
211
202
  required_rubygems_version: !ruby/object:Gem::Requirement
212
- none: false
213
203
  requirements:
214
204
  - - ">="
215
205
  - !ruby/object:Gem::Version
216
206
  version: '0'
217
207
  requirements: []
218
208
  rubyforge_project: sunspot
219
- rubygems_version: 1.8.25
209
+ rubygems_version: 2.5.0
220
210
  signing_key:
221
- specification_version: 3
211
+ specification_version: 4
222
212
  summary: Rails integration for the Sunspot Solr search library
223
213
  test_files:
224
214
  - spec/configuration_spec.rb