picky 0.3.0 → 0.9.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.
- data/lib/picky/application.rb +2 -2
- data/lib/picky/cacher/partial/default.rb +1 -1
- data/lib/picky/configuration/field.rb +8 -10
- data/lib/picky/configuration/indexes.rb +6 -6
- data/lib/picky/configuration/queries.rb +4 -3
- data/lib/picky/cores.rb +2 -2
- data/lib/picky/extensions/array.rb +2 -12
- data/lib/picky/generator.rb +27 -4
- data/lib/picky/index/bundle.rb +5 -41
- data/lib/picky/index/bundle_checker.rb +58 -0
- data/lib/picky/index/type.rb +4 -1
- data/lib/picky/index/wrappers/exact_first.rb +57 -0
- data/lib/picky/indexes.rb +12 -19
- data/lib/picky/loader.rb +7 -8
- data/lib/picky/query/allocation.rb +1 -1
- data/lib/picky/query/combinations.rb +9 -6
- data/lib/picky/query/combinator.rb +11 -5
- data/lib/picky/rack/harakiri.rb +1 -1
- data/lib/picky/results/base.rb +4 -12
- data/lib/picky/results/live.rb +0 -6
- data/lib/picky/routing.rb +17 -17
- data/lib/picky/sources/csv.rb +1 -2
- data/lib/picky/sources/db.rb +0 -1
- data/lib/picky/sources/delicious.rb +41 -0
- data/lib/picky/tokenizers/base.rb +52 -43
- data/lib/picky/tokenizers/default/index.rb +7 -0
- data/lib/picky/tokenizers/default/query.rb +7 -0
- data/lib/picky/tokenizers/index.rb +0 -9
- data/lib/picky/tokenizers/query.rb +0 -9
- data/lib/tasks/application.rake +1 -1
- data/lib/tasks/cache.rake +41 -48
- data/lib/tasks/framework.rake +1 -1
- data/lib/tasks/index.rake +22 -12
- data/lib/tasks/server.rake +3 -3
- data/lib/tasks/shortcuts.rake +9 -2
- data/lib/tasks/statistics.rake +8 -8
- data/lib/tasks/try.rake +4 -2
- data/project_prototype/Gemfile +1 -1
- data/project_prototype/app/application.rb +7 -3
- data/spec/lib/cacher/partial/default_spec.rb +1 -1
- data/spec/lib/cacher/partial/none_spec.rb +12 -0
- data/spec/lib/cacher/partial/subtoken_spec.rb +29 -1
- data/spec/lib/configuration/field_spec.rb +162 -3
- data/spec/lib/configuration/indexes_spec.rb +150 -0
- data/spec/lib/cores_spec.rb +43 -0
- data/spec/lib/extensions/module_spec.rb +27 -16
- data/spec/lib/generator_spec.rb +3 -3
- data/spec/lib/index/bundle_checker_spec.rb +67 -0
- data/spec/lib/index/bundle_spec.rb +0 -50
- data/spec/lib/index/type_spec.rb +47 -0
- data/spec/lib/index/wrappers/exact_first_spec.rb +95 -0
- data/spec/lib/indexers/base_spec.rb +18 -2
- data/spec/lib/loader_spec.rb +21 -1
- data/spec/lib/query/allocation_spec.rb +25 -0
- data/spec/lib/query/base_spec.rb +37 -0
- data/spec/lib/query/combination_spec.rb +10 -1
- data/spec/lib/query/combinations_spec.rb +82 -3
- data/spec/lib/query/combinator_spec.rb +45 -0
- data/spec/lib/query/token_spec.rb +24 -0
- data/spec/lib/rack/harakiri_spec.rb +28 -0
- data/spec/lib/results/base_spec.rb +24 -0
- data/spec/lib/results/live_spec.rb +15 -0
- data/spec/lib/routing_spec.rb +5 -0
- data/spec/lib/sources/db_spec.rb +31 -1
- data/spec/lib/sources/delicious_spec.rb +75 -0
- data/spec/lib/tokenizers/base_spec.rb +160 -49
- data/spec/lib/tokenizers/default/index_spec.rb +11 -0
- data/spec/lib/tokenizers/default/query_spec.rb +11 -0
- metadata +26 -5
- data/lib/picky/index/combined.rb +0 -45
- data/lib/picky/tokenizers/default.rb +0 -3
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Index::Wrappers::ExactFirst do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@exact = stub :exact
|
7
|
+
@partial = stub :partial
|
8
|
+
@category = stub :category, :exact => @exact, :partial => @partial
|
9
|
+
|
10
|
+
@wrapper = Index::Wrappers::ExactFirst.new @category
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "self.wrap" do
|
14
|
+
context "type" do
|
15
|
+
it "wraps each category" do
|
16
|
+
category = stub :category, :name => :some_category, :exact => :exact, :partial => :partial
|
17
|
+
|
18
|
+
type = Index::Type.new :type_name, :result_type, false, category
|
19
|
+
|
20
|
+
Index::Wrappers::ExactFirst.wrap type
|
21
|
+
|
22
|
+
type.categories.first.should be_kind_of(Index::Wrappers::ExactFirst)
|
23
|
+
end
|
24
|
+
it "returns the type" do
|
25
|
+
category = stub :category, :name => :some_category, :exact => :exact, :partial => :partial
|
26
|
+
|
27
|
+
type = Index::Type.new :type_name, :result_type, false, category
|
28
|
+
|
29
|
+
Index::Wrappers::ExactFirst.wrap(type).should == type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "category" do
|
33
|
+
it "wraps each category" do
|
34
|
+
category = stub :category, :exact => :exact, :partial => :partial
|
35
|
+
|
36
|
+
Index::Wrappers::ExactFirst.wrap(category).should be_kind_of(Index::Wrappers::ExactFirst)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'ids' do
|
42
|
+
it "uses first the exact, then the partial ids" do
|
43
|
+
@exact.stub! :ids => [1,4,5,6]
|
44
|
+
@partial.stub! :ids => [2,3,7]
|
45
|
+
|
46
|
+
@wrapper.ids(:anything).should == [1,4,5,6,2,3,7]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'weight' do
|
51
|
+
context "exact with weight" do
|
52
|
+
before(:each) do
|
53
|
+
@exact.stub! :weight => 1.23
|
54
|
+
end
|
55
|
+
context "partial with weight" do
|
56
|
+
before(:each) do
|
57
|
+
@partial.stub! :weight => 0.12
|
58
|
+
end
|
59
|
+
it "uses the higher weight" do
|
60
|
+
@wrapper.weight(:anything).should == 1.23
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context "partial without weight" do
|
64
|
+
before(:each) do
|
65
|
+
@partial.stub! :weight => nil
|
66
|
+
end
|
67
|
+
it "uses the exact weight" do
|
68
|
+
@wrapper.weight(:anything).should == 1.23
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
context "exact without weight" do
|
73
|
+
before(:each) do
|
74
|
+
@exact.stub! :weight => nil
|
75
|
+
end
|
76
|
+
context "partial with weight" do
|
77
|
+
before(:each) do
|
78
|
+
@partial.stub! :weight => 0.12
|
79
|
+
end
|
80
|
+
it "uses the partial weight" do
|
81
|
+
@wrapper.weight(:anything).should == 0.12
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "partial without weight" do
|
85
|
+
before(:each) do
|
86
|
+
@partial.stub! :weight => nil
|
87
|
+
end
|
88
|
+
it "is zero" do
|
89
|
+
@wrapper.weight(:anything).should == 0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -11,17 +11,33 @@ describe Indexers::Base do
|
|
11
11
|
:search_index_file_name => :some_search_index_name,
|
12
12
|
:indexed_name => :some_indexed_field_name
|
13
13
|
@indexer = Indexers::Base.new @type, @field
|
14
|
-
@indexer.stub! :
|
14
|
+
@indexer.stub! :timed_exclaim
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "tokenizer" do
|
18
|
-
it "
|
18
|
+
it "delegates to the field" do
|
19
19
|
@field.should_receive(:tokenizer).once.with
|
20
20
|
|
21
21
|
@indexer.tokenizer
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "indexing_message" do
|
26
|
+
it "informs the user about what it is going to index" do
|
27
|
+
@indexer.should_receive(:timed_exclaim).once.with 'INDEX some_type some_field_name'
|
28
|
+
|
29
|
+
@indexer.indexing_message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "tokenizer" do
|
34
|
+
it "should delegate to field" do
|
35
|
+
@indexer.should_receive(:tokenizer).once.with
|
36
|
+
|
37
|
+
@indexer.tokenizer
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
25
41
|
describe 'search_index_file_name' do
|
26
42
|
it 'should return a specific name' do
|
27
43
|
@indexer.search_index_file_name.should == :some_search_index_name
|
data/spec/lib/loader_spec.rb
CHANGED
@@ -7,7 +7,27 @@ describe Loader do
|
|
7
7
|
Configuration.stub! :apply
|
8
8
|
Indexes.stub! :setup
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
describe 'load_application' do
|
12
|
+
before(:each) do
|
13
|
+
Loader.stub! :load
|
14
|
+
Loader.stub! :exclaim
|
15
|
+
end
|
16
|
+
it "does ok" do
|
17
|
+
lambda { Loader.load_application }.should_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'load_framework' do
|
22
|
+
before(:each) do
|
23
|
+
Loader.stub! :load
|
24
|
+
Loader.stub! :exclaim
|
25
|
+
end
|
26
|
+
it "does ok" do
|
27
|
+
lambda { Loader.load_framework }.should_not raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
11
31
|
describe 'load_self' do
|
12
32
|
before(:each) do
|
13
33
|
Loader.stub! :load
|
@@ -7,6 +7,31 @@ describe Query::Allocation do
|
|
7
7
|
@allocation = Query::Allocation.new @combinations
|
8
8
|
end
|
9
9
|
|
10
|
+
describe "hash" do
|
11
|
+
it "delegates to the combinations" do
|
12
|
+
@combinations.should_receive(:hash).once.with
|
13
|
+
|
14
|
+
@allocation.hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "to_s" do
|
19
|
+
before(:each) do
|
20
|
+
@combinations.stub! :to_result => 'combinations_result'
|
21
|
+
end
|
22
|
+
context "allocation.count > 0" do
|
23
|
+
before(:each) do
|
24
|
+
@allocation.stub! :count => 10
|
25
|
+
@allocation.stub! :result_type => :result_type
|
26
|
+
@allocation.stub! :score => :score
|
27
|
+
@allocation.stub! :ids => :ids
|
28
|
+
end
|
29
|
+
it "represents correctly" do
|
30
|
+
@allocation.to_s.should == "Allocation: result_type, score, 10, combinations_result, ids"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
10
35
|
describe 'remove' do
|
11
36
|
it 'should delegate to the combinations' do
|
12
37
|
@combinations.should_receive(:remove).once.with [:some_identifiers]
|
data/spec/lib/query/base_spec.rb
CHANGED
@@ -3,6 +3,43 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe 'Query::Base' do
|
5
5
|
|
6
|
+
describe "empty_results" do
|
7
|
+
before(:each) do
|
8
|
+
@query = Query::Full.new
|
9
|
+
|
10
|
+
@result_type = stub :result_type
|
11
|
+
@query.stub! :result_type => @result_type
|
12
|
+
end
|
13
|
+
it "returns a new result type" do
|
14
|
+
@result_type.should_receive(:new).once.with :some_offset
|
15
|
+
|
16
|
+
@query.empty_results :some_offset
|
17
|
+
end
|
18
|
+
it "returns a new result type with default offset" do
|
19
|
+
@result_type.should_receive(:new).once.with 0
|
20
|
+
|
21
|
+
@query.empty_results
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "search_with_text" do
|
26
|
+
before(:each) do
|
27
|
+
@query = Query::Full.new
|
28
|
+
end
|
29
|
+
it "delegates to search" do
|
30
|
+
@query.stub! :tokenized => :tokens
|
31
|
+
|
32
|
+
@query.should_receive(:search).once.with :tokens, :offset
|
33
|
+
|
34
|
+
@query.search_with_text :text, :offset
|
35
|
+
end
|
36
|
+
it "uses the tokenizer" do
|
37
|
+
@query.should_receive(:tokenized).once.with :text
|
38
|
+
|
39
|
+
@query.search_with_text :text, :anything
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
6
43
|
describe 'reduce' do
|
7
44
|
context 'real' do
|
8
45
|
before(:each) do
|
@@ -11,7 +11,16 @@ describe 'Query::Combination' do
|
|
11
11
|
|
12
12
|
@combination = Query::Combination.new @token, @category
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
describe "to_s" do
|
16
|
+
it "shows the combination's info" do
|
17
|
+
@bundle.stub! :name => :bundle_name
|
18
|
+
@token.stub! :to_result => :token_result
|
19
|
+
|
20
|
+
@combination.to_s.should == 'bundle_name some_category_name:token_result'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
describe 'hash' do
|
16
25
|
it 'should hash the token and the bundle' do
|
17
26
|
@combination.hash.should == [@token.to_s, @bundle].hash
|
@@ -6,10 +6,89 @@ describe 'Query::Combinations' do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@combinations_ary = stub :combinations_ary
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
type = stub :type, :result_type => :some_type
|
11
|
+
|
12
|
+
@combinations = Query::Combinations.new type, @combinations_ary
|
11
13
|
end
|
12
|
-
|
14
|
+
|
15
|
+
describe "pack_into_allocation" do
|
16
|
+
it "return an Allocation" do
|
17
|
+
@combinations.pack_into_allocation.should be_kind_of(Query::Allocation)
|
18
|
+
end
|
19
|
+
it "returns an Allocation with specific result_type" do
|
20
|
+
@combinations.pack_into_allocation.result_type.should == :some_type
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "to_result" do
|
25
|
+
before(:each) do
|
26
|
+
@combination1 = stub :combination1, :to_result => :result1
|
27
|
+
@combination2 = stub :combination2, :to_result => :result2
|
28
|
+
|
29
|
+
@combinations_ary = [@combination1, @combination2]
|
30
|
+
|
31
|
+
@combinations = Query::Combinations.new :some_type, @combinations_ary
|
32
|
+
end
|
33
|
+
it "resultifies the combinations" do
|
34
|
+
@combinations.to_result.should == [:result1, :result2]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "add_score" do
|
39
|
+
it "uses the weights' score method" do
|
40
|
+
weights = stub :weights
|
41
|
+
weights.should_receive(:score).once.with @combinations_ary
|
42
|
+
|
43
|
+
@combinations.add_score weights
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "sum_score" do
|
48
|
+
before(:each) do
|
49
|
+
@combination1 = stub :combination1, :weight => 3.14
|
50
|
+
@combination2 = stub :combination2, :weight => 2.76
|
51
|
+
|
52
|
+
@combinations_ary = [@combination1, @combination2]
|
53
|
+
|
54
|
+
@combinations = Query::Combinations.new :some_type, @combinations_ary
|
55
|
+
end
|
56
|
+
it "sums the scores" do
|
57
|
+
@combinations.sum_score.should == 5.90
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "calculate_score" do
|
62
|
+
before(:each) do
|
63
|
+
@combinations.stub! :sum_score => 0
|
64
|
+
@combinations.stub! :add_score => 0
|
65
|
+
end
|
66
|
+
it "first sums, then weighs" do
|
67
|
+
@combinations.should_receive(:sum_score).once.ordered.and_return 0
|
68
|
+
@combinations.should_receive(:add_score).once.ordered.and_return 0
|
69
|
+
|
70
|
+
@combinations.calculate_score :anything
|
71
|
+
end
|
72
|
+
it "calls sum_score" do
|
73
|
+
@combinations.should_receive(:sum_score).once.with.and_return 0
|
74
|
+
|
75
|
+
@combinations.calculate_score :anything
|
76
|
+
end
|
77
|
+
it "calls sum_score" do
|
78
|
+
@combinations.should_receive(:add_score).once.with(:weights).and_return 0
|
79
|
+
|
80
|
+
@combinations.calculate_score :weights
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'hash' do
|
85
|
+
it "delegates to the combinations array" do
|
86
|
+
@combinations_ary.should_receive(:hash).once.with
|
87
|
+
|
88
|
+
@combinations.hash
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
13
92
|
describe 'remove' do
|
14
93
|
before(:each) do
|
15
94
|
@combination1 = stub :combination1, :in? => false
|
@@ -27,6 +27,25 @@ describe Query::Combinator do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context "with real categories" do
|
31
|
+
before(:each) do
|
32
|
+
@category1 = Index::Category.new :some_name, :some_type
|
33
|
+
@category2 = Index::Category.new :some_name, :some_type
|
34
|
+
@category3 = Index::Category.new :some_name, :some_type
|
35
|
+
@categories = [@category1, @category2, @category3]
|
36
|
+
|
37
|
+
@combinator = Query::Combinator.new @categories
|
38
|
+
end
|
39
|
+
describe "similar_possible_for" do
|
40
|
+
before(:each) do
|
41
|
+
@token = Query::Token.processed 'similar~'
|
42
|
+
end
|
43
|
+
it "returns possible categories" do
|
44
|
+
@combinator.similar_possible_for(@token).should == []
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
30
49
|
context 'without options' do
|
31
50
|
before(:each) do
|
32
51
|
@category1 = stub :category1, :name => :category1
|
@@ -37,6 +56,32 @@ describe Query::Combinator do
|
|
37
56
|
@combinator = Query::Combinator.new @categories
|
38
57
|
end
|
39
58
|
|
59
|
+
describe "possible_combinations_for" do
|
60
|
+
before(:each) do
|
61
|
+
@token = stub :token
|
62
|
+
end
|
63
|
+
context "with similar token" do
|
64
|
+
before(:each) do
|
65
|
+
@token.stub :similar? => true
|
66
|
+
end
|
67
|
+
it "calls the right method" do
|
68
|
+
@combinator.should_receive(:similar_possible_for).once.with @token
|
69
|
+
|
70
|
+
@combinator.possible_combinations_for @token
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "with non-similar token" do
|
74
|
+
before(:each) do
|
75
|
+
@token.stub :similar? => false
|
76
|
+
end
|
77
|
+
it "calls the right method" do
|
78
|
+
@combinator.should_receive(:possible_for).once.with @token
|
79
|
+
|
80
|
+
@combinator.possible_combinations_for @token
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
40
85
|
describe 'possible_for' do
|
41
86
|
context 'without preselected categories' do
|
42
87
|
context 'user defined exists' do
|
@@ -8,6 +8,30 @@ describe Query::Token do
|
|
8
8
|
Query::Qualifiers.instance.prepare
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "generate_similarity_for" do
|
12
|
+
before(:each) do
|
13
|
+
@bundle = stub :bundle
|
14
|
+
|
15
|
+
@token = Query::Token.processed 'flarb~'
|
16
|
+
end
|
17
|
+
context "with similar" do
|
18
|
+
before(:each) do
|
19
|
+
@bundle.stub! :similar => [:array, :of, :similar]
|
20
|
+
end
|
21
|
+
it "returns an enumerator" do
|
22
|
+
@token.generate_similarity_for(@bundle).to_a.size.should == 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "without similar" do
|
26
|
+
before(:each) do
|
27
|
+
@bundle.stub! :similar => nil
|
28
|
+
end
|
29
|
+
it "returns an enumerator with 0 entries" do
|
30
|
+
@token.generate_similarity_for(@bundle).to_a.size.should == 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
11
35
|
describe 'to_solr' do
|
12
36
|
def self.it_should_solr text, expected_result
|
13
37
|
it "should solrify into #{expected_result} from #{text}" do
|
@@ -12,6 +12,34 @@ describe Rack::Harakiri do
|
|
12
12
|
it "should quit after an amount of requests" do
|
13
13
|
@harakiri.quit_after_requests.should == 50
|
14
14
|
end
|
15
|
+
describe "harakiri" do
|
16
|
+
it "should kill the process after 50 harakiri calls" do
|
17
|
+
Process.should_receive(:kill).once
|
18
|
+
|
19
|
+
50.times { @harakiri.harakiri }
|
20
|
+
end
|
21
|
+
it "should not kill the process after 49 harakiri calls" do
|
22
|
+
Process.should_receive(:kill).never
|
23
|
+
|
24
|
+
49.times { @harakiri.harakiri }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe "call" do
|
28
|
+
before(:each) do
|
29
|
+
@app.stub! :call
|
30
|
+
@app.stub! :harakiri
|
31
|
+
end
|
32
|
+
it "calls harakiri" do
|
33
|
+
@harakiri.should_receive(:harakiri).once.with
|
34
|
+
|
35
|
+
@harakiri.call :env
|
36
|
+
end
|
37
|
+
it "calls the app" do
|
38
|
+
@app.should_receive(:call).once.with :env
|
39
|
+
|
40
|
+
@harakiri.call :env
|
41
|
+
end
|
42
|
+
end
|
15
43
|
end
|
16
44
|
context "with harakiri set" do
|
17
45
|
before(:each) do
|
@@ -2,6 +2,30 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Results do
|
4
4
|
|
5
|
+
describe "ids" do
|
6
|
+
before(:each) do
|
7
|
+
@allocations = stub :allocations
|
8
|
+
@results = Results::Base.new :unimportant, @allocations
|
9
|
+
end
|
10
|
+
it "delegates" do
|
11
|
+
@allocations.should_receive(:ids).once.with :anything
|
12
|
+
|
13
|
+
@results.ids :anything
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "random_ids" do
|
18
|
+
before(:each) do
|
19
|
+
@allocations = stub :allocations
|
20
|
+
@results = Results::Base.new :unimportant, @allocations
|
21
|
+
end
|
22
|
+
it "delegates" do
|
23
|
+
@allocations.should_receive(:random_ids).once.with :anything
|
24
|
+
|
25
|
+
@results.random_ids :anything
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
5
29
|
describe 'to_log' do
|
6
30
|
before(:each) do
|
7
31
|
time = stub :time, :to_s => '0-08-16 10:07:33'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Results::Live do
|
4
|
+
|
5
|
+
it "is the right subclass" do
|
6
|
+
Results::Live.should < Results::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
it "logs correctly" do
|
10
|
+
Time.stub! :now => Time.parse('2010-10-25 01:25:07')
|
11
|
+
|
12
|
+
Results::Live.new.to_log('some query').should == '.|2010-10-25 01:25:07|0.000000|some query | 0| 0| 0|'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/lib/routing_spec.rb
CHANGED
data/spec/lib/sources/db_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Sources::DB do
|
|
6
6
|
@type = stub :type, :name => 'some_type_name'
|
7
7
|
|
8
8
|
@connection = stub :connection
|
9
|
-
@adapter
|
9
|
+
@adapter = stub :adapter, :connection => @connection
|
10
10
|
|
11
11
|
@select_statement = stub :statement
|
12
12
|
|
@@ -16,6 +16,36 @@ describe Sources::DB do
|
|
16
16
|
@source.stub! :connect_backend
|
17
17
|
end
|
18
18
|
|
19
|
+
describe "get_data" do
|
20
|
+
it "delegates" do
|
21
|
+
type = stub :type, :name => :some_type
|
22
|
+
field = stub :field, :name => :some_field
|
23
|
+
|
24
|
+
@connection.should_receive(:execute).once.with 'SELECT indexed_id, some_field FROM some_type_type_index st WHERE st.id > some_offset LIMIT 25000'
|
25
|
+
|
26
|
+
@source.get_data type, field, :some_offset
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "configure" do
|
31
|
+
it "works" do
|
32
|
+
lambda { @source.configure({}) }.should_not raise_error
|
33
|
+
end
|
34
|
+
context "with file" do
|
35
|
+
it "opens the config file relative to root" do
|
36
|
+
File.should_receive(:open).once.with 'some/search/root/app/bla.yml'
|
37
|
+
|
38
|
+
@source.configure :file => 'app/bla.yml'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "connect_backend" do
|
44
|
+
it "works" do
|
45
|
+
lambda { @source.connect_backend }.should_not raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
19
49
|
describe "chunksize" do
|
20
50
|
it "should be a specific size" do
|
21
51
|
@source.chunksize.should == 25_000
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sources::Delicious do
|
4
|
+
|
5
|
+
context "with file" do
|
6
|
+
|
7
|
+
describe "harvest" do
|
8
|
+
before(:each) do
|
9
|
+
@source = Sources::Delicious.new(:username, :password)
|
10
|
+
|
11
|
+
post1 = WWW::Delicious::Post.new
|
12
|
+
post1.uid = "5045d67b3f251e4ae966dffe71501763"
|
13
|
+
post1.tags = ["barefoot", "running", "shoe"]
|
14
|
+
post1.title = "VIBRAM - FiveFingers"
|
15
|
+
post1.url = URI.parse('http://www.vibramfivefingers.it/')
|
16
|
+
|
17
|
+
# post2 = WWW::Delicious::Post.new
|
18
|
+
# post2.uid = "d0b16f4b7e998a3386052bc95ad0d695"
|
19
|
+
# post2.tags = ["floating", "title", "scrolling", "css", "javascript", "ui"]
|
20
|
+
# post2.title = "Floating Title when Scrolling"
|
21
|
+
# post2.url = URI.parse('http://mesh.scribblelive.com/Event/Value_Judgements_in_Interface_Design5')
|
22
|
+
|
23
|
+
delicious = stub :delicious, :posts_recent => [post1]
|
24
|
+
|
25
|
+
WWW::Delicious.should_receive(:new).and_return delicious
|
26
|
+
end
|
27
|
+
it "should yield the right data" do
|
28
|
+
field = stub :b, :name => :tags
|
29
|
+
@source.harvest :anything, field do |id, token|
|
30
|
+
[id, token].should == [1, "barefoot running shoe"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it "should yield the right data" do
|
34
|
+
field = stub :b, :name => :title
|
35
|
+
@source.harvest :anything, field do |id, token|
|
36
|
+
[id, token].should == [1, "VIBRAM - FiveFingers"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it "should yield the right data" do
|
40
|
+
field = stub :b, :name => :url
|
41
|
+
@source.harvest :anything, field do |id, token|
|
42
|
+
[id, token].should == [1, "http://www.vibramfivefingers.it/"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe "get_data" do
|
47
|
+
before(:each) do
|
48
|
+
@source = Sources::Delicious.new(:username, :password)
|
49
|
+
|
50
|
+
post1 = WWW::Delicious::Post.new
|
51
|
+
post1.uid = "5045d67b3f251e4ae966dffe71501763"
|
52
|
+
post1.tags = ["barefoot", "running", "shoe"]
|
53
|
+
post1.title = "VIBRAM - FiveFingers"
|
54
|
+
post1.url = URI.parse('http://www.vibramfivefingers.it/')
|
55
|
+
|
56
|
+
# post2 = WWW::Delicious::Post.new
|
57
|
+
# post2.uid = "d0b16f4b7e998a3386052bc95ad0d695"
|
58
|
+
# post2.tags = ["floating", "title", "scrolling", "css", "javascript", "ui"]
|
59
|
+
# post2.title = "Floating Title when Scrolling"
|
60
|
+
# post2.url = URI.parse('http://mesh.scribblelive.com/Event/Value_Judgements_in_Interface_Design5')
|
61
|
+
|
62
|
+
delicious = stub :delicious, :posts_recent => [post1]
|
63
|
+
|
64
|
+
WWW::Delicious.should_receive(:new).and_return delicious
|
65
|
+
end
|
66
|
+
it "should yield each line" do
|
67
|
+
@source.get_data do |uid, data|
|
68
|
+
uid.should == 1
|
69
|
+
data.should == { :title => "VIBRAM - FiveFingers", :tags => "barefoot running shoe", :url => "http://www.vibramfivefingers.it/" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|