picky 4.17.1 → 4.18.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.
Files changed (38) hide show
  1. checksums.yaml +6 -14
  2. data/lib/picky/backends/backend.rb +9 -15
  3. data/lib/picky/backends/prepared/text.rb +1 -1
  4. data/lib/picky/backends/sqlite/basic.rb +3 -10
  5. data/lib/picky/bundle.rb +2 -2
  6. data/lib/picky/category.rb +10 -5
  7. data/lib/picky/category_indexed.rb +2 -1
  8. data/lib/picky/category_realtime.rb +10 -3
  9. data/lib/picky/helpers/measuring.rb +4 -6
  10. data/lib/picky/index_indexing.rb +0 -2
  11. data/lib/picky/indexes.rb +2 -2
  12. data/lib/picky/query/allocation.rb +3 -2
  13. data/lib/picky/query/allocations.rb +2 -2
  14. data/lib/picky/query/boosts.rb +2 -0
  15. data/lib/picky/query/combination.rb +1 -1
  16. data/lib/picky/query/combinations.rb +1 -3
  17. data/lib/picky/query/indexes.rb +1 -1
  18. data/lib/picky/query/token.rb +44 -23
  19. data/lib/picky/search.rb +2 -0
  20. data/lib/picky/search_facets.rb +3 -1
  21. data/lib/picky/tokenizer.rb +3 -3
  22. data/spec/functional/allocations_uniq_by_definition_spec.rb +19 -14
  23. data/spec/functional/arrays_as_ids_spec.rb +8 -17
  24. data/spec/functional/automatic_segmentation_spec.rb +40 -37
  25. data/spec/functional/custom_delimiters_spec.rb +30 -20
  26. data/spec/functional/no_tokenize_spec.rb +2 -2
  27. data/spec/functional/or_spec.rb +74 -75
  28. data/spec/functional/pool_spec.rb +54 -53
  29. data/spec/functional/realtime_spec.rb +1 -1
  30. data/spec/lib/backends/backend_spec.rb +9 -9
  31. data/spec/lib/backends/sqlite/array_spec.rb +2 -8
  32. data/spec/lib/backends/sqlite/value_spec.rb +2 -2
  33. data/spec/lib/category_indexed_spec.rb +0 -12
  34. data/spec/lib/query/allocation_spec.rb +3 -3
  35. data/spec/lib/query/combinations_spec.rb +0 -17
  36. data/spec/lib/query/token_spec.rb +9 -4
  37. data/spec/lib/tokenizer_spec.rb +3 -3
  38. metadata +20 -21
@@ -22,69 +22,72 @@ describe "automatic splitting" do
22
22
  index
23
23
  end
24
24
 
25
- it 'can split the text automatically' do
26
- automatic_splitter = Picky::Splitters::Automatic.new index[:text]
25
+ context 'splitting the text automatically' do
26
+ let(:automatic_splitter) { Picky::Splitters::Automatic.new index[:text] }
27
27
 
28
28
  # It splits the text correctly.
29
29
  #
30
- automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow']
31
- automatic_splitter.split('purplerain').should == ['purple', 'rain']
32
- automatic_splitter.split('purple').should == ['purple']
30
+ it { automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow'] }
31
+ it { automatic_splitter.split('purplerain').should == ['purple', 'rain'] }
32
+ it { automatic_splitter.split('purple').should == ['purple'] }
33
33
 
34
34
  # When it can't, it splits it using the partial index (correctly).
35
35
  #
36
- automatic_splitter.split('purplerainbo').should == ['purple', 'rain']
37
- automatic_splitter.split('purplerainb').should == ['purple', 'rain']
36
+ it { automatic_splitter.split('purplerainbo').should == ['purple', 'rain'] }
37
+ it { automatic_splitter.split('purplerainb').should == ['purple', 'rain'] }
38
38
  #
39
- automatic_splitter.split('purplerai').should == ['purple']
40
- automatic_splitter.split('purplera').should == ['purple']
41
- automatic_splitter.split('purpler').should == ['purple']
39
+ it { automatic_splitter.split('purplerai').should == ['purple'] }
40
+ it { automatic_splitter.split('purplera').should == ['purple'] }
41
+ it { automatic_splitter.split('purpler').should == ['purple'] }
42
42
  #
43
- automatic_splitter.split('purpl').should == []
44
- automatic_splitter.split('purp').should == []
45
- automatic_splitter.split('pur').should == []
46
- automatic_splitter.split('pu').should == []
47
- automatic_splitter.split('p').should == []
43
+ it { automatic_splitter.split('purpl').should == [] }
44
+ it { automatic_splitter.split('purp').should == [] }
45
+ it { automatic_splitter.split('pur').should == [] }
46
+ it { automatic_splitter.split('pu').should == [] }
47
+ it { automatic_splitter.split('p').should == [] }
48
48
  end
49
49
 
50
- it 'can split text automatically (with partial)' do
51
- automatic_splitter = Picky::Splitters::Automatic.new index[:text], partial: true
50
+ context 'splitting text automatically (with partial)' do
51
+ let(:automatic_splitter) { Picky::Splitters::Automatic.new index[:text], partial: true }
52
52
 
53
53
  # It splits the text correctly.
54
54
  #
55
- automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow']
56
- automatic_splitter.split('purplerain').should == ['purple', 'rain']
57
- automatic_splitter.split('purple').should == ['purple']
55
+ it { automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow'] }
56
+ it { automatic_splitter.split('purplerain').should == ['purple', 'rain'] }
57
+ it { automatic_splitter.split('purple').should == ['purple'] }
58
58
 
59
59
  # When it can't, it splits it using the partial index (correctly).
60
60
  #
61
- automatic_splitter.split('purplerainbo').should == ['purple', 'rain', 'bo']
62
- automatic_splitter.split('purplerainb').should == ['purple', 'rain', 'b']
61
+ it { automatic_splitter.split('purplerainbo').should == ['purple', 'rain', 'bo'] }
62
+ it { automatic_splitter.split('purplerainb').should == ['purple', 'rain', 'b'] }
63
63
  #
64
- automatic_splitter.split('purplerai').should == ['purple', 'rai']
65
- automatic_splitter.split('purplera').should == ['purple', 'ra']
66
- automatic_splitter.split('purpler').should == ['purple'] # No 'r' in partial index.
64
+ it { automatic_splitter.split('purplerai').should == ['purple', 'rai'] }
65
+ it { automatic_splitter.split('purplera').should == ['purple', 'ra'] }
66
+ it { automatic_splitter.split('purpler').should == ['purple'] } # No 'r' in partial index.
67
67
  #
68
- automatic_splitter.split('purpl').should == ['purpl']
69
- automatic_splitter.split('purp').should == ['purp']
70
- automatic_splitter.split('pur').should == [] # No 'pur' in partial index etc.
71
- automatic_splitter.split('pu').should == []
72
- automatic_splitter.split('p').should == []
68
+ it { automatic_splitter.split('purpl').should == ['purpl'] }
69
+ it { automatic_splitter.split('purp').should == ['purp'] }
70
+ it { automatic_splitter.split('pur').should == [] } # No 'pur' in partial index etc.
71
+ it { automatic_splitter.split('pu').should == [] }
72
+ it { automatic_splitter.split('p').should == [] }
73
73
 
74
- try = Picky::Search.new index do
75
- searching splits_text_on: automatic_splitter
74
+ let(:try) do
75
+ splitter = automatic_splitter
76
+ Picky::Search.new index do
77
+ searching splits_text_on: splitter
78
+ end
76
79
  end
77
80
 
78
81
  # Should find the one with all parts.
79
82
  #
80
- try.search('purplerainbow').ids.should == [1]
81
- try.search('sunandrain').ids.should == [5]
83
+ it { try.search('purplerainbow').ids.should == [1] }
84
+ it { try.search('sunandrain').ids.should == [5] }
82
85
 
83
86
  # Common parts are found in multiple examples.
84
87
  #
85
- try.search('colorpurple').ids.should == [4,1]
86
- try.search('bownew').ids.should == [3,1]
87
- try.search('spainisking').ids.should == [6,1]
88
+ it { try.search('colorpurple').ids.should == [4,1] }
89
+ it { try.search('bownew').ids.should == [3,1] }
90
+ it { try.search('spainisking').ids.should == [6,1] }
88
91
  end
89
92
 
90
93
  it 'is fast enough' do
@@ -14,26 +14,34 @@ describe 'custom delimiters' do
14
14
  Picky::Query::Token.qualifiers_delimiter = ','
15
15
  end
16
16
 
17
- it 'offers custom partial delimiters to be set' do
18
- index = Picky::Index.new :custom_delimiters do
19
- category :text1
20
- category :text2
17
+ context 'offers custom partial delimiters to be set' do
18
+ let(:index) do
19
+ index = Picky::Index.new :custom_delimiters do
20
+ category :text1
21
+ category :text2
22
+ end
23
+
24
+ index.add Struct.new(:id, :text1, :text2).new(1, 'hello', 'world')
25
+
26
+ index
21
27
  end
22
-
23
- index.add Struct.new(:id, :text1, :text2).new(1, 'hello', 'world')
24
-
25
- try = Picky::Search.new index
26
- try.search("hell world").ids.should == []
27
- try.search("hell* world").ids.should == [1]
28
- try.search("hello world").ids.should == [1]
28
+ let(:try) { Picky::Search.new index }
29
+
30
+ it { try.search("hell world").ids.should == [] }
31
+ it { try.search("hell* world").ids.should == [1] }
32
+ it { try.search("hello world").ids.should == [1] }
29
33
 
30
- try.search("hell! world").ids.should == []
31
- Picky::Query::Token.partial_character = '!'
32
- try.search("hell! world").ids.should == [1]
34
+ it 'with changed partial character' do
35
+ try.search("hell! world").ids.should == []
36
+ Picky::Query::Token.partial_character = '!'
37
+ try.search("hell! world").ids.should == [1]
38
+ end
33
39
 
34
- try.search('hell!" world').ids.should == []
35
- Picky::Query::Token.no_partial_character = '\?'
36
- try.search('hell!? world').ids.should == []
40
+ it 'with changed no-partial character' do
41
+ try.search('hell!" world').ids.should == []
42
+ Picky::Query::Token.no_partial_character = '\?'
43
+ try.search('hell!? world').ids.should == []
44
+ end
37
45
  end
38
46
 
39
47
  it 'offers custom similar delimiters to be set' do
@@ -52,13 +60,15 @@ describe 'custom delimiters' do
52
60
  try.search("hell? world").ids.should == []
53
61
  Picky::Query::Token.similar_character = '\?'
54
62
  try.search("hell? world").ids.should == [1]
63
+ Picky::Query::Token.no_similar_character = '!'
64
+ try.search("hello?! world!").ids.should == [1]
55
65
 
56
66
  try.search('hell?" world').ids.should == []
57
- Picky::Query::Token.no_partial_character = '!'
58
- try.search('hell?! world').ids.should == []
67
+ Picky::Query::Token.no_partial_character = '\#'
68
+ try.search('hello?# world#').ids.should == [1]
59
69
  end
60
70
 
61
- it 'offers custom similar delimiters to be set' do
71
+ it 'offers custom qualifiers delimiters to be set' do
62
72
  index = Picky::Index.new :custom_delimiters do
63
73
  category :text1, similarity: Picky::Similarity::Soundex.new
64
74
  category :text2
@@ -41,7 +41,7 @@ describe 'Category#tokenize(false)' do
41
41
  index.add thing.new(1, ['already', 'tokenized'])
42
42
  expect do
43
43
  index.add thing.new(2, 'this should fail')
44
- end.to raise_error('You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.')
44
+ end.to raise_error(%Q{undefined method `each' for "this should fail":String. You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.})
45
45
 
46
46
  try = Picky::Search.new index
47
47
 
@@ -56,7 +56,7 @@ describe 'Category#tokenize(false)' do
56
56
  index.add thing.new(1, ['already', 'tokenized'])
57
57
  expect do
58
58
  index.add thing.new(2, 'this should fail')
59
- end.to raise_error('You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.')
59
+ end.to raise_error(%Q{undefined method `each' for "this should fail":String. You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.})
60
60
 
61
61
  try = Picky::Search.new index
62
62
 
@@ -4,101 +4,100 @@ require 'spec_helper'
4
4
  require 'ostruct'
5
5
 
6
6
  describe "OR token" do
7
+
8
+ # We use the same search throughout.
9
+ #
10
+ let(:try) { Picky::Search.new index }
11
+
12
+ context 'simple cases' do
13
+ let(:index) do
14
+ index = Picky::Index.new :or do
15
+ category :text
16
+ end
17
+ thing = OpenStruct.new id: 1, text: "hello ohai"
18
+ other = OpenStruct.new id: 2, text: "hello kthxbye"
7
19
 
8
- it 'handles simple cases' do
9
- index = Picky::Index.new :or do
10
- category :text
20
+ index.add thing
21
+ index.add other
22
+
23
+ index
11
24
  end
12
-
13
- thing = OpenStruct.new id: 1, text: "hello ohai"
14
- other = OpenStruct.new id: 2, text: "hello kthxbye"
15
-
16
- index.add thing
17
- index.add other
18
-
19
- try = Picky::Search.new index
20
-
21
- # With or, or |.
22
- #
23
- try.search("hello text:ohai|text:kthxbye").ids.should == [1, 2]
24
- try.search("hello text:ohai|kthxbye").ids.should == [1, 2]
25
- try.search("hello ohai|text:kthxbye").ids.should == [1, 2]
26
- try.search("hello ohai|kthxbye").ids.should == [1, 2]
27
-
28
- # Still works.
29
- #
30
- try.search("hello text:ohai").ids.should == [1]
25
+ it { try.search("hello text:ohai|text:kthxbye").ids.should == [1, 2] }
26
+ it { try.search("hello text:ohai|kthxbye").ids.should == [1, 2] }
27
+ it { try.search("hello ohai|text:kthxbye").ids.should == [1, 2] }
28
+ it { try.search("hello ohai|kthxbye").ids.should == [1, 2] }
29
+ it('still works') { try.search("hello text:ohai").ids.should == [1] }
31
30
  end
32
31
 
33
- it 'handles more complex cases' do
34
- index = Picky::Index.new :or do
35
- category :text1
36
- category :text2
37
- end
32
+ context 'more complex cases' do
33
+ let(:index) do
34
+ index = Picky::Index.new :or do
35
+ category :text1
36
+ category :text2
37
+ end
38
38
 
39
- thing = OpenStruct.new id: 1, text1: "hello world", text2: "ohai kthxbye"
40
- other = OpenStruct.new id: 2, text1: "hello something else", text2: "to be or not to be"
39
+ thing = OpenStruct.new id: 1, text1: "hello world", text2: "ohai kthxbye"
40
+ other = OpenStruct.new id: 2, text1: "hello something else", text2: "to be or not to be"
41
41
 
42
- index.add thing
43
- index.add other
44
-
45
- try = Picky::Search.new index
42
+ index.add thing
43
+ index.add other
44
+
45
+ index
46
+ end
46
47
 
47
- # With or, or |.
48
- #
49
48
  # Note that the order is changed.
50
49
  #
51
- try.search("hello ohai|not").ids.should == [1, 2]
52
- try.search("hello not|ohai").ids.should == [2, 1]
53
- try.search("hello ohai|kthxbye").ids.should == [1]
54
- try.search("hello nonexisting|not").ids.should == [2]
55
- try.search("hello nonexisting|alsononexisting").ids.should == []
56
- try.search("hello text1:world|text2:not|text2:kthxbye").ids.should == [1, 2]
50
+ it { try.search("hello ohai|not").ids.should == [1, 2] }
51
+ it { try.search("hello not|ohai").ids.should == [2, 1] }
52
+ it { try.search("hello ohai|kthxbye").ids.should == [1] }
53
+ it { try.search("hello nonexisting|not").ids.should == [2] }
54
+ it { try.search("hello nonexisting|alsononexisting").ids.should == [] }
55
+ it { try.search("hello text1:world|text2:not|text2:kthxbye").ids.should == [1, 2] }
57
56
  end
58
57
 
59
- it 'handles even more complex cases' do
60
- index = Picky::Index.new :or do
61
- category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
62
- end
58
+ context 'even more complex cases' do
59
+ let(:index) do
60
+ index = Picky::Index.new :or do
61
+ category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
62
+ end
63
63
 
64
- thing = OpenStruct.new id: 1, text: "hello ohai tester 13"
65
- other = OpenStruct.new id: 2, text: "hello kthxbye"
64
+ thing = OpenStruct.new id: 1, text: "hello ohai tester 13"
65
+ other = OpenStruct.new id: 2, text: "hello kthxbye"
66
66
 
67
- index.add thing
68
- index.add other
67
+ index.add thing
68
+ index.add other
69
69
 
70
- try = Picky::Search.new index
70
+ index
71
+ end
71
72
 
72
- # With or, or |.
73
- #
74
- try.search("something,other:ohai").ids.should == []
75
- try.search("text:taster~|text:kthxbye hello").ids.should == [2, 1]
76
- try.search("text:test*|kthxbye hello").ids.should == [2, 1]
77
- try.search("text:11-15|kthxbye hello").ids.should == [2, 1]
78
- try.search("hello text,other:ohai|text:kthxbye").ids.should == [1, 2]
79
- try.search("hello something,other:ohai|kthxbye").ids.should == [2]
80
- try.search("hello text:oh*|text:kthxbya~").ids.should == [1, 2]
73
+ it { try.search("something,other:ohai").ids.should == [] }
74
+ it { try.search("text:taster~|text:kthxbye hello").ids.should == [2, 1] }
75
+ it { try.search("text:test*|kthxbye hello").ids.should == [2, 1] }
76
+ it { try.search("text:11-15|kthxbye hello").ids.should == [2, 1] }
77
+ it { try.search("hello text,other:ohai|text:kthxbye").ids.should == [1, 2] }
78
+ it { try.search("hello something,other:ohai|kthxbye").ids.should == [2] }
79
+ it { try.search("hello text:oh*|text:kthxbya~").ids.should == [1, 2] }
81
80
  end
82
81
 
83
- it 'handles multi-ORs' do
84
- index = Picky::Index.new :or do
85
- category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
86
- end
87
-
88
- thing = OpenStruct.new id: 1, text: "that thing"
89
- something = OpenStruct.new id: 2, text: "and something"
90
- other = OpenStruct.new id: 3, text: "or other"
82
+ context 'multi-ORs' do
83
+ let(:index) do
84
+ index = Picky::Index.new :or do
85
+ category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
86
+ end
91
87
 
92
- index.add thing
93
- index.add something
94
- index.add other
88
+ thing = OpenStruct.new id: 1, text: "that thing"
89
+ something = OpenStruct.new id: 2, text: "and something"
90
+ other = OpenStruct.new id: 3, text: "or other"
95
91
 
96
- try = Picky::Search.new index
92
+ index.add thing
93
+ index.add something
94
+ index.add other
95
+
96
+ index
97
+ end
97
98
 
98
- # With or, or |.
99
- #
100
- try.search("thing|something|other").ids.should == [1, 2, 3]
101
- try.search("something|other").ids.should == [2, 3]
99
+ it { try.search("thing|something|other").ids.should == [1, 2, 3] }
100
+ it { try.search("something|other").ids.should == [2, 3] }
102
101
  end
103
102
 
104
103
  end
@@ -30,58 +30,59 @@ describe 'GC stats: searching' do
30
30
 
31
31
  # TODO Why are both versions almost equally fast?
32
32
  #
33
- context 'without pool' do
34
- # TODO Reinstate after checking assumption about Ruby 2.
35
- #
36
- # it 'runs the GC more' do
37
- # # Quickly check if the pool is removed.
38
- # #
39
- # fail 'object pool still installed' if Picky::Query::Token.respond_to? :release_all
40
- #
41
- # try = search
42
- # query = 'abracadabra mirgel'
43
- # gc_runs_of do
44
- # amount.times { try.search query }
45
- # end.should >= 10
46
- # end
47
- it 'is less (?) performant' do
48
- try = search
49
- query = 'abracadabra mirgel'
50
- performance_of do
51
- amount.times { try.search query }
52
- end.should >= 0.15
53
- end
54
- end
55
- context 'with pool' do
56
- before(:each) do
57
- Picky::Pool.install
58
- end
59
- after(:each) do
60
- # Reload since installing the Pool taints the classes.
61
- #
62
- Picky::Loader.load_framework
63
- end
64
- it 'runs the GC less' do
65
- # Quickly check that the pool is added.
66
- #
67
- fail 'object pool not installed' unless Picky::Query::Token.respond_to? :release_all
68
-
69
- try = search
70
- query = 'abracadabra mirgel'
71
- gc_runs_of do
72
- amount.times do
73
- try.search query
74
- Picky::Pool.release_all
75
- end
76
- end.should <= 1 # Definitely less GC runs.
77
- end
78
- it 'is more (?) performant' do
79
- try = search
80
- query = 'abracadabra mirgel'
81
- performance_of do
82
- amount.times { try.search query }
83
- end.should <= 0.2
84
- end
85
- end
33
+ # context 'without pool' do
34
+ # it 'runs the GC more' do
35
+ # # Quickly check if the pool is removed.
36
+ # #
37
+ # fail 'object pool still installed' if Picky::Query::Token.respond_to? :release_all
38
+ #
39
+ # try = search
40
+ # query = 'abracadabra mirgel'
41
+ # gc_runs_of do
42
+ # amount.times { try.search query }
43
+ # end.should >= 10
44
+ # end
45
+ # it 'is less (?) performant' do
46
+ # try = search
47
+ # query = 'abracadabra mirgel'
48
+ # performance_of do
49
+ # amount.times { try.search query }
50
+ # end.should <= 0.15
51
+ # end
52
+ # end
53
+ # context 'with pool' do
54
+ # before(:each) do
55
+ # Picky::Pool.install
56
+ # end
57
+ # after(:each) do
58
+ # # Reload since installing the Pool taints the classes.
59
+ # #
60
+ # Picky::Loader.load_framework
61
+ # end
62
+ # it 'runs the GC less' do
63
+ # # Quickly check that the pool is added.
64
+ # #
65
+ # fail 'object pool not installed' unless Picky::Query::Token.respond_to? :release_all
66
+ #
67
+ # try = search
68
+ # query = 'abracadabra mirgel'
69
+ # gc_runs_of do
70
+ # amount.times do |i|
71
+ # try.search query
72
+ # Picky::Pool.release_all if i % 5 == 0
73
+ # end
74
+ # end.should <= 1 # Definitely less GC runs.
75
+ # end
76
+ # it 'is more (?) performant' do
77
+ # try = search
78
+ # query = 'abracadabra it whatever mirgel'
79
+ # performance_of do
80
+ # amount.times do |i|
81
+ # try.search query
82
+ # Picky::Pool.release_all if i % 5 == 0
83
+ # end
84
+ # end.should <= 0.2
85
+ # end
86
+ # end
86
87
 
87
88
  end
@@ -478,7 +478,7 @@ describe "Realtime Indexing" do
478
478
  let(:index) do
479
479
  Picky::Index.new(:books) do
480
480
  backend Picky::Backends::Redis.new(realtime: true)
481
- key_format :to_s # TODO Make key format dependent on backend?
481
+ key_format :to_s
482
482
  category :title
483
483
  category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
484
484
  end
@@ -4,15 +4,15 @@ describe Picky::Backends::Backend do
4
4
 
5
5
  let(:backend) { described_class.new }
6
6
 
7
- describe 'weight' do
8
- it 'forwards to the parameter' do
9
- combinations = stub :combinations
10
-
11
- combinations.should_receive(:score).once.with()
12
-
13
- backend.weight combinations
14
- end
15
- end
7
+ # describe 'score' do
8
+ # it 'forwards to the parameter' do
9
+ # combinations = stub :combinations
10
+ #
11
+ # combinations.should_receive(:score).once.with()
12
+ #
13
+ # backend.score combinations
14
+ # end
15
+ # end
16
16
 
17
17
  describe 'to_s' do
18
18
  it 'is correct' do
@@ -25,19 +25,16 @@ describe Picky::Backends::SQLite::Array do
25
25
  it 'initializes the client' do
26
26
  client.stub! :execute
27
27
 
28
- db.should_receive(:lazily_initialize_client).once.with
28
+ db.should_receive(:db).exactly(4).times.with
29
29
 
30
30
  db.dump_sqlite Hash.new
31
31
  end
32
32
  it 'executes something' do
33
- db.stub! :lazily_initialize_client
34
-
35
33
  client.should_receive(:execute).at_least(1).times
36
34
 
37
35
  db.dump_sqlite Hash.new
38
36
  end
39
37
  it 'inserts keys and values' do
40
- db.stub! :lazily_initialize_client
41
38
  client.stub! :execute # We only want to test the insert statements.
42
39
 
43
40
  client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
@@ -93,19 +90,16 @@ describe Picky::Backends::SQLite::Array do
93
90
  it 'initializes the client' do
94
91
  client.stub! :execute
95
92
 
96
- db.should_receive(:lazily_initialize_client).once.with
93
+ db.should_receive(:db).exactly(4).times.with
97
94
 
98
95
  db.dump_sqlite Hash.new
99
96
  end
100
97
  it 'executes something' do
101
- db.stub! :lazily_initialize_client
102
-
103
98
  client.should_receive(:execute).at_least(1).times
104
99
 
105
100
  db.dump_sqlite Hash.new
106
101
  end
107
102
  it 'inserts keys and values' do
108
- db.stub! :lazily_initialize_client
109
103
  client.stub! :execute # We only want to test the insert statements.
110
104
 
111
105
  client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
@@ -25,7 +25,7 @@ describe Picky::Backends::SQLite::Value do
25
25
  it 'initializes the client' do
26
26
  client.stub! :execute
27
27
 
28
- db.should_receive(:lazily_initialize_client).once.with
28
+ db.should_receive(:db).exactly(4).times.with
29
29
 
30
30
  db.dump_sqlite Hash.new
31
31
  end
@@ -37,7 +37,7 @@ describe Picky::Backends::SQLite::Value do
37
37
  db.dump_sqlite Hash.new
38
38
  end
39
39
  it 'inserts keys and values' do
40
- db.stub! :lazily_initialize_client
40
+ # db.stub! :db
41
41
  client.stub! :execute # We only want to test the insert statements.
42
42
 
43
43
  client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
@@ -212,18 +212,6 @@ describe Picky::Category do
212
212
  @category.stub! :exact => (@exact = stub :exact)
213
213
  @category.stub! :partial => (@partial = stub :partial)
214
214
  end
215
- describe 'bundle_for' do
216
- it 'should return the right bundle' do
217
- token = stub :token, :partial? => false
218
-
219
- @category.bundle_for(token).should == @exact
220
- end
221
- it 'should return the right bundle' do
222
- token = stub :token, :partial? => true
223
-
224
- @category.bundle_for(token).should == @partial
225
- end
226
- end
227
215
 
228
216
  describe 'load' do
229
217
  it 'should call two methods' do
@@ -184,10 +184,10 @@ describe Picky::Query::Allocation do
184
184
  describe "calculate_score" do
185
185
  context 'non-empty combinations' do
186
186
  it 'should forward to backend and combinations' do
187
- @backend.should_receive(:weight).once.with(@combinations).and_return 1
188
- @combinations.should_receive(:boost_for).once.with(:some_boosts).and_return 2
187
+ @combinations.should_receive(:score).once.and_return 1
188
+ weights = stub :weights, :boost_for => 2
189
189
 
190
- @allocation.calculate_score(:some_boosts).should == 3
190
+ @allocation.calculate_score(weights).should == 3
191
191
  end
192
192
  end
193
193
  end