jordanyeo-simple-navigation 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +265 -0
- data/Gemfile +17 -0
- data/README +22 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/generators/navigation_config/USAGE +1 -0
- data/generators/navigation_config/navigation_config_generator.rb +8 -0
- data/generators/navigation_config/templates/config/navigation.rb +76 -0
- data/lib/generators/navigation_config/navigation_config_generator.rb +12 -0
- data/lib/simple-navigation.rb +1 -0
- data/lib/simple_navigation.rb +167 -0
- data/lib/simple_navigation/adapters.rb +10 -0
- data/lib/simple_navigation/adapters/base.rb +37 -0
- data/lib/simple_navigation/adapters/nanoc.rb +45 -0
- data/lib/simple_navigation/adapters/padrino.rb +20 -0
- data/lib/simple_navigation/adapters/rails.rb +93 -0
- data/lib/simple_navigation/adapters/sinatra.rb +69 -0
- data/lib/simple_navigation/core.rb +5 -0
- data/lib/simple_navigation/core/configuration.rb +72 -0
- data/lib/simple_navigation/core/item.rb +144 -0
- data/lib/simple_navigation/core/item_adapter.rb +63 -0
- data/lib/simple_navigation/core/item_container.rb +147 -0
- data/lib/simple_navigation/core/items_provider.rb +35 -0
- data/lib/simple_navigation/rails_controller_methods.rb +144 -0
- data/lib/simple_navigation/rendering.rb +12 -0
- data/lib/simple_navigation/rendering/helpers.rb +123 -0
- data/lib/simple_navigation/rendering/renderer/base.rb +107 -0
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +59 -0
- data/lib/simple_navigation/rendering/renderer/json.rb +29 -0
- data/lib/simple_navigation/rendering/renderer/links.rb +32 -0
- data/lib/simple_navigation/rendering/renderer/list.rb +29 -0
- data/lib/simple_navigation/rendering/renderer/text.rb +26 -0
- data/rails/init.rb +1 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +31 -0
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +287 -0
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +80 -0
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -0
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +212 -0
- data/spec/lib/simple_navigation/core/item_container_spec.rb +451 -0
- data/spec/lib/simple_navigation/core/item_spec.rb +566 -0
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +60 -0
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +249 -0
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +276 -0
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +199 -0
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +101 -0
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +48 -0
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +64 -0
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +211 -0
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -0
- data/spec/lib/simple_navigation_spec.rb +307 -0
- data/spec/spec_helper.rb +108 -0
- metadata +199 -0
@@ -0,0 +1,566 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleNavigation::Item do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@item_container = stub(:item_container, :level => 1, :selected_class => nil).as_null_object
|
7
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
|
8
|
+
@adapter = stub(:adapter)
|
9
|
+
SimpleNavigation.stub!(:adapter => @adapter)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'initialize' do
|
13
|
+
context 'subnavigation' do
|
14
|
+
before(:each) do
|
15
|
+
@subnav_container = stub(:subnav_container).as_null_object
|
16
|
+
SimpleNavigation::ItemContainer.stub!(:new => @subnav_container)
|
17
|
+
end
|
18
|
+
context 'block given' do
|
19
|
+
it "should create a new ItemContainer with a level+1" do
|
20
|
+
SimpleNavigation::ItemContainer.should_receive(:new).with(2)
|
21
|
+
SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}) {}
|
22
|
+
end
|
23
|
+
it "should call the block" do
|
24
|
+
@subnav_container.should_receive(:test)
|
25
|
+
SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}) {|subnav| subnav.test}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'no block given' do
|
29
|
+
context 'items given' do
|
30
|
+
before(:each) do
|
31
|
+
@items = stub(:items)
|
32
|
+
end
|
33
|
+
it "should create a new ItemContainer with a level+1" do
|
34
|
+
SimpleNavigation::ItemContainer.should_receive(:new).with(2)
|
35
|
+
SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}, @items)
|
36
|
+
end
|
37
|
+
it "should set the items on the subnav_container" do
|
38
|
+
@subnav_container.should_receive(:items=).with(@items)
|
39
|
+
SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}, @items)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context 'no items given' do
|
43
|
+
it "should not create a new ItemContainer" do
|
44
|
+
SimpleNavigation::ItemContainer.should_not_receive(:new)
|
45
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context ':method option' do
|
51
|
+
context 'defined' do
|
52
|
+
before(:each) do
|
53
|
+
@options = {:method => :delete}
|
54
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
|
55
|
+
end
|
56
|
+
it 'should set the method as instance_var' do
|
57
|
+
@item.method.should == :delete
|
58
|
+
end
|
59
|
+
it 'should set the html-options without the method' do
|
60
|
+
@item.instance_variable_get(:@html_options).key?(:method).should be_false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'undefined' do
|
65
|
+
it 'should set the instance-var to nil' do
|
66
|
+
@item.method.should be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'setting class and id on the container' do
|
72
|
+
before(:each) do
|
73
|
+
@options = {:container_class => 'container_class', :container_id => 'container_id'}
|
74
|
+
end
|
75
|
+
it {@item_container.should_receive(:dom_class=).with('container_class')}
|
76
|
+
it {@item_container.should_receive(:dom_id=).with('container_id')}
|
77
|
+
after(:each) do
|
78
|
+
SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context ':highlights_on option' do
|
83
|
+
context 'defined' do
|
84
|
+
before(:each) do
|
85
|
+
@highlights_on = stub(:option)
|
86
|
+
@options = {:highlights_on => @highlights_on}
|
87
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
|
88
|
+
end
|
89
|
+
it 'should set the method as instance_var' do
|
90
|
+
@item.highlights_on.should == @highlights_on
|
91
|
+
end
|
92
|
+
it 'should set the html-options without the method' do
|
93
|
+
@item.instance_variable_get(:@html_options).key?(:highlights_on).should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'undefined' do
|
98
|
+
it 'should set the instance-var to nil' do
|
99
|
+
@item.highlights_on.should be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'url' do
|
105
|
+
context 'url is a string' do
|
106
|
+
before(:each) do
|
107
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
|
108
|
+
end
|
109
|
+
it {@item.url.should == 'url'}
|
110
|
+
end
|
111
|
+
context 'url is a proc' do
|
112
|
+
before(:each) do
|
113
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', Proc.new {"my_" + "url"}, {})
|
114
|
+
end
|
115
|
+
it {@item.url.should == 'my_url'}
|
116
|
+
end
|
117
|
+
context 'url is nil' do
|
118
|
+
before(:each) do
|
119
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', nil, {})
|
120
|
+
end
|
121
|
+
it {@item.url.should == nil}
|
122
|
+
end
|
123
|
+
context 'url is unspecified' do
|
124
|
+
before(:each) do
|
125
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name')
|
126
|
+
end
|
127
|
+
it {@item.url.should == nil}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'optional url and optional options' do
|
132
|
+
context 'when constructed without any optional parameters' do
|
133
|
+
before(:each) do
|
134
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name')
|
135
|
+
end
|
136
|
+
it {@item.url.should == nil}
|
137
|
+
it {@item.instance_variable_get(:@html_options).should == {}}
|
138
|
+
end
|
139
|
+
context 'when constructed with only a url' do
|
140
|
+
before(:each) do
|
141
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url')
|
142
|
+
end
|
143
|
+
it {@item.url.should == 'url'}
|
144
|
+
it {@item.instance_variable_get(:@html_options).should == {}}
|
145
|
+
end
|
146
|
+
context 'when constructed with only options' do
|
147
|
+
before(:each) do
|
148
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', {:option => true})
|
149
|
+
end
|
150
|
+
it {@item.url.should == nil}
|
151
|
+
it {@item.instance_variable_get(:@html_options).should == {:option => true}}
|
152
|
+
end
|
153
|
+
context 'when constructed with a url and options' do
|
154
|
+
before(:each) do
|
155
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {:option => true})
|
156
|
+
end
|
157
|
+
it {@item.url.should == 'url'}
|
158
|
+
it {@item.instance_variable_get(:@html_options).should == {:option => true}}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'name' do
|
164
|
+
before(:each) do
|
165
|
+
SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>#{name}</span>"})
|
166
|
+
end
|
167
|
+
context 'default (generator is applied)' do
|
168
|
+
it {@item.name.should == "<span>name</span>"}
|
169
|
+
end
|
170
|
+
context 'generator is skipped' do
|
171
|
+
it {@item.name(:apply_generator => false).should == 'name'}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'selected?' do
|
176
|
+
context 'explicitly selected' do
|
177
|
+
before(:each) do
|
178
|
+
@item.stub!(:selected_by_config? => true)
|
179
|
+
end
|
180
|
+
it {@item.should be_selected}
|
181
|
+
it "should not evaluate the subnav or urls" do
|
182
|
+
@item.should_not_receive(:selected_by_subnav?)
|
183
|
+
@item.should_not_receive(:selected_by_condition?)
|
184
|
+
@item.selected?
|
185
|
+
end
|
186
|
+
end
|
187
|
+
context 'not explicitly selected' do
|
188
|
+
before(:each) do
|
189
|
+
@item.stub!(:selected_by_config? => false)
|
190
|
+
end
|
191
|
+
context 'subnav is selected' do
|
192
|
+
before(:each) do
|
193
|
+
@item.stub!(:selected_by_subnav? => true)
|
194
|
+
end
|
195
|
+
it {@item.should be_selected}
|
196
|
+
end
|
197
|
+
context 'subnav is not selected' do
|
198
|
+
before(:each) do
|
199
|
+
@item.stub!(:selected_by_subnav? => false)
|
200
|
+
end
|
201
|
+
context 'selected by condition' do
|
202
|
+
before(:each) do
|
203
|
+
@item.stub!(:selected_by_condition? => true)
|
204
|
+
end
|
205
|
+
it {@item.should be_selected}
|
206
|
+
end
|
207
|
+
context 'not selected by condition' do
|
208
|
+
before(:each) do
|
209
|
+
@item.stub!(:selected_by_condition? => false)
|
210
|
+
end
|
211
|
+
it {@item.should_not be_selected}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'selected_class' do
|
218
|
+
context 'selected_class is defined in context' do
|
219
|
+
before(:each) do
|
220
|
+
@item_container = stub(:item_container, :level => 1, :selected_class => 'context_defined').as_null_object
|
221
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
|
222
|
+
@item.stub!(:selected? => true)
|
223
|
+
end
|
224
|
+
it {@item.instance_eval {selected_class.should == 'context_defined'}}
|
225
|
+
end
|
226
|
+
context 'item is selected' do
|
227
|
+
before(:each) do
|
228
|
+
@item.stub!(:selected? => true)
|
229
|
+
end
|
230
|
+
it {@item.instance_eval {selected_class.should == 'selected'}}
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'item is not selected' do
|
234
|
+
before(:each) do
|
235
|
+
@item.stub!(:selected? => false)
|
236
|
+
end
|
237
|
+
it {@item.instance_eval {selected_class.should == nil}}
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'html_options' do
|
242
|
+
describe 'class' do
|
243
|
+
context 'with classes defined in options' do
|
244
|
+
before(:each) do
|
245
|
+
@options = {:class => 'my_class'}
|
246
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
|
247
|
+
end
|
248
|
+
context 'with item selected' do
|
249
|
+
before(:each) do
|
250
|
+
@item.stub!(:selected? => true, :selected_by_condition? => true)
|
251
|
+
end
|
252
|
+
it {@item.html_options[:class].should == 'my_class selected simple-navigation-active-leaf'}
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with item not selected' do
|
256
|
+
before(:each) do
|
257
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
258
|
+
end
|
259
|
+
it {@item.html_options[:class].should == 'my_class'}
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'without classes in options' do
|
264
|
+
before(:each) do
|
265
|
+
@options = {}
|
266
|
+
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
|
267
|
+
end
|
268
|
+
context 'with item selected' do
|
269
|
+
before(:each) do
|
270
|
+
@item.stub!(:selected? => true, :selected_by_condition? => true)
|
271
|
+
end
|
272
|
+
it {@item.html_options[:class].should == 'selected simple-navigation-active-leaf'}
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'with item not selected' do
|
276
|
+
before(:each) do
|
277
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
278
|
+
end
|
279
|
+
it {@item.html_options[:class].should be_blank}
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
describe 'id' do
|
286
|
+
context 'with autogenerate_item_ids == true' do
|
287
|
+
before(:each) do
|
288
|
+
@item.stub!(:autogenerate_item_ids? => true)
|
289
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
290
|
+
end
|
291
|
+
context 'with id defined in options' do
|
292
|
+
before(:each) do
|
293
|
+
@item.html_options = {:id => 'my_id'}
|
294
|
+
end
|
295
|
+
it {@item.html_options[:id].should == 'my_id'}
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'with no id defined in options (using default id)' do
|
299
|
+
before(:each) do
|
300
|
+
@item.html_options = {}
|
301
|
+
end
|
302
|
+
it {@item.html_options[:id].should == 'my_key'}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'with autogenerate_item_ids == false' do
|
307
|
+
before(:each) do
|
308
|
+
@item.stub!(:autogenerate_item_ids? => false)
|
309
|
+
@item.stub!(:selected? => false, :selected_by_condition? => false)
|
310
|
+
end
|
311
|
+
context 'with id defined in options' do
|
312
|
+
before(:each) do
|
313
|
+
@item.html_options = {:id => 'my_id'}
|
314
|
+
end
|
315
|
+
it {@item.html_options[:id].should == 'my_id'}
|
316
|
+
end
|
317
|
+
|
318
|
+
context 'with no id definied in options (using default id)' do
|
319
|
+
before(:each) do
|
320
|
+
@item.html_options = {}
|
321
|
+
end
|
322
|
+
it {@item.html_options[:id].should be_nil}
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
describe 'selected_by_subnav?' do
|
332
|
+
context 'item has subnav' do
|
333
|
+
before(:each) do
|
334
|
+
@sub_navigation = stub(:sub_navigation)
|
335
|
+
@item.stub!(:sub_navigation => @sub_navigation)
|
336
|
+
end
|
337
|
+
it "should return true if subnav is selected" do
|
338
|
+
@sub_navigation.stub!(:selected? => true, :selected_by_condition? => true)
|
339
|
+
@item.should be_selected_by_subnav
|
340
|
+
end
|
341
|
+
it "should return false if subnav is not selected" do
|
342
|
+
@sub_navigation.stub!(:selected? => false, :selected_by_condition? => true)
|
343
|
+
@item.should_not be_selected_by_subnav
|
344
|
+
end
|
345
|
+
end
|
346
|
+
context 'item does not have subnav' do
|
347
|
+
before(:each) do
|
348
|
+
@item.stub!(:sub_navigation => @sub_navigation)
|
349
|
+
end
|
350
|
+
it {@item.should_not be_selected_by_subnav}
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe 'selected_by_condition?' do
|
355
|
+
context ':highlights_on option is set' do
|
356
|
+
before(:each) do
|
357
|
+
@item.stub!(:highlights_on => /^\/current/)
|
358
|
+
SimpleNavigation.stub!(:request_uri => '/current_url')
|
359
|
+
end
|
360
|
+
it "should not check for autohighlighting" do
|
361
|
+
@item.should_not_receive(:auto_highlight?)
|
362
|
+
@item.send(:selected_by_condition?)
|
363
|
+
end
|
364
|
+
context ':highlights_on is a regexp' do
|
365
|
+
context 'regexp matches current_url' do
|
366
|
+
it {@item.send(:selected_by_condition?).should be_true}
|
367
|
+
end
|
368
|
+
context 'regexp does not match current_url' do
|
369
|
+
before(:each) do
|
370
|
+
@item.stub!(:highlights_on => /^\/no_match/)
|
371
|
+
end
|
372
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
373
|
+
end
|
374
|
+
end
|
375
|
+
context ':highlights_on is a lambda' do
|
376
|
+
context 'truthy lambda results in selection' do
|
377
|
+
before(:each) do
|
378
|
+
@item.stub!(:highlights_on => lambda{true})
|
379
|
+
end
|
380
|
+
it {@item.send(:selected_by_condition?).should be_true}
|
381
|
+
end
|
382
|
+
context 'falsey lambda results in no selection' do
|
383
|
+
before(:each) do
|
384
|
+
@item.stub!(:highlights_on => lambda{false})
|
385
|
+
end
|
386
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
387
|
+
end
|
388
|
+
end
|
389
|
+
context ':highlights_on is :subpath' do
|
390
|
+
before(:each) do
|
391
|
+
@item.stub!(:url => '/resources')
|
392
|
+
@item.stub!(:highlights_on => :subpath)
|
393
|
+
end
|
394
|
+
context 'we are in a route beginning with this item path' do
|
395
|
+
before(:each) do
|
396
|
+
SimpleNavigation.stub!(:request_uri => '/resources/id')
|
397
|
+
end
|
398
|
+
it {@item.send(:selected_by_condition?).should be_true}
|
399
|
+
end
|
400
|
+
context 'we are in a route that has a similar name' do
|
401
|
+
before(:each) do
|
402
|
+
SimpleNavigation.stub!(:request_uri => '/resources_group/id')
|
403
|
+
end
|
404
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
405
|
+
end
|
406
|
+
context 'we are in a route not beginning with this item path' do
|
407
|
+
before(:each) do
|
408
|
+
SimpleNavigation.stub!(:request_uri => '/another_resource/id')
|
409
|
+
end
|
410
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
411
|
+
end
|
412
|
+
end
|
413
|
+
context ':highlights_on is not a regexp or a proc' do
|
414
|
+
before(:each) do
|
415
|
+
@item.stub!(:highlights_on => "not a regexp")
|
416
|
+
end
|
417
|
+
it "should raise an error" do
|
418
|
+
lambda {@item.send(:selected_by_condition?).should raise_error(ArgumentError)}
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
context ':highlights_on option is not set' do
|
423
|
+
before(:each) do
|
424
|
+
@item.stub!(:highlights_on => nil)
|
425
|
+
end
|
426
|
+
it "should check for autohighlighting" do
|
427
|
+
@item.should_receive(:auto_highlight?)
|
428
|
+
@item.send(:selected_by_condition?)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
context 'auto_highlight is turned on' do
|
432
|
+
before(:each) do
|
433
|
+
@item.stub!(:auto_highlight? => true)
|
434
|
+
end
|
435
|
+
context 'root path matches' do
|
436
|
+
before(:each) do
|
437
|
+
@item.stub!(:root_path_match? => true)
|
438
|
+
end
|
439
|
+
it {@item.send(:selected_by_condition?).should be_true}
|
440
|
+
end
|
441
|
+
context 'root path does not match' do
|
442
|
+
before(:each) do
|
443
|
+
@item.stub!(:root_path_match? => false)
|
444
|
+
end
|
445
|
+
context 'current request url matches url' do
|
446
|
+
before(:each) do
|
447
|
+
@adapter.stub!(:current_page? => true)
|
448
|
+
end
|
449
|
+
it "should test with the item's url" do
|
450
|
+
@adapter.should_receive(:current_page?).with('url')
|
451
|
+
@item.send(:selected_by_condition?)
|
452
|
+
end
|
453
|
+
it "should remove anchors before testing the item's url" do
|
454
|
+
@item.stub!(:url => 'url#anchor')
|
455
|
+
@adapter.should_receive(:current_page?).with('url')
|
456
|
+
@item.send(:selected_by_condition?)
|
457
|
+
end
|
458
|
+
it "should not be queried when url is nil" do
|
459
|
+
@item.stub!(:url => nil)
|
460
|
+
@adapter.should_not_receive(:current_page?)
|
461
|
+
@item.send(:selected_by_condition?)
|
462
|
+
end
|
463
|
+
it {@item.send(:selected_by_condition?).should be_true}
|
464
|
+
end
|
465
|
+
context 'no match' do
|
466
|
+
before(:each) do
|
467
|
+
@adapter.stub!(:current_page? => false)
|
468
|
+
end
|
469
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
context 'auto_highlight is turned off' do
|
474
|
+
before(:each) do
|
475
|
+
@item.stub!(:auto_highlight? => false)
|
476
|
+
end
|
477
|
+
it {@item.send(:selected_by_condition?).should be_false}
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
describe 'root_path_match?' do
|
482
|
+
it "should match if both url == /" do
|
483
|
+
@adapter.stub!(:request_path => '/')
|
484
|
+
@item.stub!(:url => '/')
|
485
|
+
@item.send(:root_path_match?).should be_true
|
486
|
+
end
|
487
|
+
it "should not match if item url is not /" do
|
488
|
+
@adapter.stub(:request_path => '/')
|
489
|
+
@item.stub!(:url => '/bla')
|
490
|
+
@item.send(:root_path_match?).should be_false
|
491
|
+
end
|
492
|
+
it "should not match if request url is not /" do
|
493
|
+
@adapter.stub(:request_path => '/bla')
|
494
|
+
@item.stub!(:url => '/')
|
495
|
+
@item.send(:root_path_match?).should be_false
|
496
|
+
end
|
497
|
+
it "should not match if urls do not match" do
|
498
|
+
@adapter.stub(:request_path => 'bla')
|
499
|
+
@item.stub!(:url => '/bli')
|
500
|
+
@item.send(:root_path_match?).should be_false
|
501
|
+
end
|
502
|
+
it "should not match if url is nil" do
|
503
|
+
@adapter.stub(:request_path => 'bla')
|
504
|
+
@item.stub!(:url => nil)
|
505
|
+
@item.send(:root_path_match?).should be_false
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
describe 'auto_highlight?' do
|
510
|
+
before(:each) do
|
511
|
+
@global = stub(:config)
|
512
|
+
SimpleNavigation.stub!(:config => @global)
|
513
|
+
end
|
514
|
+
context 'global auto_highlight on' do
|
515
|
+
before(:each) do
|
516
|
+
@global.stub!(:auto_highlight => true)
|
517
|
+
end
|
518
|
+
context 'container auto_highlight on' do
|
519
|
+
before(:each) do
|
520
|
+
@item_container.stub!(:auto_highlight => true)
|
521
|
+
end
|
522
|
+
it {@item.send(:auto_highlight?).should be_true}
|
523
|
+
end
|
524
|
+
context 'container auto_highlight off' do
|
525
|
+
before(:each) do
|
526
|
+
@item_container.stub!(:auto_highlight => false)
|
527
|
+
end
|
528
|
+
it {@item.send(:auto_highlight?).should be_false}
|
529
|
+
end
|
530
|
+
end
|
531
|
+
context 'global auto_highlight off' do
|
532
|
+
before(:each) do
|
533
|
+
@global.stub!(:auto_highlight => false)
|
534
|
+
end
|
535
|
+
context 'container auto_highlight on' do
|
536
|
+
before(:each) do
|
537
|
+
@item_container.stub!(:auto_highlight => true)
|
538
|
+
end
|
539
|
+
it {@item.send(:auto_highlight?).should be_false}
|
540
|
+
end
|
541
|
+
context 'container auto_highlight off' do
|
542
|
+
before(:each) do
|
543
|
+
@item_container.stub!(:auto_highlight => false)
|
544
|
+
end
|
545
|
+
it {@item.send(:auto_highlight?).should be_false}
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
describe 'autogenerated_item_id' do
|
551
|
+
context 'calls' do
|
552
|
+
before(:each) do
|
553
|
+
@id_generator = stub(:id_generator)
|
554
|
+
SimpleNavigation.config.stub!(:id_generator => @id_generator)
|
555
|
+
end
|
556
|
+
it "should call the configured generator with the key as param" do
|
557
|
+
@id_generator.should_receive(:call).with(:my_key)
|
558
|
+
@item.send(:autogenerated_item_id)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
context 'default generator' do
|
562
|
+
it {@item.send(:autogenerated_item_id).should == 'my_key'}
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
end
|