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,43 +1,46 @@
1
- module SimpleNavigation
2
- describe ItemsProvider do
3
- let(:items_provider) { ItemsProvider.new(provider) }
1
+ # frozen_string_literal: true
4
2
 
5
- describe '#items' do
6
- let(:items) { double(:items) }
3
+ RSpec.describe SimpleNavigation::ItemsProvider do
4
+ let(:items_provider) { described_class.new(provider) }
7
5
 
8
- context 'when provider is a symbol' do
9
- let(:context) { double(:context, provider_method: items) }
10
- let(:provider) { :provider_method }
6
+ describe '#items' do
7
+ let(:items) { double(:items) }
11
8
 
12
- before { allow(SimpleNavigation).to receive_messages(context_for_eval: context) }
9
+ context 'when provider is a symbol' do
10
+ let(:context) { double(:context, provider_method: items) }
11
+ let(:provider) { :provider_method }
13
12
 
14
- it 'retrieves the items from the evaluation context' do
15
- expect(items_provider.items).to eq items
16
- end
13
+ before { allow(SimpleNavigation).to receive_messages(context_for_eval: context) }
14
+
15
+ it 'retrieves the items from the evaluation context' do
16
+ expect(items_provider.items).to eq items
17
17
  end
18
+ end
18
19
 
19
- context 'when provider responds to :items' do
20
- let(:provider) { double(:provider, items: items) }
20
+ context 'when provider responds to :items' do
21
+ let(:provider) { double(:provider, items: items) }
21
22
 
22
- it 'retrieves the items from the provider object' do
23
- expect(items_provider.items).to eq items
24
- end
23
+ it 'retrieves the items from the provider object' do
24
+ expect(items_provider.items).to eq items
25
25
  end
26
+ end
26
27
 
27
- context 'provider is a collection' do
28
- let(:provider) { [] }
28
+ context 'when provider is a collection' do
29
+ let(:provider) { [] }
29
30
 
30
- it 'retrieves the items by returning the provider' do
31
- expect(items_provider.items).to eq provider
32
- end
31
+ it 'retrieves the items by returning the provider' do
32
+ expect(items_provider.items).to eq provider
33
33
  end
34
+ end
34
35
 
35
- context 'when provider is something else' do
36
- let(:provider) { double(:provider) }
36
+ context 'when provider is something else' do
37
+ let(:provider) { double(:provider) }
37
38
 
38
- it 'raises an exception' do
39
- expect{ items_provider.items }.to raise_error(RuntimeError, /items_provider either must be a symbol .*, an object .* or an enumerable/)
40
- end
39
+ it 'raises an exception' do
40
+ expect do
41
+ items_provider.items
42
+ end.to raise_error(RuntimeError,
43
+ /items_provider either must be a symbol .*, an object .* or an enumerable/)
41
44
  end
42
45
  end
43
46
  end
@@ -1,238 +1,236 @@
1
- module SimpleNavigation
2
- module Renderer
3
- describe Base do
4
- subject(:base) { Base.new(options) }
1
+ # frozen_string_literal: true
5
2
 
6
- let(:adapter) { double(:adapter) }
7
- let(:options) { Hash.new }
3
+ RSpec.describe SimpleNavigation::Renderer::Base do
4
+ subject(:base) { described_class.new(options) }
8
5
 
9
- before { allow(SimpleNavigation).to receive_messages(adapter: adapter) }
6
+ let(:adapter) { double(:adapter) }
7
+ let(:options) { {} }
10
8
 
11
- it 'delegates the :link_to method to adapter' do
12
- allow(adapter).to receive_messages(link_to: 'link_to')
13
- expect(base.link_to).to eq 'link_to'
14
- end
15
-
16
- it 'delegates the :content_tag method to adapter' do
17
- allow(adapter).to receive_messages(content_tag: 'content_tag')
18
- expect(base.content_tag).to eq 'content_tag'
19
- end
9
+ before { allow(SimpleNavigation).to receive_messages(adapter: adapter) }
20
10
 
21
- describe '#initialize' do
22
- it "sets the renderer adapter to the SimpleNavigation one" do
23
- expect(base.adapter).to be adapter
24
- end
25
- end
11
+ it 'delegates the :link_to method to adapter' do
12
+ allow(adapter).to receive_messages(link_to: 'link_to')
13
+ expect(base.link_to).to eq 'link_to'
14
+ end
26
15
 
27
- describe '#options' do
28
- it "returns the renderer's options" do
29
- expect(base.options).to be options
30
- end
31
- end
16
+ it 'delegates the :content_tag method to adapter' do
17
+ allow(adapter).to receive_messages(content_tag: 'content_tag')
18
+ expect(base.content_tag).to eq 'content_tag'
19
+ end
32
20
 
33
- describe '#render' do
34
- it "raise an exception to indicate it's a subclass responsibility" do
35
- expect{ base.render(:container) }.to raise_error(NotImplementedError, 'subclass responsibility')
36
- end
37
- end
21
+ describe '#initialize' do
22
+ it 'sets the renderer adapter to the SimpleNavigation one' do
23
+ expect(base.adapter).to be adapter
24
+ end
25
+ end
38
26
 
39
- describe '#expand_all?' do
40
- context 'when :options is set' do
41
- context 'and the :expand_all option is true' do
42
- let(:options) {{ expand_all: true }}
27
+ describe '#options' do
28
+ it "returns the renderer's options" do
29
+ expect(base.options).to be options
30
+ end
31
+ end
43
32
 
44
- it 'returns true' do
45
- expect(base.expand_all?).to be true
46
- end
47
- end
33
+ describe '#render' do
34
+ it "raise an exception to indicate it's a subclass responsibility" do
35
+ expect { base.render(:container) }.to raise_error(NotImplementedError, 'subclass responsibility')
36
+ end
37
+ end
48
38
 
49
- context 'and the :expand_all option is false' do
50
- let(:options) {{ expand_all: false }}
39
+ describe '#expand_all?' do
40
+ context 'when :options is set' do
41
+ context 'when the :expand_all option is true' do
42
+ let(:options) { { expand_all: true } }
51
43
 
52
- it 'returns false' do
53
- expect(base.expand_all?).to be false
54
- end
55
- end
44
+ it 'returns true' do
45
+ expect(base.expand_all?).to be true
56
46
  end
47
+ end
57
48
 
58
- context "when :options isn't set" do
59
- let(:options) { Hash.new }
49
+ context 'when the :expand_all option is false' do
50
+ let(:options) { { expand_all: false } }
60
51
 
61
- it 'returns false' do
62
- expect(base.expand_all?).to be false
63
- end
52
+ it 'returns false' do
53
+ expect(base.expand_all?).to be false
64
54
  end
65
55
  end
56
+ end
66
57
 
67
- describe '#skip_if_empty?' do
68
- context 'when :options is set' do
69
- context 'and the :skip_if_empty option is true' do
70
- let(:options) {{ skip_if_empty: true }}
58
+ context "when :options isn't set" do
59
+ let(:options) { {} }
71
60
 
72
- it 'returns true' do
73
- expect(base.skip_if_empty?).to be true
74
- end
75
- end
61
+ it 'returns false' do
62
+ expect(base.expand_all?).to be false
63
+ end
64
+ end
65
+ end
76
66
 
77
- context 'and the :skip_if_empty option is false' do
78
- let(:options) {{ skip_if_empty: false }}
67
+ describe '#skip_if_empty?' do
68
+ context 'when :options is set' do
69
+ context 'when the :skip_if_empty option is true' do
70
+ let(:options) { { skip_if_empty: true } }
79
71
 
80
- it 'returns true' do
81
- expect(base.skip_if_empty?).to be false
82
- end
83
- end
72
+ it 'returns true' do
73
+ expect(base.skip_if_empty?).to be true
84
74
  end
75
+ end
85
76
 
86
- context "when :options isn't set" do
87
- let(:options) { Hash.new }
77
+ context 'when the :skip_if_empty option is false' do
78
+ let(:options) { { skip_if_empty: false } }
88
79
 
89
- it 'returns true' do
90
- expect(base.skip_if_empty?).to be false
91
- end
80
+ it 'returns true' do
81
+ expect(base.skip_if_empty?).to be false
92
82
  end
93
83
  end
84
+ end
94
85
 
95
- describe '#level' do
96
- context 'and the :level option is set' do
97
- let(:options) {{ level: 1 }}
86
+ context "when :options isn't set" do
87
+ let(:options) { {} }
98
88
 
99
- it 'returns the specified level' do
100
- expect(base.level).to eq 1
101
- end
102
- end
89
+ it 'returns true' do
90
+ expect(base.skip_if_empty?).to be false
91
+ end
92
+ end
93
+ end
103
94
 
104
- context "and the :level option isn't set" do
105
- let(:options) { Hash.new }
95
+ describe '#level' do
96
+ context 'when the :level option is set' do
97
+ let(:options) { { level: 1 } }
106
98
 
107
- it 'returns :all' do
108
- expect(base.level).to eq :all
109
- end
110
- end
99
+ it 'returns the specified level' do
100
+ expect(base.level).to eq 1
111
101
  end
102
+ end
112
103
 
113
- describe '#consider_sub_navigation?' do
114
- let(:item) { double(:item) }
104
+ context "when the :level option isn't set" do
105
+ let(:options) { {} }
115
106
 
116
- before { allow(item).to receive_messages(sub_navigation: sub_navigation) }
107
+ it 'returns :all' do
108
+ expect(base.level).to eq :all
109
+ end
110
+ end
111
+ end
117
112
 
118
- context 'when the item has no sub navigation' do
119
- let(:sub_navigation) { nil }
113
+ describe '#consider_sub_navigation?' do
114
+ let(:item) { double(:item) }
120
115
 
121
- it 'returns false' do
122
- expect(base.send(:consider_sub_navigation?, item)).to be false
123
- end
124
- end
116
+ before { allow(item).to receive_messages(sub_navigation: sub_navigation) }
125
117
 
126
- context 'when the item has sub navigation' do
127
- let(:sub_navigation) { double(:sub_navigation) }
118
+ context 'when the item has no sub navigation' do
119
+ let(:sub_navigation) { nil }
128
120
 
129
- context 'and the renderer has an unknown level' do
130
- before { allow(base).to receive_messages(level: 'unknown') }
121
+ it 'returns false' do
122
+ expect(base.send(:consider_sub_navigation?, item)).to be false
123
+ end
124
+ end
131
125
 
132
- it 'returns false' do
133
- expect(base.send(:consider_sub_navigation?, item)).to be false
134
- end
135
- end
126
+ context 'when the item has sub navigation' do
127
+ let(:sub_navigation) { double(:sub_navigation) }
136
128
 
137
- context 'and the renderer has a level set to :all' do
138
- before { allow(base).to receive_messages(level: :all) }
129
+ context 'when the renderer has an unknown level' do
130
+ before { allow(base).to receive_messages(level: 'unknown') }
139
131
 
140
- it 'returns false' do
141
- expect(base.send(:consider_sub_navigation?, item)).to be true
142
- end
143
- end
132
+ it 'returns false' do
133
+ expect(base.send(:consider_sub_navigation?, item)).to be false
134
+ end
135
+ end
144
136
 
145
- context "when the renderer's level is a number" do
146
- before { allow(base).to receive_messages(level: 2) }
137
+ context 'when the renderer has a level set to :all' do
138
+ before { allow(base).to receive_messages(level: :all) }
147
139
 
148
- it 'returns false' do
149
- expect(base.send(:consider_sub_navigation?, item)).to be false
150
- end
151
- end
140
+ it 'returns false' do
141
+ expect(base.send(:consider_sub_navigation?, item)).to be true
142
+ end
143
+ end
152
144
 
153
- context "when the renderer's level is a Range" do
154
- before { allow(base).to receive_messages(level: 2..3) }
145
+ context "when the renderer's level is a number" do
146
+ before { allow(base).to receive_messages(level: 2) }
155
147
 
156
- context "and sub navigation's level is greater than range.max" do
157
- before { allow(sub_navigation).to receive_messages(level: 4) }
148
+ it 'returns false' do
149
+ expect(base.send(:consider_sub_navigation?, item)).to be false
150
+ end
151
+ end
158
152
 
159
- it 'returns false' do
160
- expect(base.send(:consider_sub_navigation?, item)).to be false
161
- end
162
- end
153
+ context "when the renderer's level is a Range" do
154
+ before { allow(base).to receive_messages(level: 2..3) }
163
155
 
164
- context "and sub navigation's level is equal to range.max" do
165
- before { allow(sub_navigation).to receive_messages(level: 3) }
156
+ context "when sub navigation's level is greater than range.max" do
157
+ before { allow(sub_navigation).to receive_messages(level: 4) }
166
158
 
167
- it 'returns true' do
168
- expect(base.send(:consider_sub_navigation?, item)).to be true
169
- end
170
- end
159
+ it 'returns false' do
160
+ expect(base.send(:consider_sub_navigation?, item)).to be false
161
+ end
162
+ end
171
163
 
172
- context "and sub navigation's level is equal to range.min" do
173
- before { allow(sub_navigation).to receive_messages(level: 2) }
164
+ context "when sub navigation's level is equal to range.max" do
165
+ before { allow(sub_navigation).to receive_messages(level: 3) }
174
166
 
175
- it 'returns true' do
176
- expect(base.send(:consider_sub_navigation?, item)).to be true
177
- end
178
- end
167
+ it 'returns true' do
168
+ expect(base.send(:consider_sub_navigation?, item)).to be true
179
169
  end
180
170
  end
181
- end
182
171
 
183
- describe '#include_sub_navigation?' do
184
- let(:item) { double(:item) }
172
+ context "when sub navigation's level is equal to range.min" do
173
+ before { allow(sub_navigation).to receive_messages(level: 2) }
185
174
 
186
- context 'when consider_sub_navigation? is true' do
187
- before { allow(base).to receive_messages(consider_sub_navigation?: true) }
175
+ it 'returns true' do
176
+ expect(base.send(:consider_sub_navigation?, item)).to be true
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
188
182
 
189
- context 'and expand_sub_navigation? is true' do
190
- before { allow(base).to receive_messages(expand_sub_navigation?: true) }
183
+ describe '#include_sub_navigation?' do
184
+ let(:item) { double(:item) }
191
185
 
192
- it 'returns true' do
193
- expect(base.include_sub_navigation?(item)).to be true
194
- end
195
- end
186
+ context 'when consider_sub_navigation? is true' do
187
+ before { allow(base).to receive_messages(consider_sub_navigation?: true) }
196
188
 
197
- context 'and expand_sub_navigation? is false' do
198
- before { allow(base).to receive_messages(expand_sub_navigation?: false) }
189
+ context 'when expand_sub_navigation? is true' do
190
+ before { allow(base).to receive_messages(expand_sub_navigation?: true) }
199
191
 
200
- it 'returns false' do
201
- expect(base.include_sub_navigation?(item)).to be false
202
- end
203
- end
192
+ it 'returns true' do
193
+ expect(base.include_sub_navigation?(item)).to be true
204
194
  end
195
+ end
205
196
 
206
- context 'consider_sub_navigation? is false' do
207
- before { allow(base).to receive_messages(consider_sub_navigation?: false) }
197
+ context 'when expand_sub_navigation? is false' do
198
+ before { allow(base).to receive_messages(expand_sub_navigation?: false) }
208
199
 
209
- context 'and expand_sub_navigation? is true' do
210
- before { allow(base).to receive_messages(expand_sub_navigation?: true) }
200
+ it 'returns false' do
201
+ expect(base.include_sub_navigation?(item)).to be false
202
+ end
203
+ end
204
+ end
211
205
 
212
- it 'returns false' do
213
- expect(base.include_sub_navigation?(item)).to be false
214
- end
215
- end
206
+ context 'when consider_sub_navigation? is false' do
207
+ before { allow(base).to receive_messages(consider_sub_navigation?: false) }
216
208
 
217
- context 'and expand_sub_navigation? is false' do
218
- before { allow(base).to receive_messages(expand_sub_navigation?: false) }
209
+ context 'when expand_sub_navigation? is true' do
210
+ before { allow(base).to receive_messages(expand_sub_navigation?: true) }
219
211
 
220
- it 'returns false' do
221
- expect(base.include_sub_navigation?(item)).to be false
222
- end
223
- end
212
+ it 'returns false' do
213
+ expect(base.include_sub_navigation?(item)).to be false
224
214
  end
225
215
  end
226
216
 
227
- describe '#render_sub_navigation_for' do
228
- let(:item) { double(:item, sub_navigation: sub_navigation) }
229
- let(:sub_navigation) { double(:sub_navigation) }
217
+ context 'when expand_sub_navigation? is false' do
218
+ before { allow(base).to receive_messages(expand_sub_navigation?: false) }
230
219
 
231
- it 'renders the sub navigation passing it the options' do
232
- expect(sub_navigation).to receive(:render).with(options)
233
- base.render_sub_navigation_for(item)
220
+ it 'returns false' do
221
+ expect(base.include_sub_navigation?(item)).to be false
234
222
  end
235
223
  end
236
224
  end
237
225
  end
226
+
227
+ describe '#render_sub_navigation_for' do
228
+ let(:item) { double(:item, sub_navigation: sub_navigation) }
229
+ let(:sub_navigation) { double(:sub_navigation) }
230
+
231
+ it 'renders the sub navigation passing it the options' do
232
+ expect(sub_navigation).to receive(:render).with(options)
233
+ base.render_sub_navigation_for(item)
234
+ end
235
+ end
238
236
  end