sunspot_rails 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sunspot/rails/adapters.rb +5 -1
- data/lib/sunspot/rails/searchable.rb +6 -6
- data/spec/model_spec.rb +16 -0
- data/spec/rails_template/app/models/post.rb +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f1acfbb723240a94351de829da76209d44e561
|
4
|
+
data.tar.gz: 47ee861fe055f37f2a09901f46538007789eb210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
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
|
data/spec/model_spec.rb
CHANGED
@@ -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!
|
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.
|
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:
|
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.
|
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.
|
58
|
+
version: 2.2.4
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: nokogiri
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|