simple-navigation 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +84 -0
- data/.rspec +1 -2
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +38 -0
- data/Appraisals +55 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +21 -0
- data/Guardfile +4 -2
- data/README.md +11 -23
- data/Rakefile +2 -27
- data/bin/_guard-core +16 -0
- data/bin/appraisal +16 -0
- data/bin/guard +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/gemfiles/rails_6.1.gemfile +35 -0
- data/gemfiles/rails_7.0.gemfile +23 -0
- data/gemfiles/rails_7.1.gemfile +23 -0
- data/gemfiles/rails_7.2.gemfile +23 -0
- data/gemfiles/rails_8.0.gemfile +23 -0
- data/gemfiles/rails_8.1.gemfile +23 -0
- data/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/generators/navigation_config/templates/config/navigation.rb +30 -26
- data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/lib/simple-navigation.rb +3 -1
- data/lib/simple_navigation/adapters/base.rb +2 -0
- data/lib/simple_navigation/adapters/nanoc.rb +8 -3
- data/lib/simple_navigation/adapters/padrino.rb +3 -1
- data/lib/simple_navigation/adapters/rails.rb +12 -14
- data/lib/simple_navigation/adapters/sinatra.rb +4 -6
- data/lib/simple_navigation/config_file.rb +1 -1
- data/lib/simple_navigation/config_file_finder.rb +3 -3
- data/lib/simple_navigation/configuration.rb +5 -5
- data/lib/simple_navigation/helpers.rb +9 -11
- data/lib/simple_navigation/item.rb +26 -20
- data/lib/simple_navigation/item_adapter.rb +16 -5
- data/lib/simple_navigation/item_container.rb +13 -7
- data/lib/simple_navigation/items_provider.rb +6 -4
- data/lib/simple_navigation/railtie.rb +3 -1
- data/lib/simple_navigation/renderer/base.rb +5 -5
- data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
- data/lib/simple_navigation/renderer/json.rb +1 -1
- data/lib/simple_navigation/renderer/links.rb +2 -0
- data/lib/simple_navigation/renderer/list.rb +5 -5
- data/lib/simple_navigation/renderer/text.rb +3 -1
- data/lib/simple_navigation/version.rb +3 -1
- data/lib/simple_navigation.rb +32 -24
- data/simple-navigation.gemspec +16 -27
- data/spec/fake_app/config/navigation.rb +4 -2
- data/spec/fake_app/rails_app.rb +5 -3
- data/spec/integration/rendering_navigation_spec.rb +7 -5
- data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
- data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
- data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
- data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
- data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
- data/spec/simple_navigation/config_file_spec.rb +14 -14
- data/spec/simple_navigation/configuration_spec.rb +128 -121
- data/spec/simple_navigation/helpers_spec.rb +282 -284
- data/spec/simple_navigation/item_adapter_spec.rb +109 -122
- data/spec/simple_navigation/item_container_spec.rb +407 -408
- data/spec/simple_navigation/item_spec.rb +333 -301
- data/spec/simple_navigation/items_provider_spec.rb +30 -27
- data/spec/simple_navigation/renderer/base_spec.rb +166 -168
- data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
- data/spec/simple_navigation/renderer/json_spec.rb +49 -56
- data/spec/simple_navigation/renderer/links_spec.rb +81 -83
- data/spec/simple_navigation/renderer/list_spec.rb +111 -91
- data/spec/simple_navigation/renderer/text_spec.rb +37 -39
- data/spec/simple_navigation_spec.rb +54 -47
- data/spec/spec_helper.rb +146 -53
- metadata +25 -164
- data/.travis.yml +0 -23
- data/gemfiles/rails-3-2-stable.gemfile +0 -11
- data/gemfiles/rails-4-1-stable.gemfile +0 -7
- data/gemfiles/rails-4-2-stable.gemfile +0 -7
- data/gemfiles/rails-5-2-stable.gemfile +0 -7
- data/gemfiles/rails-6-0-stable.gemfile +0 -9
- data/gemfiles/rails-6-1-stable.gemfile +0 -9
- data/init.rb +0 -1
- data/install.rb +0 -5
- data/lib/simple_navigation/adapters.rb +0 -10
- data/lib/simple_navigation/renderer.rb +0 -12
- data/spec/initializers/coveralls.rb +0 -3
- data/spec/initializers/have_css_matcher.rb +0 -19
- data/spec/initializers/memfs.rb +0 -7
- data/spec/initializers/rails.rb +0 -4
- data/spec/initializers/rspec.rb +0 -7
- data/uninstall.rb +0 -1
|
@@ -1,34 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe SimpleNavigation::Helpers do
|
|
4
|
+
subject(:controller) { test_controller_class.new }
|
|
5
|
+
|
|
6
|
+
let(:invoices_item) { navigation[:invoices] }
|
|
7
|
+
let(:item) { nil }
|
|
8
|
+
let(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
|
9
|
+
let(:test_controller_class) do
|
|
10
|
+
Class.new { include SimpleNavigation::Helpers }
|
|
11
|
+
end
|
|
12
|
+
let(:unpaid_item) { invoices_item.sub_navigation[:unpaid] }
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
allow(SimpleNavigation::Configuration).to receive(:eval_config)
|
|
16
|
+
allow(SimpleNavigation).to receive_messages(load_config: nil,
|
|
17
|
+
primary_navigation: navigation,
|
|
18
|
+
config_file?: true,
|
|
19
|
+
context_for_eval: controller)
|
|
20
|
+
|
|
21
|
+
select_an_item(navigation[item]) if item
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#active_navigation_item_name' do
|
|
25
|
+
context 'when no item is selected' do
|
|
26
|
+
it 'returns an empty string for no parameters' do
|
|
27
|
+
expect(controller.active_navigation_item_name).to eq ''
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'returns an empty string for level: 1' do
|
|
31
|
+
item_name = controller.active_navigation_item_name(level: 1)
|
|
32
|
+
expect(item_name).to eq ''
|
|
33
|
+
end
|
|
12
34
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
config_file?: true,
|
|
18
|
-
context_for_eval: controller)
|
|
35
|
+
it 'returns an empty string for level: 2' do
|
|
36
|
+
item_name = controller.active_navigation_item_name(level: 2)
|
|
37
|
+
expect(item_name).to eq ''
|
|
38
|
+
end
|
|
19
39
|
|
|
20
|
-
|
|
40
|
+
it 'returns an empty string for level: :all' do
|
|
41
|
+
item_name = controller.active_navigation_item_name(level: :all)
|
|
42
|
+
expect(item_name).to eq ''
|
|
43
|
+
end
|
|
21
44
|
end
|
|
22
45
|
|
|
23
|
-
|
|
24
|
-
context
|
|
25
|
-
|
|
46
|
+
context 'when an item is selected' do
|
|
47
|
+
context "when it's a primary item" do
|
|
48
|
+
let(:item) { :invoices }
|
|
49
|
+
|
|
50
|
+
it 'returns an empty string' do
|
|
26
51
|
expect(controller.active_navigation_item_name).to eq ''
|
|
27
52
|
end
|
|
28
53
|
|
|
29
|
-
it "returns
|
|
54
|
+
it "returns the selected item's name for level: 1" do
|
|
30
55
|
item_name = controller.active_navigation_item_name(level: 1)
|
|
31
|
-
expect(item_name).to eq ''
|
|
56
|
+
expect(item_name).to eq 'Invoices'
|
|
32
57
|
end
|
|
33
58
|
|
|
34
59
|
it 'returns an empty string for level: 2' do
|
|
@@ -42,71 +67,67 @@ module SimpleNavigation
|
|
|
42
67
|
end
|
|
43
68
|
end
|
|
44
69
|
|
|
45
|
-
context
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
expect(controller.active_navigation_item_name).to eq ''
|
|
51
|
-
end
|
|
70
|
+
context "when it's a sub navigation item" do
|
|
71
|
+
before do
|
|
72
|
+
select_an_item(invoices_item)
|
|
73
|
+
select_an_item(unpaid_item)
|
|
74
|
+
end
|
|
52
75
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
76
|
+
it "returns the selected item's name" do
|
|
77
|
+
expect(controller.active_navigation_item_name).to eq 'Unpaid'
|
|
78
|
+
end
|
|
57
79
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
it "returns the selected item's parent name for level: 1" do
|
|
81
|
+
item_name = controller.active_navigation_item_name(level: 1)
|
|
82
|
+
expect(item_name).to eq 'Invoices'
|
|
83
|
+
end
|
|
62
84
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
end
|
|
85
|
+
it "returns the selected item's name for level: 2" do
|
|
86
|
+
item_name = controller.active_navigation_item_name(level: 2)
|
|
87
|
+
expect(item_name).to eq 'Unpaid'
|
|
67
88
|
end
|
|
68
89
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
it "returns the selected item's name for level: :all" do
|
|
91
|
+
item_name = controller.active_navigation_item_name(level: :all)
|
|
92
|
+
expect(item_name).to eq 'Unpaid'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
74
97
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
describe '#active_navigation_item_key' do
|
|
99
|
+
context 'when no item is selected' do
|
|
100
|
+
it 'returns nil for no parameters' do
|
|
101
|
+
expect(controller.active_navigation_item_key).to be_nil
|
|
102
|
+
end
|
|
78
103
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
it 'returns nil for level: 1' do
|
|
105
|
+
item_key = controller.active_navigation_item_key(level: 1)
|
|
106
|
+
expect(item_key).to be_nil
|
|
107
|
+
end
|
|
83
108
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
it 'returns nil for level: 2' do
|
|
110
|
+
item_key = controller.active_navigation_item_key(level: 2)
|
|
111
|
+
expect(item_key).to be_nil
|
|
112
|
+
end
|
|
88
113
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
end
|
|
114
|
+
it 'returns nil for level: :all' do
|
|
115
|
+
item_key = controller.active_navigation_item_key(level: :all)
|
|
116
|
+
expect(item_key).to be_nil
|
|
94
117
|
end
|
|
95
118
|
end
|
|
96
119
|
|
|
97
|
-
|
|
98
|
-
context
|
|
99
|
-
|
|
100
|
-
expect(controller.active_navigation_item_key).to be_nil
|
|
101
|
-
end
|
|
120
|
+
context 'when an item is selected' do
|
|
121
|
+
context "when it's a primary item" do
|
|
122
|
+
let(:item) { :invoices }
|
|
102
123
|
|
|
103
124
|
it 'returns nil for no parameters' do
|
|
104
125
|
expect(controller.active_navigation_item_key).to be_nil
|
|
105
126
|
end
|
|
106
127
|
|
|
107
|
-
it "returns
|
|
128
|
+
it "returns the selected item's name for level: 1" do
|
|
108
129
|
item_key = controller.active_navigation_item_key(level: 1)
|
|
109
|
-
expect(item_key).to
|
|
130
|
+
expect(item_key).to eq :invoices
|
|
110
131
|
end
|
|
111
132
|
|
|
112
133
|
it 'returns nil for level: 2' do
|
|
@@ -120,67 +141,67 @@ module SimpleNavigation
|
|
|
120
141
|
end
|
|
121
142
|
end
|
|
122
143
|
|
|
123
|
-
context
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
expect(controller.active_navigation_item_key).to be_nil
|
|
129
|
-
end
|
|
144
|
+
context "when it's a sub navigation item" do
|
|
145
|
+
before do
|
|
146
|
+
select_an_item(invoices_item)
|
|
147
|
+
select_an_item(unpaid_item)
|
|
148
|
+
end
|
|
130
149
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
end
|
|
150
|
+
it "returns the selected item's name" do
|
|
151
|
+
expect(controller.active_navigation_item_key).to eq :unpaid
|
|
152
|
+
end
|
|
135
153
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
154
|
+
it "returns the selected item's parent name for level: 1" do
|
|
155
|
+
item_key = controller.active_navigation_item_key(level: 1)
|
|
156
|
+
expect(item_key).to eq :invoices
|
|
157
|
+
end
|
|
140
158
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
end
|
|
159
|
+
it "returns the selected item's name for level: 2" do
|
|
160
|
+
item_key = controller.active_navigation_item_key(level: 2)
|
|
161
|
+
expect(item_key).to eq :unpaid
|
|
145
162
|
end
|
|
146
163
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
164
|
+
it "returns the selected item's name for level: :all" do
|
|
165
|
+
item_key = controller.active_navigation_item_key(level: :all)
|
|
166
|
+
expect(item_key).to eq :unpaid
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
152
171
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
describe '#active_navigation_item' do
|
|
173
|
+
context 'when no item is selected' do
|
|
174
|
+
it 'returns nil for no parameters' do
|
|
175
|
+
expect(controller.active_navigation_item).to be_nil
|
|
176
|
+
end
|
|
156
177
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
178
|
+
it 'returns nil for level: 1' do
|
|
179
|
+
item_key = controller.active_navigation_item(level: 1)
|
|
180
|
+
expect(item_key).to be_nil
|
|
181
|
+
end
|
|
161
182
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
183
|
+
it 'returns nil for level: 2' do
|
|
184
|
+
item_key = controller.active_navigation_item(level: 2)
|
|
185
|
+
expect(item_key).to be_nil
|
|
186
|
+
end
|
|
166
187
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
end
|
|
171
|
-
end
|
|
188
|
+
it 'returns nil for level: :all' do
|
|
189
|
+
item_key = controller.active_navigation_item(level: :all)
|
|
190
|
+
expect(item_key).to be_nil
|
|
172
191
|
end
|
|
173
192
|
end
|
|
174
193
|
|
|
175
|
-
|
|
176
|
-
context
|
|
194
|
+
context 'when an item is selected' do
|
|
195
|
+
context "when it's a primary item" do
|
|
196
|
+
let(:item) { :invoices }
|
|
197
|
+
|
|
177
198
|
it 'returns nil for no parameters' do
|
|
178
199
|
expect(controller.active_navigation_item).to be_nil
|
|
179
200
|
end
|
|
180
201
|
|
|
181
|
-
it "returns
|
|
202
|
+
it "returns the selected item's name for level: 1" do
|
|
182
203
|
item_key = controller.active_navigation_item(level: 1)
|
|
183
|
-
expect(item_key).to
|
|
204
|
+
expect(item_key).to be invoices_item
|
|
184
205
|
end
|
|
185
206
|
|
|
186
207
|
it 'returns nil for level: 2' do
|
|
@@ -194,235 +215,212 @@ module SimpleNavigation
|
|
|
194
215
|
end
|
|
195
216
|
end
|
|
196
217
|
|
|
197
|
-
context
|
|
198
|
-
|
|
199
|
-
|
|
218
|
+
context "when it's a sub navigation item" do
|
|
219
|
+
before do
|
|
220
|
+
select_an_item(invoices_item)
|
|
221
|
+
select_an_item(unpaid_item)
|
|
222
|
+
end
|
|
200
223
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
it "returns the selected item's name for no parameters" do
|
|
225
|
+
expect(controller.active_navigation_item).to be unpaid_item
|
|
226
|
+
end
|
|
204
227
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
228
|
+
it "returns the selected item's parent name for level: 1" do
|
|
229
|
+
item_key = controller.active_navigation_item(level: 1)
|
|
230
|
+
expect(item_key).to be invoices_item
|
|
231
|
+
end
|
|
209
232
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
it "returns the selected item's name for level: 2" do
|
|
234
|
+
item_key = controller.active_navigation_item(level: 2)
|
|
235
|
+
expect(item_key).to eq unpaid_item
|
|
236
|
+
end
|
|
214
237
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
end
|
|
238
|
+
it "returns the selected item's name for level: :all" do
|
|
239
|
+
item_key = controller.active_navigation_item(level: :all)
|
|
240
|
+
expect(item_key).to eq unpaid_item
|
|
219
241
|
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
220
245
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
246
|
+
describe '#active_navigation_item_container' do
|
|
247
|
+
shared_examples 'returning items container' do
|
|
248
|
+
it 'returns the primary navigation for no parameters' do
|
|
249
|
+
expect(controller.active_navigation_item_container).to be navigation
|
|
250
|
+
end
|
|
226
251
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
252
|
+
it 'returns the primary navigation for level: 1' do
|
|
253
|
+
item_container = controller.active_navigation_item_container(level: 1)
|
|
254
|
+
expect(item_container).to be navigation
|
|
255
|
+
end
|
|
230
256
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
257
|
+
it 'returns the primary navigation level: :all' do
|
|
258
|
+
item_container =
|
|
259
|
+
controller.active_navigation_item_container(level: :all)
|
|
260
|
+
expect(item_container).to be navigation
|
|
261
|
+
end
|
|
262
|
+
end
|
|
235
263
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
expect(item_key).to eq unpaid_item
|
|
239
|
-
end
|
|
264
|
+
context 'when no item is selected' do
|
|
265
|
+
it_behaves_like 'returning items container'
|
|
240
266
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
end
|
|
267
|
+
it 'returns nil for level: 2' do
|
|
268
|
+
item_container = controller.active_navigation_item_container(level: 2)
|
|
269
|
+
expect(item_container).to be_nil
|
|
246
270
|
end
|
|
247
271
|
end
|
|
248
272
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
expect(controller.active_navigation_item_container).to be navigation
|
|
253
|
-
end
|
|
273
|
+
context 'when an item is selected' do
|
|
274
|
+
context "when it's a primary item" do
|
|
275
|
+
let(:item) { :invoices }
|
|
254
276
|
|
|
255
|
-
|
|
256
|
-
item_container = controller.active_navigation_item_container(level: 1)
|
|
257
|
-
expect(item_container).to be navigation
|
|
258
|
-
end
|
|
277
|
+
it_behaves_like 'returning items container'
|
|
259
278
|
|
|
260
|
-
it 'returns the
|
|
279
|
+
it 'returns the invoices items container for level: 2' do
|
|
261
280
|
item_container =
|
|
262
|
-
controller.active_navigation_item_container(level:
|
|
263
|
-
expect(item_container).to be
|
|
281
|
+
controller.active_navigation_item_container(level: 2)
|
|
282
|
+
expect(item_container).to be invoices_item.sub_navigation
|
|
264
283
|
end
|
|
265
284
|
end
|
|
266
285
|
|
|
267
|
-
context
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
item_container = controller.active_navigation_item_container(level: 2)
|
|
272
|
-
expect(item_container).to be_nil
|
|
286
|
+
context "when it's a sub navigation item" do
|
|
287
|
+
before do
|
|
288
|
+
select_an_item(invoices_item)
|
|
289
|
+
select_an_item(unpaid_item)
|
|
273
290
|
end
|
|
274
|
-
end
|
|
275
291
|
|
|
276
|
-
|
|
277
|
-
context "and it's a primary item" do
|
|
278
|
-
let(:item) { :invoices }
|
|
279
|
-
|
|
280
|
-
it_behaves_like 'returning items container'
|
|
292
|
+
it_behaves_like 'returning items container'
|
|
281
293
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
end
|
|
294
|
+
it 'returns the invoices items container for level: 2' do
|
|
295
|
+
item_container =
|
|
296
|
+
controller.active_navigation_item_container(level: 2)
|
|
297
|
+
expect(item_container).to be invoices_item.sub_navigation
|
|
287
298
|
end
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
288
302
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
303
|
+
describe '#render_navigation' do
|
|
304
|
+
it 'evaluates the configuration on every request' do
|
|
305
|
+
expect(SimpleNavigation).to receive(:load_config).twice
|
|
306
|
+
2.times { controller.render_navigation }
|
|
307
|
+
end
|
|
294
308
|
|
|
295
|
-
|
|
309
|
+
it 'loads the :default configuration' do
|
|
310
|
+
expect(SimpleNavigation).to receive(:load_config).with(:default)
|
|
311
|
+
controller.render_navigation
|
|
312
|
+
end
|
|
296
313
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
expect(item_container).to be invoices_item.sub_navigation
|
|
301
|
-
end
|
|
302
|
-
end
|
|
303
|
-
end
|
|
314
|
+
it "doesn't set the items directly" do
|
|
315
|
+
expect(SimpleNavigation.config).not_to receive(:items)
|
|
316
|
+
controller.render_navigation
|
|
304
317
|
end
|
|
305
318
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
319
|
+
it 'looks up the active_item_container based on the level' do
|
|
320
|
+
expect(SimpleNavigation).to receive(:active_item_container_for)
|
|
321
|
+
.with(:all)
|
|
322
|
+
controller.render_navigation
|
|
323
|
+
end
|
|
311
324
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
325
|
+
context 'when the :context option is specified' do
|
|
326
|
+
it 'loads the configuration for the specified context' do
|
|
327
|
+
expect(SimpleNavigation).to receive(:load_config).with(:my_context)
|
|
328
|
+
controller.render_navigation(context: :my_context)
|
|
315
329
|
end
|
|
330
|
+
end
|
|
316
331
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
controller.render_navigation
|
|
320
|
-
end
|
|
332
|
+
context 'when the :items option is specified' do
|
|
333
|
+
let(:items) { double(:items) }
|
|
321
334
|
|
|
322
|
-
it '
|
|
323
|
-
expect(SimpleNavigation).to receive(:
|
|
324
|
-
|
|
325
|
-
controller.render_navigation
|
|
335
|
+
it 'sets the items directly' do
|
|
336
|
+
expect(SimpleNavigation.config).to receive(:items).with(items)
|
|
337
|
+
controller.render_navigation(items: items)
|
|
326
338
|
end
|
|
339
|
+
end
|
|
327
340
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
341
|
+
context 'when the :level option is set' do
|
|
342
|
+
context 'when its value is 1' do
|
|
343
|
+
it 'calls render on the primary navigation' do
|
|
344
|
+
expect(navigation).to receive(:render).with({ level: 1 })
|
|
345
|
+
controller.render_navigation(level: 1)
|
|
332
346
|
end
|
|
333
347
|
end
|
|
334
348
|
|
|
335
|
-
context 'when
|
|
336
|
-
|
|
349
|
+
context 'when its value is 2' do
|
|
350
|
+
context 'when the active_item_container is set' do
|
|
351
|
+
let(:item_container) { double(:container).as_null_object }
|
|
337
352
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
controller.render_navigation(items: items)
|
|
341
|
-
end
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
context 'when the :level option is set' do
|
|
345
|
-
context 'and its value is 1' do
|
|
346
|
-
it 'calls render on the primary navigation' do
|
|
347
|
-
expect(navigation).to receive(:render).with(level: 1)
|
|
348
|
-
controller.render_navigation(level: 1)
|
|
353
|
+
before do
|
|
354
|
+
allow(SimpleNavigation).to receive_messages(active_item_container_for: item_container)
|
|
349
355
|
end
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
context 'and its value is 2' do
|
|
353
|
-
context 'and the active_item_container is set' do
|
|
354
|
-
let(:item_container) { double(:container).as_null_object }
|
|
355
|
-
|
|
356
|
-
before do
|
|
357
|
-
allow(SimpleNavigation).to receive_messages(active_item_container_for: item_container)
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
it 'finds the selected sub navigation for the specified level' do
|
|
361
|
-
expect(SimpleNavigation).to receive(:active_item_container_for)
|
|
362
|
-
.with(2)
|
|
363
|
-
controller.render_navigation(level: 2)
|
|
364
|
-
end
|
|
365
356
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
357
|
+
it 'finds the selected sub navigation for the specified level' do
|
|
358
|
+
expect(SimpleNavigation).to receive(:active_item_container_for)
|
|
359
|
+
.with(2)
|
|
360
|
+
controller.render_navigation(level: 2)
|
|
370
361
|
end
|
|
371
362
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
controller.render_navigation(level: 2)
|
|
376
|
-
}.not_to raise_error
|
|
377
|
-
end
|
|
363
|
+
it 'calls render on the active item_container' do
|
|
364
|
+
expect(item_container).to receive(:render).with({ level: 2 })
|
|
365
|
+
controller.render_navigation(level: 2)
|
|
378
366
|
end
|
|
379
367
|
end
|
|
380
368
|
|
|
381
|
-
context "
|
|
382
|
-
it '
|
|
383
|
-
expect
|
|
384
|
-
controller.render_navigation(level:
|
|
385
|
-
|
|
369
|
+
context "when the active_item_container isn't set" do
|
|
370
|
+
it "doesn't raise an exception" do
|
|
371
|
+
expect do
|
|
372
|
+
controller.render_navigation(level: 2)
|
|
373
|
+
end.not_to raise_error
|
|
386
374
|
end
|
|
387
375
|
end
|
|
388
376
|
end
|
|
389
377
|
|
|
390
|
-
context
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
controller.render_navigation(levels: 2)
|
|
378
|
+
context "when its value isn't a valid level" do
|
|
379
|
+
it 'raises an exception' do
|
|
380
|
+
expect do
|
|
381
|
+
controller.render_navigation(level: :invalid)
|
|
382
|
+
end.to raise_error(ArgumentError, 'Invalid navigation level: invalid')
|
|
396
383
|
end
|
|
397
384
|
end
|
|
385
|
+
end
|
|
398
386
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
387
|
+
context 'when the :levels option is set' do
|
|
388
|
+
before { allow(SimpleNavigation).to receive_messages(active_item_container_for: navigation) }
|
|
389
|
+
|
|
390
|
+
it 'treats it like the :level option' do
|
|
391
|
+
expect(navigation).to receive(:render).with({ level: 2 })
|
|
392
|
+
controller.render_navigation(levels: 2)
|
|
405
393
|
end
|
|
394
|
+
end
|
|
406
395
|
|
|
407
|
-
|
|
408
|
-
|
|
396
|
+
context 'when a block is given' do
|
|
397
|
+
it 'calls the block passing it an item container' do
|
|
398
|
+
expect do |blk|
|
|
399
|
+
controller.render_navigation(&blk)
|
|
400
|
+
end.to yield_with_args(SimpleNavigation::ItemContainer)
|
|
401
|
+
end
|
|
402
|
+
end
|
|
409
403
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
404
|
+
context 'when no primary configuration is defined' do
|
|
405
|
+
before { allow(SimpleNavigation).to receive_messages(primary_navigation: nil) }
|
|
406
|
+
|
|
407
|
+
it 'raises an exception' do
|
|
408
|
+
message = 'no primary navigation defined, either use a navigation config file or ' \
|
|
409
|
+
'pass items directly to render_navigation'
|
|
410
|
+
expect { controller.render_navigation }.to raise_error(RuntimeError, message)
|
|
413
411
|
end
|
|
412
|
+
end
|
|
414
413
|
|
|
415
|
-
|
|
416
|
-
|
|
414
|
+
context 'when active_item_container is set' do
|
|
415
|
+
let(:active_item_container) { double(:container).as_null_object }
|
|
417
416
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
417
|
+
before do
|
|
418
|
+
allow(SimpleNavigation).to receive_messages(active_item_container_for: active_item_container)
|
|
419
|
+
end
|
|
421
420
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
end
|
|
421
|
+
it 'calls render on the active_item_container' do
|
|
422
|
+
expect(active_item_container).to receive(:render)
|
|
423
|
+
controller.render_navigation
|
|
426
424
|
end
|
|
427
425
|
end
|
|
428
426
|
end
|