-
Notifications
You must be signed in to change notification settings - Fork 49
/
category_indexing_spec.rb
181 lines (156 loc) · 5.46 KB
/
category_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
require 'spec_helper'
describe Picky::Category do
before(:each) do
@index = Picky::Index.new :some_index
@source = stub :some_given_source, :key_format => nil
end
let(:category) { described_class.new(:some_category, @index, :source => @source).tap { |c| c.stub! :timed_exclaim } }
context "unit specs" do
let(:exact) { category.indexing_exact }
let(:partial) { category.indexing_partial }
describe 'backup' do
it 'delegates to both bundles' do
exact.should_receive(:backup).once.with()
partial.should_receive(:backup).once.with()
category.backup
end
end
describe 'restore' do
it 'delegates to both bundles' do
exact.should_receive(:restore).once.with()
partial.should_receive(:restore).once.with()
category.restore
end
end
describe 'check' do
it 'delegates to both bundles' do
exact.should_receive(:raise_unless_cache_exists).once.with()
partial.should_receive(:raise_unless_cache_exists).once.with()
category.check
end
end
describe 'clear' do
it 'delegates to both bundles' do
exact.should_receive(:delete).once.with()
partial.should_receive(:delete).once.with()
category.clear
end
end
describe 'dump_caches' do
before(:each) do
exact.stub! :dump
partial.stub! :dump
end
it 'should dump the exact index' do
exact.should_receive(:dump).once.with
category.dump_caches
end
it 'should dump the partial index' do
partial.should_receive(:dump).once.with
category.dump_caches
end
end
describe 'generate_caches_from_memory' do
it 'should delegate to partial' do
partial.should_receive(:generate_caches_from_memory).once.with
category.generate_caches_from_memory
end
end
describe 'generate_partial' do
it 'should return whatever the partial generation returns' do
exact.stub! :index
partial.stub! :generate_partial_from => :generation_returns
category.generate_partial
end
it 'should use the exact index to generate the partial index' do
exact_index = stub :exact_index
exact.stub! :inverted => exact_index
partial.should_receive(:generate_partial_from).once.with(exact_index)
category.generate_partial
end
end
describe 'generate_caches_from_source' do
it 'should delegate to exact' do
exact.should_receive(:generate_caches_from_source).once.with
category.generate_caches_from_source
end
end
describe 'cache' do
it 'should call multiple methods in order' do
category.should_receive(:generate_caches_from_source).once.with().ordered
category.should_receive(:generate_partial).once.with().ordered
category.should_receive(:generate_caches_from_memory).once.with().ordered
category.should_receive(:dump_caches).once.with().ordered
category.should_receive(:timed_exclaim).once.ordered
category.cache
end
end
describe 'key_format' do
context 'source has key_format' do
before(:each) do
category.stub! :source => stub(:source, :key_format => :some_key_format)
end
it 'returns that key_format' do
category.key_format.should == :some_key_format
end
end
context 'source does not have key_format' do
before(:each) do
category.stub! :source => stub(:source)
end
context 'category has its own key_format' do
before(:each) do
category.instance_variable_set :@key_format, :other_key_format
end
it 'returns that key_format' do
category.key_format.should == :other_key_format
end
end
context 'category does not have its own key format' do
before(:each) do
category.instance_variable_set :@key_format, nil
end
context 'it has an index' do
before(:each) do
category.instance_variable_set :@index, stub(:index, :key_format => :yet_another_key_format)
end
it 'returns that key_format' do
category.key_format.should == :yet_another_key_format
end
end
end
end
end
describe 'source' do
context 'with explicit source' do
let(:category) { described_class.new(:some_category, @index, :source => :category_source) }
it 'returns the right source' do
category.source.should == :category_source
end
end
context 'without explicit source' do
let(:category) { described_class.new(:some_category, @index.tap{ |index| index.stub! :source => :index_source }) }
it 'returns the right source' do
category.source.should == :index_source
end
end
end
describe "index" do
before(:each) do
@indexer = stub :indexer, :index => nil
category.stub! :indexer => @indexer
end
it "tells the indexer to index" do
@indexer.should_receive(:index).once.with [category]
category.prepare
end
end
describe "source" do
context "without source" do
it "has no problem with that" do
lambda { described_class.new :some_name, @index }.should_not raise_error
end
end
end
end
end