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.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +11 -0
- data/Gemfile +2 -16
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -39
- data/generators/navigation_config/templates/config/navigation.rb +7 -5
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/adapters/rails.rb +5 -1
- data/lib/simple_navigation/core/configuration.rb +5 -1
- data/lib/simple_navigation/core/item.rb +2 -1
- data/lib/simple_navigation/core/item_adapter.rb +4 -4
- data/lib/simple_navigation/core/item_container.rb +6 -1
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
- data/lib/simple_navigation/version.rb +3 -0
- data/lib/simple_navigation.rb +1 -0
- data/simple-navigation.gemspec +40 -0
- data/spec/initializers/have_css_matcher.rb +13 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
- data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
- data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
- data/spec/lib/simple_navigation_spec.rb +207 -225
- data/spec/spec_helper.rb +53 -82
- data/uninstall.rb +1 -0
- metadata +100 -22
- data/README +0 -22
- data/VERSION +0 -1
@@ -1,276 +1,432 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
3
|
+
class TestController
|
4
|
+
include SimpleNavigation::Helpers
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
before(:each) do
|
30
|
-
blackbox_setup
|
23
|
+
select_an_item(navigation[item]) if item
|
31
24
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
75
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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 '
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
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
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
250
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|