supernova 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/supernova.rb +1 -1
- data/lib/supernova/criteria.rb +6 -2
- data/lib/supernova/solr_indexer.rb +1 -1
- data/spec/supernova/criteria_spec.rb +32 -4
- data/spec/supernova/solr_indexer_spec.rb +13 -0
- data/spec/supernova_spec.rb +1 -1
- data/supernova.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/lib/supernova.rb
CHANGED
data/lib/supernova/criteria.rb
CHANGED
@@ -170,13 +170,17 @@ class Supernova::Criteria
|
|
170
170
|
if args.length == 1 && Array.new.respond_to?(args.first)
|
171
171
|
to_a.send(args.first, &block)
|
172
172
|
elsif self.named_scope_defined?(args.first)
|
173
|
-
self.merge(self.
|
173
|
+
self.merge(self.search_options[:named_scope_class].send(*args)) # merge named scope and current criteria
|
174
174
|
else
|
175
175
|
super
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
+
def named_scope_class(clazz)
|
180
|
+
merge_search_options :named_scope_class, clazz
|
181
|
+
end
|
182
|
+
|
179
183
|
def named_scope_defined?(name)
|
180
|
-
self.
|
184
|
+
self.search_options[:named_scope_class] && self.search_options[:named_scope_class].respond_to?(:defined_named_search_scopes) && self.search_options[:named_scope_class].defined_named_search_scopes.respond_to?(:include?) && self.search_options[:named_scope_class].defined_named_search_scopes.include?(name)
|
181
185
|
end
|
182
186
|
end
|
@@ -34,7 +34,7 @@ class Supernova::SolrIndexer
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def search_scope
|
37
|
-
Supernova::SolrCriteria.new(self.clazz).attribute_mapping(self.field_definitions)
|
37
|
+
Supernova::SolrCriteria.new(self.clazz).attribute_mapping(self.field_definitions).named_scope_class(self)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -169,7 +169,7 @@ describe "Supernova::Criteria" do
|
|
169
169
|
|
170
170
|
it "it calls merge with self and returned scope" do
|
171
171
|
clazz = double("clazz")
|
172
|
-
scope = Supernova::Criteria.new(clazz)
|
172
|
+
scope = Supernova::Criteria.new.named_scope_class(clazz)
|
173
173
|
scope.stub(:named_scope_defined?).and_return true
|
174
174
|
rge_scope = double("rgne_scope")
|
175
175
|
scope_ret = double("ret")
|
@@ -195,6 +195,10 @@ describe "Supernova::Criteria" do
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
+
describe "#with_scopes" do
|
199
|
+
|
200
|
+
end
|
201
|
+
|
198
202
|
describe "#merge" do
|
199
203
|
let(:criteria) { Supernova::Criteria.new.order("popularity asc").with(:a => 1).conditions(:b => 2).search("New Search") }
|
200
204
|
let(:new_crit) { Supernova::Criteria.new.order("popularity desc").with(:c => 8).conditions(:e => 9).search("Search") }
|
@@ -219,6 +223,24 @@ describe "Supernova::Criteria" do
|
|
219
223
|
new_crit.merge(criteria).search_options[:search].should == ["New Search"]
|
220
224
|
end
|
221
225
|
|
226
|
+
it "correctly merges the named_scope_class" do
|
227
|
+
new_crit.named_scope_class(String)
|
228
|
+
new_crit.merge(criteria).search_options[:named_scope_class].should == String
|
229
|
+
end
|
230
|
+
|
231
|
+
it "correctly merges the attribute_mapping" do
|
232
|
+
mapping = { :title => { :type => :string } }
|
233
|
+
new_crit.attribute_mapping(mapping)
|
234
|
+
new_crit.merge(criteria).search_options[:attribute_mapping].should == mapping
|
235
|
+
end
|
236
|
+
|
237
|
+
it "uses the base attributes_mapping when " do
|
238
|
+
mapping = { :title => { :type => :string }, :artist_name => { :type => :string } }
|
239
|
+
other = Supernova::SolrCriteria.new.with(:artist_name => "name")
|
240
|
+
Supernova::SolrCriteria.new.attribute_mapping(mapping).with(:title => "test").merge(other).to_params[:fq].should include("artist_name_s:name")
|
241
|
+
Supernova::SolrCriteria.new.attribute_mapping(mapping).with(:title => "test").merge(other).to_params[:fq].should include("title_s:test")
|
242
|
+
end
|
243
|
+
|
222
244
|
it "calls merge on options" do
|
223
245
|
criteria.stub!(:search_options).and_return({ :x => 2, :y => 9 })
|
224
246
|
new_crit.stub!(:search_options).and_return({ :z => 3, :c => 1 })
|
@@ -293,7 +315,7 @@ describe "Supernova::Criteria" do
|
|
293
315
|
attr_accessor :defined_named_search_scopes
|
294
316
|
end
|
295
317
|
clazz.defined_named_search_scopes = nil
|
296
|
-
Supernova::Criteria.new(clazz).should_not be_named_scope_defined(:rgne)
|
318
|
+
Supernova::Criteria.new.named_scope_class(clazz).should_not be_named_scope_defined(:rgne)
|
297
319
|
end
|
298
320
|
|
299
321
|
it "returns false when clazz is responding to defined_search_scopes but not included" do
|
@@ -302,7 +324,7 @@ describe "Supernova::Criteria" do
|
|
302
324
|
attr_accessor :defined_named_search_scopes
|
303
325
|
end
|
304
326
|
clazz.defined_named_search_scopes = [:some_other]
|
305
|
-
Supernova::Criteria.new(clazz).should_not be_named_scope_defined(:rgne)
|
327
|
+
Supernova::Criteria.new.named_scope_class(clazz).should_not be_named_scope_defined(:rgne)
|
306
328
|
end
|
307
329
|
|
308
330
|
it "returns true when clazz is responding to defined_search_scopes and included" do
|
@@ -311,7 +333,13 @@ describe "Supernova::Criteria" do
|
|
311
333
|
attr_accessor :defined_named_search_scopes
|
312
334
|
end
|
313
335
|
clazz.defined_named_search_scopes = [:rgne]
|
314
|
-
Supernova::Criteria.new(clazz).should be_named_scope_defined(:rgne)
|
336
|
+
Supernova::Criteria.new.named_scope_class(clazz).should be_named_scope_defined(:rgne)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
describe "#named_scope_class" do
|
341
|
+
it "sets the named_scope_class search_option" do
|
342
|
+
Supernova::Criteria.new.named_scope_class(String).search_options[:named_scope_class].should == String
|
315
343
|
end
|
316
344
|
end
|
317
345
|
end
|
@@ -433,6 +433,19 @@ describe Supernova::SolrIndexer do
|
|
433
433
|
end
|
434
434
|
indexer_clazz.with_title.to_params[:fq].should include("title_t:[* TO *]")
|
435
435
|
end
|
436
|
+
|
437
|
+
it "allows chaining of named scopes" do
|
438
|
+
indexer_clazz.named_search_scope :with_title do
|
439
|
+
where(:title.ne => nil)
|
440
|
+
end
|
441
|
+
|
442
|
+
indexer_clazz.named_search_scope :with_description do
|
443
|
+
where(:description.ne => nil)
|
444
|
+
end
|
445
|
+
fqs = indexer_clazz.with_description.with_title.to_params[:fq]
|
446
|
+
fqs.should include("description_t:[* TO *]")
|
447
|
+
fqs.should include("title_t:[* TO *]")
|
448
|
+
end
|
436
449
|
end
|
437
450
|
|
438
451
|
describe "#solr_field_for_field_name_and_mapping" do
|
data/spec/supernova_spec.rb
CHANGED
@@ -58,7 +58,7 @@ describe Supernova do
|
|
58
58
|
|
59
59
|
describe "chaining" do
|
60
60
|
it "calls merge with both scopes" do
|
61
|
-
scope = Supernova::ThinkingSphinxCriteria.new(clazz)
|
61
|
+
scope = Supernova::ThinkingSphinxCriteria.new(clazz).named_scope_class(clazz)
|
62
62
|
scope.should_receive(:merge).with(instance_of(Supernova::ThinkingSphinxCriteria))
|
63
63
|
scope.popular
|
64
64
|
end
|
data/supernova.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supernova
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|