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,281 +1,274 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe SimpleNavigation::Adapters::Rails do
|
|
4
|
+
let(:action_controller) { ActionController::Base }
|
|
5
|
+
let(:adapter) { described_class.new(context) }
|
|
6
|
+
let(:context) { double(:context, controller: controller) }
|
|
7
|
+
let(:controller) { double(:controller) }
|
|
8
|
+
let(:request) { double(:request) }
|
|
9
|
+
let(:simple_navigation) { SimpleNavigation }
|
|
10
|
+
let(:template) { double(:template, request: request) }
|
|
11
|
+
|
|
12
|
+
describe '.register' do
|
|
13
|
+
before { allow(action_controller).to receive(:include) }
|
|
14
|
+
|
|
15
|
+
it 'calls set_env' do
|
|
16
|
+
app_path = RailsApp::Application.root
|
|
17
|
+
expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
|
|
18
|
+
simple_navigation.register
|
|
19
|
+
end
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end
|
|
21
|
+
it 'extends the ActionController::Base with the Helpers' do
|
|
22
|
+
expect(action_controller).to receive(:include).with(SimpleNavigation::Helpers)
|
|
23
|
+
simple_navigation.register
|
|
24
|
+
end
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
shared_examples 'installing helper method' do |method|
|
|
27
|
+
it "installs the #{method} method as helper method" do
|
|
28
|
+
simple_navigation.register
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it_behaves_like 'installing helper method', :render_navigation
|
|
37
|
-
it_behaves_like 'installing helper method', :active_navigation_item_name
|
|
38
|
-
it_behaves_like 'installing helper method', :active_navigation_item_key
|
|
39
|
-
it_behaves_like 'installing helper method', :active_navigation_item
|
|
40
|
-
it_behaves_like 'installing helper method', :active_navigation_item_container
|
|
30
|
+
helper_methods = action_controller.send(:_helper_methods)
|
|
31
|
+
expect(helper_methods).to include(method)
|
|
41
32
|
end
|
|
33
|
+
end
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
end
|
|
35
|
+
it_behaves_like 'installing helper method', :render_navigation
|
|
36
|
+
it_behaves_like 'installing helper method', :active_navigation_item_name
|
|
37
|
+
it_behaves_like 'installing helper method', :active_navigation_item_key
|
|
38
|
+
it_behaves_like 'installing helper method', :active_navigation_item
|
|
39
|
+
it_behaves_like 'installing helper method', :active_navigation_item_container
|
|
40
|
+
end
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
describe '#initialize' do
|
|
43
|
+
context "when the controller's template is set" do
|
|
44
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
it "sets the adapter's request accordingly" do
|
|
47
|
+
expect(adapter.request).to be request
|
|
48
|
+
end
|
|
49
|
+
end
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
end
|
|
51
|
+
context "when the controller's template is not set" do
|
|
52
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
|
63
53
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
it "sets the adapter's request to nil" do
|
|
55
|
+
expect(adapter.request).to be_nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
59
|
+
it "sets the adapter's controller to the context's controller" do
|
|
60
|
+
expect(adapter.controller).to be controller
|
|
61
|
+
end
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
context "when the controller's template is stored as instance var (Rails2)" do
|
|
64
|
+
context "when the controller's template is set" do
|
|
65
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
end
|
|
67
|
+
it "sets the adapter's template accordingly" do
|
|
68
|
+
expect(adapter.template).to be template
|
|
80
69
|
end
|
|
70
|
+
end
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
before { allow(controller).to receive_messages(view_context: template) }
|
|
72
|
+
context "when the controller's template is not set" do
|
|
73
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
it "set the adapter's template to nil" do
|
|
76
|
+
expect(adapter.template).to be_nil
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
context "when the controller's template is stored as view_context (Rails3)" do
|
|
82
|
+
context 'when the template is set' do
|
|
83
|
+
before { allow(controller).to receive_messages(view_context: template) }
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
end
|
|
85
|
+
it "sets the adapter's template accordingly" do
|
|
86
|
+
expect(adapter.template).to be template
|
|
98
87
|
end
|
|
99
88
|
end
|
|
100
89
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
before { allow(adapter).to receive_messages(request: request) }
|
|
90
|
+
context 'when the template is not set' do
|
|
91
|
+
before { allow(controller).to receive_messages(view_context: nil) }
|
|
104
92
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
end
|
|
93
|
+
it "sets the adapter's template to nil" do
|
|
94
|
+
expect(adapter.template).to be_nil
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
112
99
|
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
describe '#request_uri' do
|
|
101
|
+
context "when the adapter's request is set" do
|
|
102
|
+
before { allow(adapter).to receive_messages(request: request) }
|
|
115
103
|
|
|
116
|
-
|
|
104
|
+
context 'when request.fullpath is defined' do
|
|
105
|
+
let(:request) { double(:request, fullpath: '/fullpath') }
|
|
117
106
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
end
|
|
121
|
-
end
|
|
107
|
+
it "sets the adapter's request_uri to the request.fullpath" do
|
|
108
|
+
expect(adapter.request_uri).to eq '/fullpath'
|
|
122
109
|
end
|
|
110
|
+
end
|
|
123
111
|
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
context 'when request.fullpath is not defined' do
|
|
113
|
+
let(:request) { double(:request, request_uri: '/request_uri') }
|
|
126
114
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
115
|
+
before { allow(adapter).to receive_messages(request: request) }
|
|
116
|
+
|
|
117
|
+
it "sets the adapter's request_uri to the request.request_uri" do
|
|
118
|
+
expect(adapter.request_uri).to eq '/request_uri'
|
|
130
119
|
end
|
|
131
120
|
end
|
|
121
|
+
end
|
|
132
122
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
let(:request) { double(:request, path: '/request_path') }
|
|
123
|
+
context "when the adapter's request is not set" do
|
|
124
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
|
136
125
|
|
|
137
|
-
|
|
126
|
+
it "sets the adapter's request_uri to an empty string" do
|
|
127
|
+
expect(adapter.request_uri).to eq ''
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
138
131
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
end
|
|
132
|
+
describe '#request_path' do
|
|
133
|
+
context "when the adapter's request is set" do
|
|
134
|
+
let(:request) { double(:request, path: '/request_path') }
|
|
143
135
|
|
|
144
|
-
|
|
145
|
-
before { allow(adapter).to receive_messages(request: nil) }
|
|
136
|
+
before { allow(adapter).to receive_messages(request: request) }
|
|
146
137
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
end
|
|
150
|
-
end
|
|
138
|
+
it "sets the adapter's request_path to the request.path" do
|
|
139
|
+
expect(adapter.request_path).to eq '/request_path'
|
|
151
140
|
end
|
|
141
|
+
end
|
|
152
142
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
before { adapter.instance_variable_set(:@controller, controller) }
|
|
143
|
+
context "when the adapter's request is not set" do
|
|
144
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
|
156
145
|
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
it "sets the adapter's request_path to an empty string" do
|
|
147
|
+
expect(adapter.request_path).to eq ''
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
159
151
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
end
|
|
152
|
+
describe '#context_for_eval' do
|
|
153
|
+
context "when the adapter's controller is set" do
|
|
154
|
+
before { adapter.instance_variable_set(:@controller, controller) }
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
context "when the adapter's template is set" do
|
|
157
|
+
before { adapter.instance_variable_set(:@template, template) }
|
|
167
158
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
end
|
|
171
|
-
end
|
|
159
|
+
it "sets the adapter's context_for_eval to the template" do
|
|
160
|
+
expect(adapter.context_for_eval).to be template
|
|
172
161
|
end
|
|
162
|
+
end
|
|
173
163
|
|
|
174
|
-
|
|
175
|
-
|
|
164
|
+
context "when the adapter's template is not set" do
|
|
165
|
+
before { adapter.instance_variable_set(:@template, nil) }
|
|
176
166
|
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
it "sets the adapter's context_for_eval to the controller" do
|
|
168
|
+
expect(adapter.context_for_eval).to be controller
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
179
172
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
end
|
|
183
|
-
end
|
|
173
|
+
context "when the adapter's controller is not set" do
|
|
174
|
+
before { adapter.instance_variable_set(:@controller, nil) }
|
|
184
175
|
|
|
185
|
-
|
|
186
|
-
|
|
176
|
+
context "when the adapter's template is set" do
|
|
177
|
+
before { adapter.instance_variable_set(:@template, template) }
|
|
187
178
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
end
|
|
191
|
-
end
|
|
179
|
+
it "sets the adapter's context_for_eval to the template" do
|
|
180
|
+
expect(adapter.context_for_eval).to be template
|
|
192
181
|
end
|
|
193
182
|
end
|
|
194
183
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
before { allow(adapter).to receive_messages(template: template) }
|
|
184
|
+
context "when the adapter's template is not set" do
|
|
185
|
+
before { adapter.instance_variable_set(:@template, nil) }
|
|
198
186
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
adapter.
|
|
202
|
-
end
|
|
187
|
+
it 'raises an exception' do
|
|
188
|
+
expect do
|
|
189
|
+
adapter.context_for_eval
|
|
190
|
+
end.to raise_error(RuntimeError, 'no context set for evaluation the config file')
|
|
203
191
|
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
204
195
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
it 'returns false' do
|
|
209
|
-
expect(adapter.current_page?(:page)).to be_falsey
|
|
210
|
-
end
|
|
211
|
-
end
|
|
196
|
+
describe '#current_page?' do
|
|
197
|
+
context "when the adapter's template is set" do
|
|
198
|
+
before { allow(adapter).to receive_messages(template: template) }
|
|
212
199
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
end
|
|
217
|
-
end
|
|
200
|
+
it 'delegates the call to the template' do
|
|
201
|
+
expect(template).to receive(:current_page?).with(:page)
|
|
202
|
+
adapter.current_page?(:page)
|
|
218
203
|
end
|
|
204
|
+
end
|
|
219
205
|
|
|
220
|
-
|
|
221
|
-
|
|
206
|
+
context "when the adapter's template is not set" do
|
|
207
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
|
222
208
|
|
|
223
|
-
|
|
224
|
-
|
|
209
|
+
it 'returns false' do
|
|
210
|
+
expect(adapter).not_to be_current_page(:page)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
225
213
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
214
|
+
context 'when the given url is nil' do
|
|
215
|
+
it 'returns false' do
|
|
216
|
+
expect(adapter).not_to be_current_page(nil)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
229
220
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
.with('safe_text', 'url', options)
|
|
233
|
-
adapter.link_to('text', 'url', options)
|
|
234
|
-
end
|
|
235
|
-
end
|
|
221
|
+
describe '#link_to' do
|
|
222
|
+
let(:options) { double(:options) }
|
|
236
223
|
|
|
237
|
-
|
|
224
|
+
context "when the adapter's template is set" do
|
|
225
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
|
238
226
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
adapter.link_to('text', 'url', options)
|
|
243
|
-
end
|
|
244
|
-
end
|
|
227
|
+
context 'with considering item names as safe' do
|
|
228
|
+
before { SimpleNavigation.config.consider_item_names_as_safe = true }
|
|
229
|
+
after { SimpleNavigation.config.consider_item_names_as_safe = false }
|
|
245
230
|
|
|
231
|
+
it 'delegates the call to the template (with html_safe text)' do
|
|
232
|
+
expect(template).to receive(:link_to).with('safe_text', 'url', options)
|
|
233
|
+
adapter.link_to('text', 'url', options)
|
|
246
234
|
end
|
|
235
|
+
end
|
|
247
236
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
expect(adapter.link_to('text', 'url', options)).to be_nil
|
|
253
|
-
end
|
|
237
|
+
context 'with considering item names as UNsafe (default)' do
|
|
238
|
+
it 'delegates the call to the template (with html_safe text)' do
|
|
239
|
+
expect(template).to receive(:link_to).with('text', 'url', options)
|
|
240
|
+
adapter.link_to('text', 'url', options)
|
|
254
241
|
end
|
|
255
242
|
end
|
|
243
|
+
end
|
|
256
244
|
|
|
257
|
-
|
|
258
|
-
|
|
245
|
+
context "when the adapter's template is not set" do
|
|
246
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
|
259
247
|
|
|
260
|
-
|
|
261
|
-
|
|
248
|
+
it 'returns nil' do
|
|
249
|
+
expect(adapter.link_to('text', 'url', options)).to be_nil
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
262
253
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
.with(:div, 'safe_text', options)
|
|
266
|
-
adapter.content_tag(:div, 'text', options)
|
|
267
|
-
end
|
|
268
|
-
end
|
|
254
|
+
describe '#content_tag' do
|
|
255
|
+
let(:options) { double(:options) }
|
|
269
256
|
|
|
270
|
-
|
|
271
|
-
|
|
257
|
+
context "when the adapter's template is set" do
|
|
258
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
|
272
259
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
end
|
|
260
|
+
it 'delegates the call to the template (with html_safe text)' do
|
|
261
|
+
expect(template).to receive(:content_tag).with(:div, 'safe_text', options)
|
|
262
|
+
adapter.content_tag(:div, 'text', options)
|
|
277
263
|
end
|
|
264
|
+
end
|
|
278
265
|
|
|
266
|
+
context "when the adapter's template is not set" do
|
|
267
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
|
268
|
+
|
|
269
|
+
it 'returns nil' do
|
|
270
|
+
expect(adapter.content_tag(:div, 'text', options)).to be_nil
|
|
271
|
+
end
|
|
279
272
|
end
|
|
280
273
|
end
|
|
281
274
|
end
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe SimpleNavigation::Adapters::Sinatra do
|
|
4
|
+
let(:adapter) { described_class.new(context) }
|
|
3
5
|
let(:context) { double(:context) }
|
|
4
6
|
let(:request) { double(:request, fullpath: '/full?param=true', path: '/full') }
|
|
5
7
|
|
|
6
8
|
before { allow(context).to receive_messages(request: request) }
|
|
7
9
|
|
|
10
|
+
describe '.register' do
|
|
11
|
+
let(:sinatra_app) { double(:app, root: '/sinatra/root', environment: 'test') }
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
allow(SimpleNavigation).to receive(:set_env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'calls SimpleNavigation.set_env with app root and environment' do
|
|
18
|
+
expect(SimpleNavigation).to receive(:set_env).with('/sinatra/root', 'test')
|
|
19
|
+
described_class.register(sinatra_app)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
8
23
|
describe '#context_for_eval' do
|
|
9
24
|
context "when adapter's context is not set" do
|
|
10
25
|
it 'raises an exception' do
|
|
11
26
|
allow(adapter).to receive_messages(context: nil)
|
|
12
|
-
expect
|
|
27
|
+
expect do
|
|
28
|
+
adapter.context_for_eval
|
|
29
|
+
end.to raise_error(RuntimeError, 'no context set for evaluation the config file')
|
|
13
30
|
end
|
|
14
31
|
end
|
|
15
32
|
|
|
@@ -57,8 +74,7 @@ describe SimpleNavigation::Adapters::Sinatra do
|
|
|
57
74
|
|
|
58
75
|
context 'when URL is encoded' do
|
|
59
76
|
before do
|
|
60
|
-
allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true',
|
|
61
|
-
path: '/full%20with%20spaces')
|
|
77
|
+
allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true', path: '/full%20with%20spaces')
|
|
62
78
|
end
|
|
63
79
|
|
|
64
80
|
it_behaves_like 'detecting current page', '/full%20with%20spaces?param=true', true
|
|
@@ -1,48 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'fileutils'
|
|
2
4
|
require 'simple_navigation/config_file_finder'
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
subject(:finder) { ConfigFileFinder.new(paths) }
|
|
6
|
+
RSpec.describe SimpleNavigation::ConfigFileFinder do
|
|
7
|
+
subject(:finder) { described_class.new(paths) }
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
let(:paths) { ['/path/one', '/path/two'] }
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
describe '#find', :memfs do
|
|
12
|
+
before { FileUtils.mkdir_p(paths) }
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
context 'when the context is :default' do
|
|
15
|
+
let(:context) { :default }
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
context 'when a navigation.rb file is found in one of the paths' do
|
|
18
|
+
before { FileUtils.touch('/path/one/navigation.rb') }
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
20
|
+
it 'returns its full path' do
|
|
21
|
+
expect(finder.find(context)).to eq '/path/one/navigation.rb'
|
|
22
22
|
end
|
|
23
|
+
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
context 'when no navigation.rb file is found in the paths' do
|
|
26
|
+
it 'raises an exception' do
|
|
27
|
+
expect do
|
|
28
|
+
finder.find(context)
|
|
29
|
+
end.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
|
|
28
30
|
end
|
|
29
31
|
end
|
|
32
|
+
end
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
context 'when the context is :other' do
|
|
35
|
+
let(:context) { :other }
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
context 'when a other_navigation.rb file is found in one of the paths' do
|
|
38
|
+
before { FileUtils.touch('/path/two/other_navigation.rb') }
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
+
it 'returns its full path' do
|
|
41
|
+
expect(finder.find(context)).to eq '/path/two/other_navigation.rb'
|
|
40
42
|
end
|
|
43
|
+
end
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
context 'when no other_navigation.rb file is found in the paths' do
|
|
46
|
+
it 'raise an exception' do
|
|
47
|
+
expect do
|
|
48
|
+
finder.find(context)
|
|
49
|
+
end.to raise_error(RuntimeError, /Config file 'other_navigation.rb' not found in path\(s\)/)
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
end
|