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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +84 -0
  3. data/.rspec +1 -2
  4. data/.rubocop.yml +49 -0
  5. data/.rubocop_todo.yml +38 -0
  6. data/Appraisals +55 -0
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +21 -0
  9. data/Guardfile +4 -2
  10. data/README.md +11 -23
  11. data/Rakefile +2 -27
  12. data/bin/_guard-core +16 -0
  13. data/bin/appraisal +16 -0
  14. data/bin/guard +16 -0
  15. data/bin/rake +16 -0
  16. data/bin/rspec +16 -0
  17. data/bin/rubocop +16 -0
  18. data/gemfiles/rails_6.1.gemfile +35 -0
  19. data/gemfiles/rails_7.0.gemfile +23 -0
  20. data/gemfiles/rails_7.1.gemfile +23 -0
  21. data/gemfiles/rails_7.2.gemfile +23 -0
  22. data/gemfiles/rails_8.0.gemfile +23 -0
  23. data/gemfiles/rails_8.1.gemfile +23 -0
  24. data/generators/navigation_config/navigation_config_generator.rb +2 -0
  25. data/generators/navigation_config/templates/config/navigation.rb +30 -26
  26. data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
  27. data/lib/simple-navigation.rb +3 -1
  28. data/lib/simple_navigation/adapters/base.rb +2 -0
  29. data/lib/simple_navigation/adapters/nanoc.rb +8 -3
  30. data/lib/simple_navigation/adapters/padrino.rb +3 -1
  31. data/lib/simple_navigation/adapters/rails.rb +12 -14
  32. data/lib/simple_navigation/adapters/sinatra.rb +4 -6
  33. data/lib/simple_navigation/config_file.rb +1 -1
  34. data/lib/simple_navigation/config_file_finder.rb +3 -3
  35. data/lib/simple_navigation/configuration.rb +5 -5
  36. data/lib/simple_navigation/helpers.rb +9 -11
  37. data/lib/simple_navigation/item.rb +26 -20
  38. data/lib/simple_navigation/item_adapter.rb +16 -5
  39. data/lib/simple_navigation/item_container.rb +13 -7
  40. data/lib/simple_navigation/items_provider.rb +6 -4
  41. data/lib/simple_navigation/railtie.rb +3 -1
  42. data/lib/simple_navigation/renderer/base.rb +5 -5
  43. data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
  44. data/lib/simple_navigation/renderer/json.rb +1 -1
  45. data/lib/simple_navigation/renderer/links.rb +2 -0
  46. data/lib/simple_navigation/renderer/list.rb +5 -5
  47. data/lib/simple_navigation/renderer/text.rb +3 -1
  48. data/lib/simple_navigation/version.rb +3 -1
  49. data/lib/simple_navigation.rb +32 -24
  50. data/simple-navigation.gemspec +16 -27
  51. data/spec/fake_app/config/navigation.rb +4 -2
  52. data/spec/fake_app/rails_app.rb +5 -3
  53. data/spec/integration/rendering_navigation_spec.rb +7 -5
  54. data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
  55. data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
  56. data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
  57. data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
  58. data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
  59. data/spec/simple_navigation/config_file_spec.rb +14 -14
  60. data/spec/simple_navigation/configuration_spec.rb +128 -121
  61. data/spec/simple_navigation/helpers_spec.rb +282 -284
  62. data/spec/simple_navigation/item_adapter_spec.rb +109 -122
  63. data/spec/simple_navigation/item_container_spec.rb +407 -408
  64. data/spec/simple_navigation/item_spec.rb +333 -301
  65. data/spec/simple_navigation/items_provider_spec.rb +30 -27
  66. data/spec/simple_navigation/renderer/base_spec.rb +166 -168
  67. data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
  68. data/spec/simple_navigation/renderer/json_spec.rb +49 -56
  69. data/spec/simple_navigation/renderer/links_spec.rb +81 -83
  70. data/spec/simple_navigation/renderer/list_spec.rb +111 -91
  71. data/spec/simple_navigation/renderer/text_spec.rb +37 -39
  72. data/spec/simple_navigation_spec.rb +54 -47
  73. data/spec/spec_helper.rb +146 -53
  74. metadata +25 -164
  75. data/.travis.yml +0 -23
  76. data/gemfiles/rails-3-2-stable.gemfile +0 -11
  77. data/gemfiles/rails-4-1-stable.gemfile +0 -7
  78. data/gemfiles/rails-4-2-stable.gemfile +0 -7
  79. data/gemfiles/rails-5-2-stable.gemfile +0 -7
  80. data/gemfiles/rails-6-0-stable.gemfile +0 -9
  81. data/gemfiles/rails-6-1-stable.gemfile +0 -9
  82. data/init.rb +0 -1
  83. data/install.rb +0 -5
  84. data/lib/simple_navigation/adapters.rb +0 -10
  85. data/lib/simple_navigation/renderer.rb +0 -12
  86. data/spec/initializers/coveralls.rb +0 -3
  87. data/spec/initializers/have_css_matcher.rb +0 -19
  88. data/spec/initializers/memfs.rb +0 -7
  89. data/spec/initializers/rails.rb +0 -4
  90. data/spec/initializers/rspec.rb +0 -7
  91. data/uninstall.rb +0 -1
@@ -1,34 +1,59 @@
1
- module SimpleNavigation
2
- describe Helpers do
3
- subject(:controller) { test_controller_class.new }
4
-
5
- let(:invoices_item) { navigation[:invoices] }
6
- let(:item) { nil }
7
- let(:navigation) { setup_navigation('nav_id', 'nav_class') }
8
- let(:test_controller_class) do
9
- Class.new { include SimpleNavigation::Helpers }
10
- end
11
- let(:unpaid_item) { invoices_item.sub_navigation[:unpaid] }
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
- before do
14
- allow(Configuration).to receive(:eval_config)
15
- allow(SimpleNavigation).to receive_messages(load_config: nil,
16
- primary_navigation: navigation,
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
- select_an_item(navigation[item]) if item
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
- describe '#active_navigation_item_name' do
24
- context 'when no item is selected' do
25
- it 'returns an empty string for no parameters' do
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 an empty string for level: 1" do
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 'when an item is selected' do
46
- context "and it's a primary item" do
47
- let(:item) { :invoices }
48
-
49
- it 'returns an empty string' do
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
- it "returns the selected item's name for level: 1" do
54
- item_name = controller.active_navigation_item_name(level: 1)
55
- expect(item_name).to eq 'Invoices'
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
- it 'returns an empty string for level: 2' do
59
- item_name = controller.active_navigation_item_name(level: 2)
60
- expect(item_name).to eq ''
61
- end
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
- it 'returns an empty string for level: :all' do
64
- item_name = controller.active_navigation_item_name(level: :all)
65
- expect(item_name).to eq ''
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
- context "and it's a sub navigation item" do
70
- before do
71
- select_an_item(invoices_item)
72
- select_an_item(unpaid_item)
73
- end
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
- it "returns the selected item's name" do
76
- expect(controller.active_navigation_item_name).to eq 'Unpaid'
77
- end
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
- it "returns the selected item's parent name for level: 1" do
80
- item_name = controller.active_navigation_item_name(level: 1)
81
- expect(item_name).to eq 'Invoices'
82
- end
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
- it "returns the selected item's name for level: 2" do
85
- item_name = controller.active_navigation_item_name(level: 2)
86
- expect(item_name).to eq 'Unpaid'
87
- end
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
- it "returns the selected item's name for level: :all" do
90
- item_name = controller.active_navigation_item_name(level: :all)
91
- expect(item_name).to eq 'Unpaid'
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
- describe '#active_navigation_item_key' do
98
- context 'when no item is selected' do
99
- it 'returns nil' do
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 nil for level: 1" do
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 be_nil
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 'when an item is selected' do
124
- context "and it's a primary item" do
125
- let(:item) { :invoices }
126
-
127
- it 'returns nil for no parameters' do
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
- it "returns the selected item's name for level: 1" do
132
- item_key = controller.active_navigation_item_key(level: 1)
133
- expect(item_key).to eq :invoices
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
- it 'returns nil for level: 2' do
137
- item_key = controller.active_navigation_item_key(level: 2)
138
- expect(item_key).to be_nil
139
- end
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
- it 'returns nil for level: :all' do
142
- item_key = controller.active_navigation_item_key(level: :all)
143
- expect(item_key).to be_nil
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
- context "and it's a sub navigation item" do
148
- before do
149
- select_an_item(invoices_item)
150
- select_an_item(unpaid_item)
151
- end
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
- it "returns the selected item's name" do
154
- expect(controller.active_navigation_item_key).to eq :unpaid
155
- end
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
- it "returns the selected item's parent name for level: 1" do
158
- item_key = controller.active_navigation_item_key(level: 1)
159
- expect(item_key).to eq :invoices
160
- end
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
- it "returns the selected item's name for level: 2" do
163
- item_key = controller.active_navigation_item_key(level: 2)
164
- expect(item_key).to eq :unpaid
165
- end
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
- it "returns the selected item's name for level: :all" do
168
- item_key = controller.active_navigation_item_key(level: :all)
169
- expect(item_key).to eq :unpaid
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
- describe '#active_navigation_item' do
176
- context 'when no item is selected' do
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 nil for level: 1" do
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 be_nil
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 'when an item is selected' do
198
- context "and it's a primary item" do
199
- let(:item) { :invoices }
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
- it 'returns nil for no parameters' do
202
- expect(controller.active_navigation_item).to be_nil
203
- end
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
- it "returns the selected item's name for level: 1" do
206
- item_key = controller.active_navigation_item(level: 1)
207
- expect(item_key).to be invoices_item
208
- end
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
- it 'returns nil for level: 2' do
211
- item_key = controller.active_navigation_item(level: 2)
212
- expect(item_key).to be_nil
213
- end
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
- it 'returns nil for level: :all' do
216
- item_key = controller.active_navigation_item(level: :all)
217
- expect(item_key).to be_nil
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
- context "and it's a sub navigation item" do
222
- before do
223
- select_an_item(invoices_item)
224
- select_an_item(unpaid_item)
225
- end
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
- it "returns the selected item's name for no parameters" do
228
- expect(controller.active_navigation_item).to be unpaid_item
229
- end
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
- it "returns the selected item's parent name for level: 1" do
232
- item_key = controller.active_navigation_item(level: 1)
233
- expect(item_key).to be invoices_item
234
- end
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
- it "returns the selected item's name for level: 2" do
237
- item_key = controller.active_navigation_item(level: 2)
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
- it "returns the selected item's name for level: :all" do
242
- item_key = controller.active_navigation_item(level: :all)
243
- expect(item_key).to eq unpaid_item
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
- describe '#active_navigation_item_container' do
250
- shared_examples 'returning items container' do
251
- it 'returns the primary navigation for no parameters' do
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
- it "returns the primary navigation for level: 1" do
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 primary navigation level: :all' do
279
+ it 'returns the invoices items container for level: 2' do
261
280
  item_container =
262
- controller.active_navigation_item_container(level: :all)
263
- expect(item_container).to be navigation
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 'when no item is selected' do
268
- it_behaves_like 'returning items container'
269
-
270
- it 'returns nil for level: 2' do
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
- context 'when an item is selected' do
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
- it 'returns the invoices items container for level: 2' do
283
- item_container =
284
- controller.active_navigation_item_container(level: 2)
285
- expect(item_container).to be invoices_item.sub_navigation
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
- context "and it's a sub navigation item" do
290
- before do
291
- select_an_item(invoices_item)
292
- select_an_item(unpaid_item)
293
- end
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
- it_behaves_like 'returning items container'
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
- it 'returns the invoices items container for level: 2' do
298
- item_container =
299
- controller.active_navigation_item_container(level: 2)
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
- describe '#render_navigation' do
307
- it 'evaluates the configuration on every request' do
308
- expect(SimpleNavigation).to receive(:load_config).twice
309
- 2.times { controller.render_navigation }
310
- end
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
- it 'loads the :default configuration' do
313
- expect(SimpleNavigation).to receive(:load_config).with(:default)
314
- controller.render_navigation
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
- it "doesn't set the items directly" do
318
- expect(SimpleNavigation.config).not_to receive(:items)
319
- controller.render_navigation
320
- end
332
+ context 'when the :items option is specified' do
333
+ let(:items) { double(:items) }
321
334
 
322
- it 'looks up the active_item_container based on the level' do
323
- expect(SimpleNavigation).to receive(:active_item_container_for)
324
- .with(:all)
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
- context 'when the :context option is specified' do
329
- it 'loads the configuration for the specified context' do
330
- expect(SimpleNavigation).to receive(:load_config).with(:my_context)
331
- controller.render_navigation(context: :my_context)
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 the :items option is specified' do
336
- let(:items) { double(:items) }
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
- it 'sets the items directly' do
339
- expect(SimpleNavigation.config).to receive(:items).with(items)
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
- it 'calls render on the active item_container' do
367
- expect(item_container).to receive(:render).with(level: 2)
368
- controller.render_navigation(level: 2)
369
- end
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
- context "and the active_item_container isn't set" do
373
- it "doesn't raise an exception" do
374
- expect{
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 "and its value isn't a valid level" do
382
- it 'raises an exception' do
383
- expect{
384
- controller.render_navigation(level: :invalid)
385
- }.to raise_error(ArgumentError, 'Invalid navigation level: invalid')
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 'when the :levels option is set' do
391
- before { allow(SimpleNavigation).to receive_messages(active_item_container_for: navigation) }
392
-
393
- it 'treats it like the :level option' do
394
- expect(navigation).to receive(:render).with(level: 2)
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
- context 'when a block is given' do
400
- it 'calls the block passing it an item container' do
401
- expect{ |blk|
402
- controller.render_navigation(&blk)
403
- }.to yield_with_args(ItemContainer)
404
- end
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
- context 'when no primary configuration is defined' do
408
- before { allow(SimpleNavigation).to receive_messages(primary_navigation: nil) }
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
- it 'raises an exception' do
411
- expect{controller.render_navigation}.to raise_error(RuntimeError, 'no primary navigation defined, either use a navigation config file or pass items directly to render_navigation')
412
- end
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
- context "when active_item_container is set" do
416
- let(:active_item_container) { double(:container).as_null_object }
414
+ context 'when active_item_container is set' do
415
+ let(:active_item_container) { double(:container).as_null_object }
417
416
 
418
- before do
419
- allow(SimpleNavigation).to receive_messages(active_item_container_for: active_item_container)
420
- end
417
+ before do
418
+ allow(SimpleNavigation).to receive_messages(active_item_container_for: active_item_container)
419
+ end
421
420
 
422
- it 'calls render on the active_item_container' do
423
- expect(active_item_container).to receive(:render)
424
- controller.render_navigation
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