simple-navigation 3.11.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG +11 -0
  5. data/Gemfile +2 -16
  6. data/Guardfile +5 -0
  7. data/LICENSE +22 -0
  8. data/README.md +40 -0
  9. data/Rakefile +6 -39
  10. data/generators/navigation_config/templates/config/navigation.rb +7 -5
  11. data/init.rb +1 -0
  12. data/install.rb +5 -0
  13. data/lib/simple_navigation/adapters/rails.rb +5 -1
  14. data/lib/simple_navigation/core/configuration.rb +5 -1
  15. data/lib/simple_navigation/core/item.rb +2 -1
  16. data/lib/simple_navigation/core/item_adapter.rb +4 -4
  17. data/lib/simple_navigation/core/item_container.rb +6 -1
  18. data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
  19. data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
  20. data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
  21. data/lib/simple_navigation/version.rb +3 -0
  22. data/lib/simple_navigation.rb +1 -0
  23. data/simple-navigation.gemspec +40 -0
  24. data/spec/initializers/have_css_matcher.rb +13 -0
  25. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
  26. data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
  27. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
  28. data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
  29. data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
  30. data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
  31. data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
  32. data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
  33. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
  34. data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
  35. data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
  36. data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
  37. data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
  38. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
  39. data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
  40. data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
  41. data/spec/lib/simple_navigation_spec.rb +207 -225
  42. data/spec/spec_helper.rb +53 -82
  43. data/uninstall.rb +1 -0
  44. metadata +100 -22
  45. data/README +0 -22
  46. data/VERSION +0 -1
@@ -1,276 +1,432 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SimpleNavigation::Helpers do
4
- class ControllerMock
5
- include SimpleNavigation::Helpers
6
- end
3
+ class TestController
4
+ include SimpleNavigation::Helpers
5
+ end
7
6
 
8
- def blackbox_setup()
9
- @controller = ControllerMock.new
10
- SimpleNavigation.stub!(:load_config)
11
- SimpleNavigation::Configuration.stub!(:eval_config)
12
- setup_adapter_for :rails
13
- @primary_container, @subnav_container = containers
14
- @subnav1_item = sub_item(:subnav1)
15
- @invoices_item = primary_item(:invoices)
16
- SimpleNavigation.stub!(:primary_navigation => @primary_container)
17
- end
7
+ module SimpleNavigation
8
+ describe Helpers do
9
+ subject(:controller) { TestController.new }
18
10
 
19
- def whitebox_setup
20
- @controller = ControllerMock.new
21
- SimpleNavigation.stub!(:load_config)
22
- SimpleNavigation::Configuration.stub!(:eval_config)
23
- @primary_navigation = stub(:primary_navigation).as_null_object
24
- SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
25
- SimpleNavigation.stub!(:config_file? => true)
26
- end
11
+ let(:invoices_item) { navigation[:invoices] }
12
+ let(:item) { nil }
13
+ let(:navigation) { setup_navigation('nav_id', 'nav_class') }
14
+ let(:unpaid_item) { invoices_item.sub_navigation[:unpaid] }
15
+
16
+ before do
17
+ Configuration.stub(:eval_config)
18
+ SimpleNavigation.stub(load_config: nil,
19
+ primary_navigation: navigation,
20
+ config_file?: true,
21
+ context_for_eval: controller)
27
22
 
28
- describe 'active_navigation_item_name' do
29
- before(:each) do
30
- blackbox_setup
23
+ select_an_item(navigation[item]) if item
31
24
  end
32
- context 'active item_container for desired level exists' do
33
- context 'container has selected item' do
34
- before(:each) do
35
- select_item(:subnav1)
36
- end
37
- it {@controller.active_navigation_item_name(:level => 2).should == 'subnav1'}
38
- it {@controller.active_navigation_item_name.should == 'subnav1'}
39
- it {@controller.active_navigation_item_name(:level => 1).should == 'invoices'}
40
- it {@controller.active_navigation_item_name(:level => :all).should == 'subnav1'}
41
- end
42
- context 'container does not have selected item' do
43
- it {@controller.active_navigation_item_name.should == ''}
44
- end
45
- context 'custom name generator set' do
46
- before(:each) do
47
- select_item(:subnav1)
48
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
25
+
26
+ describe '#active_navigation_item_name' do
27
+ context 'when no item is selected' do
28
+ it 'returns an empty string for no parameters' do
29
+ expect(controller.active_navigation_item_name).to eq ''
49
30
  end
50
- it "should not apply the generator" do
51
- @controller.active_navigation_item_name(:level => 1).should == 'invoices'
31
+
32
+ it "returns an empty string for level: 1" do
33
+ item_name = controller.active_navigation_item_name(level: 1)
34
+ expect(item_name).to eq ''
52
35
  end
53
- end
54
- end
55
- context 'no active item_container for desired level' do
56
- it {@controller.active_navigation_item_name(:level => 5).should == ''}
57
- end
58
- end
59
36
 
60
- describe 'active_navigation_item_key' do
61
- before(:each) do
62
- blackbox_setup
63
- end
64
- context 'active item_container for desired level exists' do
65
- context 'container has selected item' do
66
- before(:each) do
67
- select_item(:subnav1)
68
- end
69
- it {@controller.active_navigation_item_key(:level => 2).should == :subnav1}
70
- it {@controller.active_navigation_item_key.should == :subnav1}
71
- it {@controller.active_navigation_item_key(:level => 1).should == :invoices}
72
- it {@controller.active_navigation_item_key(:level => :all).should == :subnav1}
37
+ it 'returns an empty string for level: 2' do
38
+ item_name = controller.active_navigation_item_name(level: 2)
39
+ expect(item_name).to eq ''
40
+ end
41
+
42
+ it 'returns an empty string for level: :all' do
43
+ item_name = controller.active_navigation_item_name(level: :all)
44
+ expect(item_name).to eq ''
45
+ end
73
46
  end
74
- context 'container does not have selected item' do
75
- it {@controller.active_navigation_item_key.should == nil}
47
+
48
+ context 'when an item is selected' do
49
+ context "and it's a primary item" do
50
+ let(:item) { :invoices }
51
+
52
+ it 'returns an empty string' do
53
+ expect(controller.active_navigation_item_name).to eq ''
54
+ end
55
+
56
+ it "returns the selected item's name for level: 1" do
57
+ item_name = controller.active_navigation_item_name(level: 1)
58
+ expect(item_name).to eq 'Invoices'
59
+ end
60
+
61
+ it 'returns an empty string for level: 2' do
62
+ item_name = controller.active_navigation_item_name(level: 2)
63
+ expect(item_name).to eq ''
64
+ end
65
+
66
+ it 'returns an empty string for level: :all' do
67
+ item_name = controller.active_navigation_item_name(level: :all)
68
+ expect(item_name).to eq ''
69
+ end
70
+ end
71
+
72
+ context "and it's a sub navigation item" do
73
+ before do
74
+ select_an_item(invoices_item)
75
+ select_an_item(unpaid_item)
76
+ end
77
+
78
+ it "returns the selected item's name" do
79
+ expect(controller.active_navigation_item_name).to eq 'Unpaid'
80
+ end
81
+
82
+ it "returns the selected item's parent name for level: 1" do
83
+ item_name = controller.active_navigation_item_name(level: 1)
84
+ expect(item_name).to eq 'Invoices'
85
+ end
86
+
87
+ it "returns the selected item's name for level: 2" do
88
+ item_name = controller.active_navigation_item_name(level: 2)
89
+ expect(item_name).to eq 'Unpaid'
90
+ end
91
+
92
+ it "returns the selected item's name for level: :all" do
93
+ item_name = controller.active_navigation_item_name(level: :all)
94
+ expect(item_name).to eq 'Unpaid'
95
+ end
96
+ end
76
97
  end
77
98
  end
78
- context 'no active item_container for desired level' do
79
- it {@controller.active_navigation_item_key(:level => 5).should == nil}
80
- end
81
- end
82
99
 
83
- describe 'active_navigation_item' do
84
- before(:each) do
85
- blackbox_setup
86
- end
87
- context 'active item_container for desired level exists' do
88
- context 'container has selected item' do
89
- before(:each) do
90
- select_item(:subnav1)
91
- end
92
- it {@controller.active_navigation_item(:level => 2).should eq(@subnav1_item)}
93
- it {@controller.active_navigation_item.should eq(@subnav1_item)}
94
- it {@controller.active_navigation_item(:level => 1).should eq(@invoices_item)}
95
- it {@controller.active_navigation_item(:level => :all).should eq(@subnav1_item)}
96
- end
97
- context 'container does not have selected item' do
98
- context 'return value defaults to nil' do
99
- it {@controller.active_navigation_item.should == nil}
100
+ describe '#active_navigation_item_key' do
101
+ context 'when no item is selected' do
102
+ it 'returns nil' do
103
+ expect(controller.active_navigation_item_key).to be_nil
100
104
  end
101
- context 'return value reflects passed in value' do
102
- it {@controller.active_navigation_item({},'none').should == 'none'}
103
- it {@controller.active_navigation_item({},@invoices_item).should eq(@invoices_item)}
105
+
106
+ it 'returns nil for no parameters' do
107
+ expect(controller.active_navigation_item_key).to be_nil
108
+ end
109
+
110
+ it "returns nil for level: 1" do
111
+ item_key = controller.active_navigation_item_key(level: 1)
112
+ expect(item_key).to be_nil
113
+ end
114
+
115
+ it 'returns nil for level: 2' do
116
+ item_key = controller.active_navigation_item_key(level: 2)
117
+ expect(item_key).to be_nil
118
+ end
119
+
120
+ it 'returns nil for level: :all' do
121
+ item_key = controller.active_navigation_item_key(level: :all)
122
+ expect(item_key).to be_nil
104
123
  end
105
124
  end
106
- end
107
- context 'no active item_container for desired level' do
108
- it {@controller.active_navigation_item(:level => 5).should == nil}
109
- end
110
- end
111
125
 
112
- describe 'active_navigation_item_container' do
113
- before(:each) do
114
- blackbox_setup
115
- end
116
- context 'active item_container for desired level exists' do
117
- before(:each) do
118
- select_item(:subnav1)
126
+ context 'when an item is selected' do
127
+ context "and it's a primary item" do
128
+ let(:item) { :invoices }
129
+
130
+ it 'returns nil for no parameters' do
131
+ expect(controller.active_navigation_item_key).to be_nil
132
+ end
133
+
134
+ it "returns the selected item's name for level: 1" do
135
+ item_key = controller.active_navigation_item_key(level: 1)
136
+ expect(item_key).to eq :invoices
137
+ end
138
+
139
+ it 'returns nil for level: 2' do
140
+ item_key = controller.active_navigation_item_key(level: 2)
141
+ expect(item_key).to be_nil
142
+ end
143
+
144
+ it 'returns nil for level: :all' do
145
+ item_key = controller.active_navigation_item_key(level: :all)
146
+ expect(item_key).to be_nil
147
+ end
148
+ end
149
+
150
+ context "and it's a sub navigation item" do
151
+ before do
152
+ select_an_item(invoices_item)
153
+ select_an_item(unpaid_item)
154
+ end
155
+
156
+ it "returns the selected item's name" do
157
+ expect(controller.active_navigation_item_key).to eq :unpaid
158
+ end
159
+
160
+ it "returns the selected item's parent name for level: 1" do
161
+ item_key = controller.active_navigation_item_key(level: 1)
162
+ expect(item_key).to eq :invoices
163
+ end
164
+
165
+ it "returns the selected item's name for level: 2" do
166
+ item_key = controller.active_navigation_item_key(level: 2)
167
+ expect(item_key).to eq :unpaid
168
+ end
169
+
170
+ it "returns the selected item's name for level: :all" do
171
+ item_key = controller.active_navigation_item_key(level: :all)
172
+ expect(item_key).to eq :unpaid
173
+ end
174
+ end
119
175
  end
120
- it {@controller.active_navigation_item_container(:level => 2).should == @subnav_container}
121
- it {@controller.active_navigation_item_container.should == @primary_container}
122
- it {@controller.active_navigation_item_container(:level => 1).should == @primary_container}
123
- it {@controller.active_navigation_item_container(:level => :all).should == @primary_container}
124
176
  end
125
- context 'no active item_container for desired level' do
126
- it {@controller.active_navigation_item_container(:level => 5).should == nil}
127
- end
128
- end
129
177
 
130
- describe 'render_navigation' do
131
-
132
- before(:each) do
133
- whitebox_setup
134
- end
135
-
136
- describe 'regarding loading of the config-file' do
137
- context 'no options specified' do
138
- it "should load the config-file for the default context" do
139
- SimpleNavigation.should_receive(:load_config).with(:default)
140
- @controller.render_navigation
178
+ describe '#active_navigation_item' do
179
+ context 'when no item is selected' do
180
+ it 'returns nil for no parameters' do
181
+ expect(controller.active_navigation_item).to be_nil
182
+ end
183
+
184
+ it "returns nil for level: 1" do
185
+ item_key = controller.active_navigation_item(level: 1)
186
+ expect(item_key).to be_nil
187
+ end
188
+
189
+ it 'returns nil for level: 2' do
190
+ item_key = controller.active_navigation_item(level: 2)
191
+ expect(item_key).to be_nil
192
+ end
193
+
194
+ it 'returns nil for level: :all' do
195
+ item_key = controller.active_navigation_item(level: :all)
196
+ expect(item_key).to be_nil
141
197
  end
142
198
  end
143
-
144
- context 'with options specified' do
145
- it "should load the config-file for the specified context" do
146
- SimpleNavigation.should_receive(:load_config).with(:my_context)
147
- @controller.render_navigation(:context => :my_context)
199
+
200
+ context 'when an item is selected' do
201
+ context "and it's a primary item" do
202
+ let(:item) { :invoices }
203
+
204
+ it 'returns nil for no parameters' do
205
+ expect(controller.active_navigation_item).to be_nil
206
+ end
207
+
208
+ it "returns the selected item's name for level: 1" do
209
+ item_key = controller.active_navigation_item(level: 1)
210
+ expect(item_key).to be invoices_item
211
+ end
212
+
213
+ it 'returns nil for level: 2' do
214
+ item_key = controller.active_navigation_item(level: 2)
215
+ expect(item_key).to be_nil
216
+ end
217
+
218
+ it 'returns nil for level: :all' do
219
+ item_key = controller.active_navigation_item(level: :all)
220
+ expect(item_key).to be_nil
221
+ end
222
+ end
223
+
224
+ context "and it's a sub navigation item" do
225
+ before do
226
+ select_an_item(invoices_item)
227
+ select_an_item(unpaid_item)
228
+ end
229
+
230
+ it "returns the selected item's name for no parameters" do
231
+ expect(controller.active_navigation_item).to be unpaid_item
232
+ end
233
+
234
+ it "returns the selected item's parent name for level: 1" do
235
+ item_key = controller.active_navigation_item(level: 1)
236
+ expect(item_key).to be invoices_item
237
+ end
238
+
239
+ it "returns the selected item's name for level: 2" do
240
+ item_key = controller.active_navigation_item(level: 2)
241
+ expect(item_key).to eq unpaid_item
242
+ end
243
+
244
+ it "returns the selected item's name for level: :all" do
245
+ item_key = controller.active_navigation_item(level: :all)
246
+ expect(item_key).to eq unpaid_item
247
+ end
148
248
  end
149
249
  end
150
250
  end
151
-
152
- it "should eval the config on every request" do
153
- SimpleNavigation::Configuration.should_receive(:eval_config).with(:default)
154
- @controller.render_navigation
155
- end
156
-
157
- describe 'regarding setting of items' do
158
- context 'not items specified in options' do
159
- it "should not set the items directly" do
160
- SimpleNavigation.config.should_not_receive(:items)
161
- @controller.render_navigation
251
+
252
+ describe '#active_navigation_item_container' do
253
+ shared_examples 'returning items container' do
254
+ it 'returns the primary navigation for no parameters' do
255
+ expect(controller.active_navigation_item_container).to be navigation
162
256
  end
163
- end
164
- context 'items specified in options' do
165
- before(:each) do
166
- @items = stub(:items)
257
+
258
+ it "returns the primary navigation for level: 1" do
259
+ item_container = controller.active_navigation_item_container(level: 1)
260
+ expect(item_container).to be navigation
167
261
  end
168
- it "should set the items directly" do
169
- SimpleNavigation.config.should_receive(:items).with(@items)
170
- @controller.render_navigation(:items => @items)
262
+
263
+ it 'returns the primary navigation level: :all' do
264
+ item_container =
265
+ controller.active_navigation_item_container(level: :all)
266
+ expect(item_container).to be navigation
171
267
  end
172
268
  end
173
- context 'block given' do
174
- it 'should use block' do
175
- block_executed = 0
176
- expect do
177
- @controller.render_navigation do |menu|
178
- menu.class.should == SimpleNavigation::ItemContainer
179
- block_executed += 1
180
- end
181
- end.to change{block_executed}.by(1)
269
+
270
+ context 'when no item is selected' do
271
+ it_behaves_like 'returning items container'
272
+
273
+ it 'returns nil for level: 2' do
274
+ item_container = controller.active_navigation_item_container(level: 2)
275
+ expect(item_container).to be_nil
182
276
  end
183
277
  end
184
- end
185
-
186
- describe 'no primary navigation defined' do
187
- before(:each) do
188
- SimpleNavigation.stub!(:primary_navigation => nil)
278
+
279
+ context 'when an item is selected' do
280
+ context "and it's a primary item" do
281
+ let(:item) { :invoices }
282
+
283
+ it_behaves_like 'returning items container'
284
+
285
+ it 'returns the invoices items container for level: 2' do
286
+ item_container =
287
+ controller.active_navigation_item_container(level: 2)
288
+ expect(item_container).to be invoices_item.sub_navigation
289
+ end
290
+ end
291
+
292
+ context "and it's a sub navigation item" do
293
+ before do
294
+ select_an_item(invoices_item)
295
+ select_an_item(unpaid_item)
296
+ end
297
+
298
+ it_behaves_like 'returning items container'
299
+
300
+ it 'returns the invoices items container for level: 2' do
301
+ item_container =
302
+ controller.active_navigation_item_container(level: 2)
303
+ expect(item_container).to be invoices_item.sub_navigation
304
+ end
305
+ end
189
306
  end
190
- it {lambda {@controller.render_navigation}.should raise_error}
191
307
  end
192
-
193
- context 'rendering of the item_container' do
194
- before(:each) do
195
- @active_item_container = stub(:item_container).as_null_object
196
- SimpleNavigation.stub!(:active_item_container_for => @active_item_container)
308
+
309
+ describe '#render_navigation' do
310
+ it 'evaluates the configuration on every request' do
311
+ expect(SimpleNavigation).to receive(:load_config).twice
312
+ 2.times { controller.render_navigation }
197
313
  end
198
- it "should lookup the active_item_container based on the level" do
199
- SimpleNavigation.should_receive(:active_item_container_for).with(:all)
200
- @controller.render_navigation
314
+
315
+ it 'loads the :default configuration' do
316
+ expect(SimpleNavigation).to receive(:load_config).with(:default)
317
+ controller.render_navigation
201
318
  end
202
- context 'active_item_container is nil' do
203
- before(:each) do
204
- SimpleNavigation.stub!(:active_item_container_for => nil)
205
- end
206
- it "should not call render" do
207
- @active_item_container.should_not_receive(:render)
208
- @controller.render_navigation
209
- end
319
+
320
+ it "doesn't set the items directly" do
321
+ expect(SimpleNavigation.config).not_to receive(:items)
322
+ controller.render_navigation
323
+ end
324
+
325
+ it 'looks up the active_item_container based on the level' do
326
+ expect(SimpleNavigation).to receive(:active_item_container_for)
327
+ .with(:all)
328
+ controller.render_navigation
210
329
  end
211
- context 'active_item_container is not nil' do
212
- it "should call render on the container" do
213
- @active_item_container.should_receive(:render)
214
- @controller.render_navigation
330
+
331
+ context 'when the :context option is specified' do
332
+ it 'loads the configuration for the specified context' do
333
+ expect(SimpleNavigation).to receive(:load_config).with(:my_context)
334
+ controller.render_navigation(context: :my_context)
215
335
  end
216
336
  end
217
- end
218
-
219
- context 'primary' do
220
- it "should call render on the primary_navigation (specifying level through options)" do
221
- @primary_navigation.should_receive(:render).with(:level => 1)
222
- @controller.render_navigation(:level => 1)
337
+
338
+ context 'when the :items option is specified' do
339
+ let(:items) { double(:items) }
340
+
341
+ it 'sets the items directly' do
342
+ expect(SimpleNavigation.config).to receive(:items).with(items)
343
+ controller.render_navigation(items: items)
344
+ end
223
345
  end
224
- end
225
-
226
- context 'secondary' do
227
- context 'with current_primary_navigation set' do
228
- before(:each) do
229
- @selected_item_container = stub(:selected_container).as_null_object
230
- SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
346
+
347
+ context 'when the :level option is set' do
348
+ context 'and its value is 1' do
349
+ it 'calls render on the primary navigation' do
350
+ expect(navigation).to receive(:render).with(level: 1)
351
+ controller.render_navigation(level: 1)
352
+ end
231
353
  end
232
- it "should find the selected sub_navigation for the specified level" do
233
- SimpleNavigation.should_receive(:active_item_container_for).with(2)
234
- @controller.render_navigation(:level => 2)
354
+
355
+ context 'and its value is 2' do
356
+ context 'and the active_item_container is set' do
357
+ let(:item_container) { double(:container).as_null_object }
358
+
359
+ before do
360
+ SimpleNavigation.stub(active_item_container_for: item_container)
361
+ end
362
+
363
+ it 'finds the selected sub navigation for the specified level' do
364
+ expect(SimpleNavigation).to receive(:active_item_container_for)
365
+ .with(2)
366
+ controller.render_navigation(level: 2)
367
+ end
368
+
369
+ it 'calls render on the active item_container' do
370
+ expect(item_container).to receive(:render).with(level: 2)
371
+ controller.render_navigation(level: 2)
372
+ end
373
+ end
374
+
375
+ context "and the active_item_container isn't set" do
376
+ it "doesn't raise an exception" do
377
+ expect{
378
+ controller.render_navigation(level: 2)
379
+ }.not_to raise_error
380
+ end
381
+ end
235
382
  end
236
- it "should find the selected sub_navigation for the specified level" do
237
- SimpleNavigation.should_receive(:active_item_container_for).with(1)
238
- @controller.render_navigation(:level => 1)
383
+
384
+ context "and its value isn't a valid level" do
385
+ it 'raises an exception' do
386
+ expect{
387
+ controller.render_navigation(level: :invalid)
388
+ }.to raise_error
389
+ end
239
390
  end
240
- it "should call render on the active item_container" do
241
- @selected_item_container.should_receive(:render).with(:level => 2)
242
- @controller.render_navigation(:level => 2)
391
+ end
392
+
393
+ context 'when the :levels option is set' do
394
+ before { SimpleNavigation.stub(active_item_container_for: navigation) }
395
+
396
+ it 'treats it like the :level option' do
397
+ expect(navigation).to receive(:render).with(level: 2)
398
+ controller.render_navigation(levels: 2)
243
399
  end
244
400
  end
245
- context 'without an active item_container set' do
246
- before(:each) do
247
- SimpleNavigation.stub!(:active_item_container_for => nil)
401
+
402
+ context 'when a block is given' do
403
+ it 'calls the block passing it an item container' do
404
+ expect{ |blk|
405
+ controller.render_navigation(&blk)
406
+ }.to yield_with_args(ItemContainer)
248
407
  end
249
- it "should not raise an error" do
250
- lambda {@controller.render_navigation(:level => 2)}.should_not raise_error
408
+ end
409
+
410
+ context 'when no primary configuration is defined' do
411
+ before { SimpleNavigation.stub(primary_navigation: nil) }
412
+
413
+ it 'raises an exception' do
414
+ expect{controller.render_navigation}.to raise_error
251
415
  end
252
416
  end
253
-
254
- end
255
-
256
- context 'unknown level' do
257
- it "should raise an error" do
258
- lambda {@controller.render_navigation(:level => :unknown)}.should raise_error(ArgumentError)
417
+
418
+ context "when active_item_container is set" do
419
+ let(:active_item_container) { double(:container).as_null_object }
420
+
421
+ before do
422
+ SimpleNavigation.stub(active_item_container_for: active_item_container)
423
+ end
424
+
425
+ it 'calls render on the active_item_container' do
426
+ expect(active_item_container).to receive(:render)
427
+ controller.render_navigation
428
+ end
259
429
  end
260
430
  end
261
-
262
431
  end
263
-
264
- describe "should treat :level and :levels options the same" do
265
- before(:each) do
266
- whitebox_setup
267
- @selected_item_container = stub(:selected_container).as_null_object
268
- SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
269
- end
270
- it "should pass a valid levels options as level" do
271
- @selected_item_container.should_receive(:render).with(:level => 2)
272
- @controller.render_navigation(:levels => 2)
273
- end
274
- end
275
-
276
432
  end