sunspot_rails 2.2.3 → 2.2.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53553509fb1420ff217918c4af4874764cf06d97
4
- data.tar.gz: 8135d49a163251579ca4233d6e6744b0b34bbbee
3
+ metadata.gz: 35f1acfbb723240a94351de829da76209d44e561
4
+ data.tar.gz: 47ee861fe055f37f2a09901f46538007789eb210
5
5
  SHA512:
6
- metadata.gz: 7ad49232bf33f0e1d858bff51a965d022048b8240584b4a08776f508ba29b66d23cc08116c38994c32c0bf2592f473e5338c73ed90ee360a455750814ad4c1ed
7
- data.tar.gz: 80e5d687362e3aafe2a5cb97e7ad6cb9629c8cdbf2f1b7ade41dbfcd83dca20eb83739f2f047b087a32780e715e8d4d84ae7cd1cf44064f8fbc497fbf4b1daf2
6
+ metadata.gz: 483a3523c068942840b0fee63727e30a7a506793ad7107ce9df747e0199e61f764a5915873e20ec66789c7ad895b9ceb22e640eb65caf9405523fc9245b41817
7
+ data.tar.gz: ae29cca30f1103b861cbffe4776f3172e4f6408711738a4e0dbce81dcb51b5e4c90ed0464f76db469de7cb63dc8a0d7adb29a7d58689b7283667bb46330767e7
@@ -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
 
@@ -374,15 +374,15 @@ module Sunspot #:nodoc:
374
374
  end
375
375
 
376
376
  def solr_execute_search(options = {})
377
- options.assert_valid_keys(:include, :select)
377
+ inherited_attributes = [:include, :select, :scopes]
378
+ options.assert_valid_keys(*inherited_attributes)
378
379
  search = yield
379
380
  unless options.empty?
380
381
  search.build do |query|
381
- if options[:include]
382
- query.data_accessor_for(self).include = options[:include]
383
- end
384
- if options[:select]
385
- 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
386
386
  end
387
387
  end
388
388
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -26,7 +26,7 @@ authors:
26
26
  autorequire:
27
27
  bindir: bin
28
28
  cert_chain: []
29
- date: 2015-12-15 00:00:00.000000000 Z
29
+ date: 2016-01-21 00:00:00.000000000 Z
30
30
  dependencies:
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rails
@@ -48,14 +48,14 @@ dependencies:
48
48
  requirements:
49
49
  - - '='
50
50
  - !ruby/object:Gem::Version
51
- version: 2.2.3
51
+ version: 2.2.4
52
52
  type: :runtime
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - '='
57
57
  - !ruby/object:Gem::Version
58
- version: 2.2.3
58
+ version: 2.2.4
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: nokogiri
61
61
  requirement: !ruby/object:Gem::Requirement