picky 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/lib/picky/analyzer.rb +4 -4
  2. data/lib/picky/application.rb +6 -7
  3. data/lib/picky/backend/{backend.rb → base.rb} +31 -14
  4. data/lib/picky/backend/file/basic.rb +12 -4
  5. data/lib/picky/backend/file/json.rb +5 -5
  6. data/lib/picky/backend/file/text.rb +1 -1
  7. data/lib/picky/backend/files.rb +3 -9
  8. data/lib/picky/backend/redis/basic.rb +8 -0
  9. data/lib/picky/backend/redis/list_hash.rb +5 -5
  10. data/lib/picky/backend/redis/string_hash.rb +5 -5
  11. data/lib/picky/backend/redis.rb +5 -5
  12. data/lib/picky/bundle.rb +62 -0
  13. data/lib/picky/categories.rb +10 -9
  14. data/lib/picky/categories_indexed.rb +12 -7
  15. data/lib/picky/categories_indexing.rb +7 -9
  16. data/lib/picky/category.rb +38 -26
  17. data/lib/picky/category_indexed.rb +4 -20
  18. data/lib/picky/category_indexing.rb +71 -68
  19. data/lib/picky/generators/base.rb +6 -6
  20. data/lib/picky/generators/partial/substring.rb +28 -26
  21. data/lib/picky/generators/partial_generator.rb +3 -3
  22. data/lib/picky/generators/similarity/phonetic.rb +5 -5
  23. data/lib/picky/generators/similarity_generator.rb +2 -2
  24. data/lib/picky/generators/weights/logarithmic.rb +3 -3
  25. data/lib/picky/generators/weights_generator.rb +2 -2
  26. data/lib/picky/index/base.rb +13 -10
  27. data/lib/picky/index/base_indexed.rb +2 -0
  28. data/lib/picky/index/base_indexing.rb +65 -57
  29. data/lib/picky/indexed/bundle/base.rb +21 -86
  30. data/lib/picky/indexed/bundle/memory.rb +5 -12
  31. data/lib/picky/indexed/bundle/redis.rb +42 -0
  32. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +3 -3
  33. data/lib/picky/indexers/base.rb +20 -3
  34. data/lib/picky/indexers/parallel.rb +32 -14
  35. data/lib/picky/indexers/serial.rb +29 -26
  36. data/lib/picky/indexes.rb +5 -3
  37. data/lib/picky/indexes_indexed.rb +3 -15
  38. data/lib/picky/indexes_indexing.rb +18 -21
  39. data/lib/picky/indexing/bundle/base.rb +64 -45
  40. data/lib/picky/indexing/bundle/memory.rb +0 -4
  41. data/lib/picky/loader.rb +7 -6
  42. data/lib/picky/query/allocation.rb +3 -3
  43. data/lib/picky/query/token.rb +5 -1
  44. data/lib/picky/search.rb +5 -0
  45. data/lib/picky/sources/base.rb +21 -2
  46. data/lib/picky/sources/db.rb +0 -7
  47. data/lib/picky/statistics.rb +9 -12
  48. data/lib/picky/tokenizers/location.rb +1 -1
  49. data/lib/tasks/checks.rake +8 -6
  50. data/lib/tasks/index.rake +14 -20
  51. data/lib/tasks/server.rake +18 -2
  52. data/lib/tasks/statistics.rake +27 -14
  53. data/lib/tasks/todo.rake +2 -2
  54. data/lib/tasks/try.rake +12 -27
  55. data/spec/lib/application_spec.rb +1 -1
  56. data/spec/lib/backend/file/basic_spec.rb +6 -6
  57. data/spec/lib/backend/file/json_spec.rb +11 -6
  58. data/spec/lib/backend/file/marshal_spec.rb +11 -6
  59. data/spec/lib/backend/files_spec.rb +21 -7
  60. data/spec/lib/backend/redis/basic_spec.rb +6 -0
  61. data/spec/lib/backend/redis/list_hash_spec.rb +9 -3
  62. data/spec/lib/backend/redis/string_hash_spec.rb +7 -1
  63. data/spec/lib/backend/redis_spec.rb +22 -12
  64. data/spec/lib/categories_indexed_spec.rb +2 -2
  65. data/spec/lib/category_indexing_spec.rb +12 -33
  66. data/spec/lib/category_spec.rb +22 -0
  67. data/spec/lib/index/base_indexing_spec.rb +30 -0
  68. data/spec/lib/indexed/bundle/memory_spec.rb +13 -20
  69. data/spec/lib/indexers/base_spec.rb +39 -4
  70. data/spec/lib/indexers/parallel_spec.rb +2 -10
  71. data/spec/lib/indexers/serial_spec.rb +11 -26
  72. data/spec/lib/indexes_class_spec.rb +4 -4
  73. data/spec/lib/indexes_indexed_spec.rb +2 -2
  74. data/spec/lib/indexes_indexing_spec.rb +6 -10
  75. data/spec/lib/indexes_spec.rb +3 -3
  76. data/spec/lib/indexing/bundle/{super_base_spec.rb → base_spec.rb} +2 -2
  77. data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +3 -3
  78. data/spec/lib/indexing/bundle/memory_spec.rb +16 -14
  79. data/spec/lib/indexing/bundle/redis_spec.rb +18 -16
  80. data/spec/lib/query/allocation_spec.rb +1 -1
  81. data/spec/lib/query/token_spec.rb +5 -7
  82. data/spec/lib/sources/base_spec.rb +53 -0
  83. data/spec/lib/sources/db_spec.rb +0 -7
  84. metadata +11 -12
  85. data/lib/picky/indexers/solr.rb +0 -56
  86. data/lib/picky/indexing/bundle/super_base.rb +0 -61
  87. data/lib/picky/solr/schema_generator.rb +0 -74
  88. data/lib/tasks/search.rake +0 -9
  89. data/lib/tasks/shortcuts.rake +0 -32
  90. data/lib/tasks/solr.rake +0 -36
@@ -2,14 +2,49 @@ require 'spec_helper'
2
2
 
3
3
  describe Indexers::Base do
4
4
 
5
- let(:indexer) { described_class.new }
5
+ let(:some_index_or_category) { stub :some_index_or_category, :name => 'some index or category' }
6
+ let(:indexer) { described_class.new some_index_or_category }
7
+
8
+ describe 'index_or_category' do
9
+ it 'returns the right thing' do
10
+ indexer.index_or_category.should == some_index_or_category
11
+ end
12
+ end
13
+
14
+ describe 'source' do
15
+ it 'delegates it to the index or category' do
16
+ some_index_or_category.should_receive(:source).once.with
17
+
18
+ indexer.source
19
+ end
20
+ end
6
21
 
7
22
  describe 'index' do
8
23
  it 'messages, then processed' do
9
- indexer.should_receive(:indexing_message).once.with.ordered
10
- indexer.should_receive(:process).once.with.ordered
24
+ indexer.should_receive(:start_indexing_message).once.with.ordered
25
+ indexer.should_receive(:prepare).once.with(:categories).ordered
26
+ indexer.should_receive(:process).once.with(:categories).ordered
27
+ indexer.should_receive(:finish_indexing_message).once.with.ordered
28
+
29
+ indexer.index :categories
30
+ end
31
+ end
32
+
33
+ describe 'prepare' do
34
+ it 'calls a certain method on each category' do
35
+ some_index_or_category.stub! :source
36
+
37
+ category1 = stub :category1
38
+ category2 = stub :category2
39
+ category3 = stub :category3
40
+
41
+ categories = [category1, category2, category3]
42
+
43
+ categories.each do |category|
44
+ category.should_receive(:prepare_index_directory).once.with
45
+ end
11
46
 
12
- indexer.index
47
+ indexer.prepare categories
13
48
  end
14
49
  end
15
50
 
@@ -4,9 +4,9 @@ describe Indexers::Parallel do
4
4
 
5
5
  before(:each) do
6
6
  @source = stub :source
7
- @tokenizer = stub :tokenizer
7
+ @index = stub :index, :name => :some_index, :source => @source
8
+
8
9
  @categories = stub :categories
9
- @index = stub :index, :name => :some_index, :categories => @categories
10
10
 
11
11
  @indexer = described_class.new @index
12
12
  @indexer.stub! :timed_exclaim
@@ -25,12 +25,4 @@ describe Indexers::Parallel do
25
25
  end
26
26
  end
27
27
 
28
- describe "index" do
29
- it "should process" do
30
- @indexer.should_receive(:process).once.with
31
-
32
- @indexer.index
33
- end
34
- end
35
-
36
28
  end
@@ -5,39 +5,28 @@ describe Indexers::Serial do
5
5
  before(:each) do
6
6
  @tokenizer = stub :tokenizer
7
7
  @source = stub :source
8
- @category = stub :category, :identifier => :some_identifier, :tokenizer => @tokenizer, :source => @source
8
+ @category = stub :category,
9
+ :identifier => :some_identifier,
10
+ :tokenizer => @tokenizer,
11
+ :source => @source
9
12
 
10
13
  @indexer = described_class.new @category
11
14
  @indexer.stub! :timed_exclaim
12
15
  end
13
16
 
14
- describe "tokenizer" do
15
- it "returns the right one" do
16
- @indexer.tokenizer.should == @tokenizer
17
- end
18
- end
19
-
20
- describe "indexing_message" do
17
+ describe "start_indexing_message" do
21
18
  it "informs the user about what it is going to index" do
22
- @indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Starting serial indexing.'
19
+ @indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Starting serial data preparation.'
23
20
 
24
- @indexer.indexing_message
21
+ @indexer.start_indexing_message
25
22
  end
26
23
  end
27
24
 
28
- describe "tokenizer" do
29
- it "returns it" do
30
- @indexer.should_receive(:tokenizer).once.with
31
-
32
- @indexer.tokenizer
33
- end
34
- end
35
-
36
- describe "index" do
37
- it "should process" do
38
- @indexer.should_receive(:process).once.with
25
+ describe "finish_indexing_message" do
26
+ it "informs the user about what it is going to index" do
27
+ @indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Finished serial data preparation.'
39
28
 
40
- @indexer.index
29
+ @indexer.finish_indexing_message
41
30
  end
42
31
  end
43
32
 
@@ -47,8 +36,4 @@ describe Indexers::Serial do
47
36
  end
48
37
  end
49
38
 
50
- describe "chunked" do
51
-
52
- end
53
-
54
39
  end
@@ -7,11 +7,11 @@ describe Indexes do
7
7
  @indexes = described_class.instance
8
8
  end
9
9
 
10
- describe 'clear' do
10
+ describe 'clear_indexes' do
11
11
  it 'clears the indexes' do
12
- Indexes.register @index
12
+ @indexes.register @index
13
13
 
14
- Indexes.clear
14
+ @indexes.clear_indexes
15
15
 
16
16
  @indexes.indexes.should == []
17
17
  end
@@ -19,7 +19,7 @@ describe Indexes do
19
19
 
20
20
  describe 'register' do
21
21
  it 'adds the given index to the indexes' do
22
- Indexes.clear
22
+ @indexes.clear_indexes
23
23
 
24
24
  Indexes.register @index
25
25
 
@@ -38,12 +38,12 @@ describe Indexes do
38
38
  end
39
39
  describe 'clear' do
40
40
  it 'clears the indexes' do
41
- indexes.clear
41
+ indexes.clear_indexes
42
42
 
43
43
  indexes.indexes.should == []
44
44
  end
45
45
  it 'clears the mapping' do
46
- indexes.clear
46
+ indexes.clear_indexes
47
47
 
48
48
  indexes.index_mapping.should == {}
49
49
  end
@@ -21,7 +21,6 @@ describe Indexes do
21
21
  end
22
22
  describe 'index_for_tests' do
23
23
  it 'takes a snapshot, then indexes and caches each' do
24
- indexes.should_receive(:take_snapshot).once.with.ordered
25
24
  @index1.should_receive(:index).once.with.ordered
26
25
  @index2.should_receive(:index).once.with.ordered
27
26
 
@@ -33,9 +32,9 @@ describe Indexes do
33
32
  indexes.indexes.should == [@index1, @index2]
34
33
  end
35
34
  end
36
- describe 'clear' do
35
+ describe 'clear_indexes' do
37
36
  it 'clears the indexes' do
38
- indexes.clear
37
+ indexes.clear_indexes
39
38
 
40
39
  indexes.indexes.should == []
41
40
  end
@@ -50,13 +49,10 @@ describe Indexes do
50
49
  end
51
50
  end
52
51
  end
53
- it_delegates_each :take_snapshot
54
- it_delegates_each :generate_caches
55
- it_delegates_each :backup_caches
56
- it_delegates_each :restore_caches
57
- it_delegates_each :check_caches
58
- it_delegates_each :clear_caches
59
- it_delegates_each :create_directory_structure
52
+ it_delegates_each :check
53
+ it_delegates_each :clear
54
+ it_delegates_each :backup
55
+ it_delegates_each :restore
60
56
  end
61
57
 
62
58
  end
@@ -16,11 +16,11 @@ describe Indexes do
16
16
  end
17
17
  end
18
18
 
19
- describe 'clear' do
19
+ describe 'clear_indexes' do
20
20
  it 'clears the indexes' do
21
21
  @indexes.register @index
22
22
 
23
- @indexes.clear
23
+ @indexes.clear_indexes
24
24
 
25
25
  @indexes.indexes.should == []
26
26
  end
@@ -28,7 +28,7 @@ describe Indexes do
28
28
 
29
29
  describe 'register' do
30
30
  it 'adds the given index to the indexes' do
31
- @indexes.clear
31
+ @indexes.clear_indexes
32
32
 
33
33
  @indexes.register @index
34
34
 
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexing::Bundle::SuperBase do
3
+ describe Indexing::Bundle::Base do
4
4
 
5
5
  before(:each) do
6
6
  @configuration = stub :configuration, :identifier => 'some_identifier'
7
7
  Backend::Files.stub! :new
8
8
  @similarity = Similarity::DoubleMetaphone.new 3
9
- @bundle = described_class.new :some_name, @configuration, @similarity
9
+ @bundle = described_class.new :some_name, @configuration, :some_weights, :some_partial, @similarity
10
10
  end
11
11
 
12
12
  describe 'identifier' do
@@ -27,9 +27,9 @@ describe Indexing::Bundle::Memory do
27
27
  describe 'speed' do
28
28
  context 'medium arrays' do
29
29
  before(:each) do
30
- random_keys = generate_random_keys 300
31
- random_ids = generate_random_ids 300
32
- @exact.index = Hash[random_keys.zip(random_ids)]
30
+ random_keys = generate_random_keys 300
31
+ random_ids = generate_random_ids 300
32
+ @exact.inverted = Hash[random_keys.zip(random_ids)]
33
33
  end
34
34
  it 'should be fast' do
35
35
  performance_of do
@@ -10,19 +10,19 @@ describe Indexing::Bundle::Memory do
10
10
  @weights = stub :weights
11
11
  @similarity = stub :similarity
12
12
  end
13
- let(:index) { described_class.new :some_name, @category, @similarity, @partial, @weights }
13
+ let(:index) { described_class.new :some_name, @category, @weights, @partial, @similarity }
14
14
 
15
15
  describe 'raise_cache_missing' do
16
16
  it 'does something' do
17
17
  expect {
18
18
  index.raise_cache_missing :similarity
19
- }.to raise_error("Error: The similarity cache for some_index:some_category:some_name is missing.")
19
+ }.to raise_error("Error: The similarity cache for test:some_index:some_category:some_name is missing.")
20
20
  end
21
21
  end
22
22
 
23
23
  describe 'warn_cache_small' do
24
24
  it 'warns the user' do
25
- index.should_receive(:warn).once.with "Warning: similarity cache for some_index:some_category:some_name smaller than 16 bytes."
25
+ index.should_receive(:warn).once.with "Warning: similarity cache for test:some_index:some_category:some_name smaller than 16 bytes."
26
26
 
27
27
  index.warn_cache_small :similarity
28
28
  end
@@ -30,7 +30,7 @@ describe Indexing::Bundle::Memory do
30
30
 
31
31
  describe 'identifier' do
32
32
  it 'should return a specific identifier' do
33
- index.identifier.should == 'some_index:some_category:some_name'
33
+ index.identifier.should == 'test:some_index:some_category:some_name'
34
34
  end
35
35
  end
36
36
 
@@ -40,9 +40,9 @@ describe Indexing::Bundle::Memory do
40
40
  index.stub! :index => {}
41
41
  end
42
42
  it 'should assign it an empty array' do
43
- index.initialize_index_for :some_token
43
+ index.initialize_inverted_index_for :some_token
44
44
 
45
- index.index[:some_token].should == []
45
+ index.inverted[:some_token].should == []
46
46
  end
47
47
  end
48
48
  context 'token already assigned' do
@@ -50,7 +50,7 @@ describe Indexing::Bundle::Memory do
50
50
  index.stub! :index => { :some_token => :already_assigned }
51
51
  end
52
52
  it 'should not assign it anymore' do
53
- index.initialize_index_for :some_token
53
+ index.initialize_inverted_index_for :some_token
54
54
 
55
55
  index.index[:some_token].should == :already_assigned
56
56
  end
@@ -64,8 +64,8 @@ describe Indexing::Bundle::Memory do
64
64
  index.stub! :files => files
65
65
 
66
66
  @ary = stub :ary
67
- @index.should_receive(:[]).any_number_of_times.and_return @ary
68
- index.stub! :index => @index
67
+ inverted = stub :inverted, :[] => @ary
68
+ index.stub! :inverted => inverted
69
69
  end
70
70
  context 'id key format' do
71
71
  before(:each) do
@@ -101,11 +101,11 @@ describe Indexing::Bundle::Memory do
101
101
 
102
102
  describe 'load_from_index_file' do
103
103
  it 'should call two methods in order' do
104
- index.should_receive(:load_from_index_generation_message).once.ordered
104
+ index.should_receive(:load_from_prepared_index_generation_message).once.ordered
105
105
  index.should_receive(:clear).once.ordered
106
106
  index.should_receive(:retrieve).once.ordered
107
107
 
108
- index.load_from_index_file
108
+ index.load_from_prepared_index_file
109
109
  end
110
110
  end
111
111
 
@@ -129,7 +129,7 @@ describe Indexing::Bundle::Memory do
129
129
 
130
130
  describe 'generate_caches_from_source' do
131
131
  it 'should call two methods in order' do
132
- index.should_receive(:load_from_index_file).once.ordered
132
+ index.should_receive(:load_from_prepared_index_file).once.ordered
133
133
  index.should_receive(:generate_caches_from_memory).once.ordered
134
134
 
135
135
  index.generate_caches_from_source
@@ -138,7 +138,9 @@ describe Indexing::Bundle::Memory do
138
138
 
139
139
  describe 'dump' do
140
140
  it 'should trigger dumps' do
141
- index.should_receive(:dump_index).once.with
141
+ index.stub! :timed_exclaim
142
+
143
+ index.should_receive(:dump_inverted).once.with
142
144
  index.should_receive(:dump_weights).once.with
143
145
  index.should_receive(:dump_similarity).once.with
144
146
  index.should_receive(:dump_configuration).once.with
@@ -260,7 +262,7 @@ describe Indexing::Bundle::Memory do
260
262
 
261
263
  describe 'initialization' do
262
264
  it 'should initialize the index correctly' do
263
- index.index.should == {}
265
+ index.inverted.should == {}
264
266
  end
265
267
  it 'should initialize the weights index correctly' do
266
268
  index.weights.should == {}
@@ -10,19 +10,19 @@ describe Indexing::Bundle::Redis do
10
10
  @weights = stub :weights
11
11
  @similarity = stub :similarity
12
12
  end
13
- let(:index) { described_class.new :some_name, @category, @similarity, @partial, @weights }
13
+ let(:index) { described_class.new :some_name, @category, @weights, @partial, @similarity }
14
14
 
15
15
  describe 'raise_cache_missing' do
16
16
  it 'does something' do
17
17
  expect {
18
18
  index.raise_cache_missing :similarity
19
- }.to raise_error("Error: The similarity cache for some_index:some_category:some_name is missing.")
19
+ }.to raise_error("Error: The similarity cache for test:some_index:some_category:some_name is missing.")
20
20
  end
21
21
  end
22
22
 
23
23
  describe 'warn_cache_small' do
24
24
  it 'warns the user' do
25
- index.should_receive(:warn).once.with "Warning: similarity cache for some_index:some_category:some_name smaller than 16 bytes."
25
+ index.should_receive(:warn).once.with "Warning: similarity cache for test:some_index:some_category:some_name smaller than 16 bytes."
26
26
 
27
27
  index.warn_cache_small :similarity
28
28
  end
@@ -30,19 +30,19 @@ describe Indexing::Bundle::Redis do
30
30
 
31
31
  describe 'identifier' do
32
32
  it 'should return a specific identifier' do
33
- index.identifier.should == 'some_index:some_category:some_name'
33
+ index.identifier.should == 'test:some_index:some_category:some_name'
34
34
  end
35
35
  end
36
36
 
37
37
  describe 'initialize_index_for' do
38
38
  context 'token not yet assigned' do
39
39
  before(:each) do
40
- index.stub! :index => {}
40
+ index.stub! :inverted => {}
41
41
  end
42
42
  it 'should assign it an empty array' do
43
- index.initialize_index_for :some_token
43
+ index.initialize_inverted_index_for :some_token
44
44
 
45
- index.index[:some_token].should == []
45
+ index.inverted[:some_token].should == []
46
46
  end
47
47
  end
48
48
  context 'token already assigned' do
@@ -50,7 +50,7 @@ describe Indexing::Bundle::Redis do
50
50
  index.stub! :index => { :some_token => :already_assigned }
51
51
  end
52
52
  it 'should not assign it anymore' do
53
- index.initialize_index_for :some_token
53
+ index.initialize_inverted_index_for :some_token
54
54
 
55
55
  index.index[:some_token].should == :already_assigned
56
56
  end
@@ -64,8 +64,8 @@ describe Indexing::Bundle::Redis do
64
64
  index.stub! :files => files
65
65
 
66
66
  @ary = stub :ary
67
- @index.should_receive(:[]).any_number_of_times.and_return @ary
68
- index.stub! :index => @index
67
+ inverted = stub :inverted, :[] => @ary
68
+ index.stub! :inverted => inverted
69
69
  end
70
70
  context 'id key format' do
71
71
  before(:each) do
@@ -99,13 +99,13 @@ describe Indexing::Bundle::Redis do
99
99
  end
100
100
  end
101
101
 
102
- describe 'load_from_index_file' do
102
+ describe 'load_from_prepared_index_file' do
103
103
  it 'should call two methods in order' do
104
- index.should_receive(:load_from_index_generation_message).once.ordered
104
+ index.should_receive(:load_from_prepared_index_generation_message).once.ordered
105
105
  index.should_receive(:clear).once.ordered
106
106
  index.should_receive(:retrieve).once.ordered
107
107
 
108
- index.load_from_index_file
108
+ index.load_from_prepared_index_file
109
109
  end
110
110
  end
111
111
 
@@ -129,7 +129,7 @@ describe Indexing::Bundle::Redis do
129
129
 
130
130
  describe 'generate_caches_from_source' do
131
131
  it 'should call two methods in order' do
132
- index.should_receive(:load_from_index_file).once.ordered
132
+ index.should_receive(:load_from_prepared_index_file).once.ordered
133
133
  index.should_receive(:generate_caches_from_memory).once.ordered
134
134
 
135
135
  index.generate_caches_from_source
@@ -138,7 +138,9 @@ describe Indexing::Bundle::Redis do
138
138
 
139
139
  describe 'dump' do
140
140
  it 'should trigger dumps' do
141
- index.should_receive(:dump_index).once.with
141
+ index.stub! :timed_exclaim
142
+
143
+ index.should_receive(:dump_inverted).once.with
142
144
  index.should_receive(:dump_weights).once.with
143
145
  index.should_receive(:dump_similarity).once.with
144
146
  index.should_receive(:dump_configuration).once.with
@@ -256,7 +258,7 @@ describe Indexing::Bundle::Redis do
256
258
 
257
259
  describe 'initialization' do
258
260
  it 'should initialize the index correctly' do
259
- index.index.should == {}
261
+ index.inverted.should == {}
260
262
  end
261
263
  it 'should initialize the weights index correctly' do
262
264
  index.weights.should == {}
@@ -34,7 +34,7 @@ describe Query::Allocation do
34
34
  @allocation.stub! :ids => :ids
35
35
  end
36
36
  it "represents correctly" do
37
- @allocation.to_s.should == "Allocation: some_result_identifier, score, 10, combinations_result, ids"
37
+ @allocation.to_s.should == "Allocation([:some_result_identifier, :score, 10, \"combinations_result\", :ids])"
38
38
  end
39
39
  end
40
40
  end
@@ -87,13 +87,11 @@ describe Query::Token do
87
87
  it 'generates all similar' do
88
88
  @token.next_similar(@bundle).should == nil
89
89
  end
90
- # TODO
91
- #
92
- # it 'should have a certain text' do
93
- # @token.next_similar @bundle
94
- #
95
- # @token.text.should == :nonsimilar
96
- # end
90
+ it 'should have a certain text' do
91
+ @token.next_similar @bundle
92
+
93
+ @token.text.should == :nonsimilar
94
+ end
97
95
  end
98
96
  end
99
97
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sources::Base do
4
+ context 'with the base class' do
5
+ let(:source) { described_class.new }
6
+
7
+ describe 'connect_backend' do
8
+ it 'exists' do
9
+ source.connect_backend
10
+ end
11
+ end
12
+
13
+ describe 'take_snapshot' do
14
+ it 'exists and takes a single parameter' do
15
+ source.take_snapshot :some_index
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'with subclass' do
21
+ let(:take_snapshot_called) { 0 }
22
+ let(:subclass) do
23
+ Class.new(described_class) do
24
+ def take_snapshot index
25
+ index.call index
26
+ end
27
+ end.new
28
+ end
29
+
30
+ describe 'with snapshot' do
31
+ it 'is called only once when called in nested blocks' do
32
+ index = stub :index, :identifier => :some_index
33
+ subclass.stub! :timed_exclaim
34
+
35
+ index.should_receive(:call).once.with index
36
+
37
+ subclass.with_snapshot(index) do
38
+ subclass.with_snapshot(index) do
39
+ subclass.with_snapshot(index) do
40
+
41
+ end
42
+ end
43
+ subclass.with_snapshot(index) do
44
+ subclass.with_snapshot(index) do
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -102,13 +102,6 @@ describe Sources::DB do
102
102
  @source.should_receive(:get_data).any_number_of_times.and_return [[:some_id, 'some_text']].cycle
103
103
  @source.stub! :count => 17
104
104
  end
105
- it 'calls connect_backend' do
106
- @source.should_receive(:connect_backend).once.with()
107
-
108
- @source.harvest @category do |id, text|
109
- p [id, text]
110
- end
111
- end
112
105
  end
113
106
 
114
107
  describe "harvest_statement_with_offset" do