/
index_indexing_spec.rb
136 lines (121 loc) · 3.49 KB
/
index_indexing_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'spec_helper'
describe Picky::Index do
describe 'tokenizer' do
context 'with tokenizer' do
let(:tokenizer) { double :tokenizer, :tokenize => '' }
let(:index) do
the_tokenizer = tokenizer
described_class.new :some_name do
source []
indexing the_tokenizer
end
end
it 'does things in order' do
index.tokenizer.should == tokenizer
end
end
context 'without tokenizer' do
let(:index) do
described_class.new :some_name do
source []
end
end
it 'does things in order' do
index.tokenizer.should == Picky::Indexes.tokenizer
end
end
end
context 'after_indexing' do
context 'with it set' do
let(:index) do
described_class.new :some_name do
after_indexing "some after indexing going on"
end
end
it 'has an after_indexing set' do
index.after_indexing.should == "some after indexing going on"
end
end
context 'with it not set' do
let(:index) do
described_class.new :some_name do
end
end
it 'does not have an after_indexing set' do
index.after_indexing.should == nil
end
end
end
context 'in general' do
context 'with #each source' do
let(:index) do
described_class.new :some_name
end
it 'does things in order' do
scheduler = double :scheduler, :fork? => false, :finish => nil
index.should_receive(:prepare).once.with(scheduler).ordered
index.should_receive(:cache).once.with(scheduler).ordered
index.index scheduler
end
end
context 'with non#each source' do
it 'raises' do
the_source = double :source, :harvest => nil
expect {
described_class.new :some_name do
source the_source
end
}.to raise_error(<<-ERROR)
The source for some_name should respond to either the method #each or
it can be a lambda/block, returning such a source.
ERROR
end
end
end
context "with categories" do
before(:each) do
the_source = []
@index = described_class.new :some_name do
source the_source
end
@index.category :some_category_name1
@index.category :some_category_name2
end
describe 'source' do
it 'can be set with this method' do
source = double :source, :each => [].each
@index.source source
@index.source.should == source
end
end
describe 'find' do
context 'no categories' do
it 'raises on none existent category' do
expect do
@index[:some_non_existent_name]
end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_category_name1", "some_category_name2".})
end
end
context 'with categories' do
before(:each) do
@index.category :some_name, :source => double(:source)
end
it 'returns it if found' do
@index[:some_name].should_not == nil
end
it 'raises on none existent category' do
expect do
@index[:some_non_existent_name]
end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_category_name1", "some_category_name2", "some_name".})
end
end
end
end
context "no categories" do
it "works" do
described_class.new :some_name do
source []
end
end
end
end