simple-navigation 3.13.0 → 4.0.5
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 +7 -0
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -3
- data/CHANGELOG.md +420 -0
- data/Guardfile +4 -2
- data/LICENSE +1 -1
- data/README.md +30 -7
- data/Rakefile +25 -2
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails-3-2-stable.gemfile +11 -0
- data/gemfiles/rails-4-1-stable.gemfile +7 -0
- data/gemfiles/rails-4-2-stable.gemfile +7 -0
- data/generators/navigation_config/navigation_config_generator.rb +0 -1
- data/generators/navigation_config/templates/config/navigation.rb +18 -15
- data/lib/simple_navigation.rb +25 -42
- data/lib/simple_navigation/adapters/padrino.rb +2 -2
- data/lib/simple_navigation/adapters/rails.rb +1 -24
- data/lib/simple_navigation/adapters/sinatra.rb +2 -11
- data/lib/simple_navigation/config_file.rb +36 -0
- data/lib/simple_navigation/config_file_finder.rb +42 -0
- data/lib/simple_navigation/{core/configuration.rb → configuration.rb} +7 -1
- data/lib/simple_navigation/{rendering/helpers.rb → helpers.rb} +0 -4
- data/lib/simple_navigation/{core/item.rb → item.rb} +76 -83
- data/lib/simple_navigation/{core/item_adapter.rb → item_adapter.rb} +3 -17
- data/lib/simple_navigation/{core/item_container.rb → item_container.rb} +23 -14
- data/lib/simple_navigation/{core/items_provider.rb → items_provider.rb} +0 -0
- data/lib/simple_navigation/railtie.rb +7 -0
- data/lib/simple_navigation/renderer.rb +12 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/base.rb +1 -1
- data/lib/simple_navigation/{rendering/renderer → renderer}/breadcrumbs.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/json.rb +2 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/links.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/list.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/text.rb +0 -0
- data/lib/simple_navigation/version.rb +1 -1
- data/simple-navigation.gemspec +6 -5
- data/spec/fake_app/config/navigation.rb +6 -0
- data/spec/fake_app/rails_app.rb +35 -0
- data/spec/initializers/coveralls.rb +3 -0
- data/spec/initializers/have_css_matcher.rb +8 -3
- data/spec/initializers/memfs.rb +7 -0
- data/spec/initializers/rails.rb +4 -0
- data/spec/initializers/rspec.rb +7 -0
- data/spec/integration/rendering_navigation_spec.rb +14 -0
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/padrino_spec.rb +0 -2
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/rails_spec.rb +43 -94
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/sinatra_spec.rb +4 -6
- data/spec/simple_navigation/config_file_finder_spec.rb +50 -0
- data/spec/simple_navigation/config_file_spec.rb +25 -0
- data/spec/{lib/simple_navigation/core → simple_navigation}/configuration_spec.rb +29 -19
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/helpers_spec.rb +10 -13
- data/spec/{lib/simple_navigation/core → simple_navigation}/item_adapter_spec.rb +14 -11
- data/spec/{lib/simple_navigation/core → simple_navigation}/item_container_spec.rb +130 -42
- data/spec/simple_navigation/item_spec.rb +475 -0
- data/spec/{lib/simple_navigation/core → simple_navigation}/items_provider_spec.rb +1 -3
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/base_spec.rb +34 -36
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/breadcrumbs_spec.rb +4 -7
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/json_spec.rb +5 -11
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/links_spec.rb +5 -8
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/list_spec.rb +4 -7
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/text_spec.rb +4 -7
- data/spec/simple_navigation_spec.rb +190 -0
- data/spec/spec_helper.rb +29 -35
- metadata +128 -113
- data/CHANGELOG +0 -288
- data/lib/simple_navigation/core.rb +0 -5
- data/lib/simple_navigation/rails_controller_methods.rb +0 -164
- data/lib/simple_navigation/rendering.rb +0 -12
- data/rails/init.rb +0 -1
- data/spec/lib/simple_navigation/core/item_spec.rb +0 -703
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +0 -270
- data/spec/lib/simple_navigation_spec.rb +0 -300
data/simple-navigation.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'simple_navigation/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'simple-navigation'
|
8
8
|
spec.version = SimpleNavigation::VERSION
|
9
|
-
spec.authors = ['Andi Schacke', 'Mark J. Titorenko']
|
9
|
+
spec.authors = ['Andi Schacke', 'Mark J. Titorenko', 'Simon Courtois']
|
10
10
|
spec.email = ['andi@codeplant.ch']
|
11
11
|
spec.description = "With the simple-navigation gem installed you can easily " \
|
12
12
|
"create multilevel navigations for your Rails, Sinatra or "\
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
"as explicit highlighting of the currently active " \
|
16
16
|
"navigation through regular expressions."
|
17
17
|
spec.summary = "simple-navigation is a ruby library for creating navigations "\
|
18
|
-
"(with multiple levels) for your
|
18
|
+
"(with multiple levels) for your Rails, Sinatra or " \
|
19
19
|
"Padrino application."
|
20
20
|
spec.homepage = 'http://github.com/codeplant/simple-navigation'
|
21
21
|
spec.license = 'MIT'
|
@@ -29,12 +29,13 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
|
31
31
|
|
32
|
-
spec.add_development_dependency 'actionpack', '>= 2.3.2'
|
33
32
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
33
|
+
spec.add_development_dependency 'capybara'
|
34
34
|
spec.add_development_dependency 'coveralls', '~> 0.7'
|
35
35
|
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
36
|
-
spec.add_development_dependency '
|
36
|
+
spec.add_development_dependency 'memfs', '~> 0.4.1'
|
37
37
|
spec.add_development_dependency 'rake'
|
38
38
|
spec.add_development_dependency 'rdoc'
|
39
|
-
spec.add_development_dependency 'rspec', '~>
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
spec.add_development_dependency 'tzinfo', '>= 0'
|
40
41
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
SimpleNavigation::Configuration.run do |navigation|
|
2
|
+
navigation.items do |nav|
|
3
|
+
nav.item :item_1, 'Item 1', '/item_1', html: {class: 'item_1'}, link_html: {id: 'link_1'}
|
4
|
+
nav.item :item_2, 'Item 2', '/item_2', html: {class: 'item_2'}, link_html: {id: 'link_2'}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'simple_navigation'
|
5
|
+
|
6
|
+
module RailsApp
|
7
|
+
class Application < Rails::Application
|
8
|
+
config.active_support.deprecation = :log
|
9
|
+
config.cache_classes = true
|
10
|
+
config.eager_load = false
|
11
|
+
config.root = __dir__
|
12
|
+
config.secret_token = 'x'*100
|
13
|
+
config.session_store :cookie_store, key: '_myapp_session'
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestsController < ActionController::Base
|
17
|
+
def base
|
18
|
+
render inline: <<-END
|
19
|
+
<!DOCTYPE html>
|
20
|
+
<html>
|
21
|
+
<body>
|
22
|
+
<%= render_navigation %>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
END
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails.backtrace_cleaner.remove_silencers!
|
31
|
+
RailsApp::Application.initialize!
|
32
|
+
|
33
|
+
RailsApp::Application.routes.draw do
|
34
|
+
get '/base_spec' => 'rails_app/tests#base'
|
35
|
+
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
RSpec::Matchers.define :have_css do |expected, times|
|
2
2
|
match do |actual|
|
3
|
-
HTML::Selector.new(expected).select(actual)
|
3
|
+
selector = HTML::Selector.new(expected).select(actual)
|
4
|
+
if times
|
5
|
+
expect(selector.size).to eq times
|
6
|
+
else
|
7
|
+
expect(selector.size).to be >= 1
|
8
|
+
end
|
4
9
|
end
|
5
10
|
|
6
|
-
|
11
|
+
failure_message do |actual|
|
7
12
|
"expected #{actual.to_s} to have #{times || 1} elements matching '#{expected}'"
|
8
13
|
end
|
9
14
|
|
10
|
-
|
15
|
+
failure_message_when_negated do |actual|
|
11
16
|
"expected #{actual.to_s} not to have #{times || 1} elements matching '#{expected}'"
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
RSpec.feature 'Rendering navigation' do
|
2
|
+
background do
|
3
|
+
SimpleNavigation.set_env(RailsApp::Application.root, 'test')
|
4
|
+
end
|
5
|
+
|
6
|
+
scenario 'Rendering basic navigation', type: :feature do
|
7
|
+
visit '/base_spec'
|
8
|
+
|
9
|
+
expect(page).to have_content('Item 1')
|
10
|
+
expect(page).to have_content('Item 2')
|
11
|
+
expect(page).to have_selector('li.item_1 a#link_1')
|
12
|
+
expect(page).to have_selector('li.item_2 a#link_2')
|
13
|
+
end
|
14
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
module SimpleNavigation
|
4
2
|
module Adapters
|
5
3
|
describe Rails do
|
6
4
|
let(:action_controller) { ActionController::Base }
|
7
|
-
let(:adapter) {
|
5
|
+
let(:adapter) { Rails.new(context) }
|
8
6
|
let(:context) { double(:context, controller: controller) }
|
9
7
|
let(:controller) { double(:controller) }
|
10
8
|
let(:request) { double(:request) }
|
@@ -12,10 +10,11 @@ module SimpleNavigation
|
|
12
10
|
let(:template) { double(:template, request: request) }
|
13
11
|
|
14
12
|
describe '.register' do
|
15
|
-
before { action_controller.
|
13
|
+
before { allow(action_controller).to receive(:include) }
|
16
14
|
|
17
15
|
it 'calls set_env' do
|
18
|
-
|
16
|
+
app_path = RailsApp::Application.root
|
17
|
+
expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
|
19
18
|
simple_navigation.register
|
20
19
|
end
|
21
20
|
|
@@ -25,19 +24,25 @@ module SimpleNavigation
|
|
25
24
|
simple_navigation.register
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
shared_examples 'installing helper method' do |method|
|
28
|
+
it "installs the #{method} method as helper method" do
|
29
|
+
simple_navigation.register
|
30
|
+
|
31
|
+
helper_methods = action_controller.send(:_helper_methods)
|
32
|
+
expect(helper_methods).to include(method)
|
33
|
+
end
|
35
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
|
36
41
|
end
|
37
42
|
|
38
43
|
describe '#initialize' do
|
39
44
|
context "when the controller's template is set" do
|
40
|
-
before { controller.
|
45
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
41
46
|
|
42
47
|
it "sets the adapter's request accordingly" do
|
43
48
|
expect(adapter.request).to be request
|
@@ -45,7 +50,7 @@ module SimpleNavigation
|
|
45
50
|
end
|
46
51
|
|
47
52
|
context "when the controller's template is not set" do
|
48
|
-
before { controller.
|
53
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
49
54
|
|
50
55
|
it "sets the adapter's request to nil" do
|
51
56
|
expect(adapter.request).to be_nil
|
@@ -58,7 +63,7 @@ module SimpleNavigation
|
|
58
63
|
|
59
64
|
context "when the controller's template is stored as instance var (Rails2)" do
|
60
65
|
context "when the controller's template is set" do
|
61
|
-
before { controller.
|
66
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
62
67
|
|
63
68
|
it "sets the adapter's template accordingly" do
|
64
69
|
expect(adapter.template).to be template
|
@@ -66,7 +71,7 @@ module SimpleNavigation
|
|
66
71
|
end
|
67
72
|
|
68
73
|
context "when the controller's template is not set" do
|
69
|
-
before { controller.
|
74
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
70
75
|
|
71
76
|
it "set the adapter's template to nil" do
|
72
77
|
expect(adapter.template).to be_nil
|
@@ -76,7 +81,7 @@ module SimpleNavigation
|
|
76
81
|
|
77
82
|
context "when the controller's template is stored as view_context (Rails3)" do
|
78
83
|
context 'and the template is set' do
|
79
|
-
before { controller.
|
84
|
+
before { allow(controller).to receive_messages(view_context: template) }
|
80
85
|
|
81
86
|
it "sets the adapter's template accordingly" do
|
82
87
|
expect(adapter.template).to be template
|
@@ -84,7 +89,7 @@ module SimpleNavigation
|
|
84
89
|
end
|
85
90
|
|
86
91
|
context 'and the template is not set' do
|
87
|
-
before { controller.
|
92
|
+
before { allow(controller).to receive_messages(view_context: nil) }
|
88
93
|
|
89
94
|
it "sets the adapter's template to nil" do
|
90
95
|
expect(adapter.template).to be_nil
|
@@ -92,10 +97,10 @@ module SimpleNavigation
|
|
92
97
|
end
|
93
98
|
end
|
94
99
|
end
|
95
|
-
|
100
|
+
|
96
101
|
describe '#request_uri' do
|
97
102
|
context "when the adapter's request is set" do
|
98
|
-
before { adapter.
|
103
|
+
before { allow(adapter).to receive_messages(request: request) }
|
99
104
|
|
100
105
|
context 'and request.fullpath is defined' do
|
101
106
|
let(:request) { double(:request, fullpath: '/fullpath') }
|
@@ -108,7 +113,7 @@ module SimpleNavigation
|
|
108
113
|
context 'and request.fullpath is not defined' do
|
109
114
|
let(:request) { double(:request, request_uri: '/request_uri') }
|
110
115
|
|
111
|
-
before { adapter.
|
116
|
+
before { allow(adapter).to receive_messages(request: request) }
|
112
117
|
|
113
118
|
it "sets the adapter's request_uri to the request.request_uri" do
|
114
119
|
expect(adapter.request_uri).to eq '/request_uri'
|
@@ -117,19 +122,19 @@ module SimpleNavigation
|
|
117
122
|
end
|
118
123
|
|
119
124
|
context "when the adapter's request is not set" do
|
120
|
-
before { adapter.
|
125
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
121
126
|
|
122
127
|
it "sets the adapter's request_uri to an empty string" do
|
123
128
|
expect(adapter.request_uri).to eq ''
|
124
129
|
end
|
125
130
|
end
|
126
131
|
end
|
127
|
-
|
132
|
+
|
128
133
|
describe '#request_path' do
|
129
134
|
context "when the adapter's request is set" do
|
130
135
|
let(:request) { double(:request, path: '/request_path') }
|
131
136
|
|
132
|
-
before { adapter.
|
137
|
+
before { allow(adapter).to receive_messages(request: request) }
|
133
138
|
|
134
139
|
it "sets the adapter's request_path to the request.path" do
|
135
140
|
expect(adapter.request_path).to eq '/request_path'
|
@@ -137,7 +142,7 @@ module SimpleNavigation
|
|
137
142
|
end
|
138
143
|
|
139
144
|
context "when the adapter's request is not set" do
|
140
|
-
before { adapter.
|
145
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
141
146
|
|
142
147
|
it "sets the adapter's request_path to an empty string" do
|
143
148
|
expect(adapter.request_path).to eq ''
|
@@ -189,7 +194,7 @@ module SimpleNavigation
|
|
189
194
|
|
190
195
|
describe '#current_page?' do
|
191
196
|
context "when the adapter's template is set" do
|
192
|
-
before { adapter.
|
197
|
+
before { allow(adapter).to receive_messages(template: template) }
|
193
198
|
|
194
199
|
it 'delegates the call to the template' do
|
195
200
|
expect(template).to receive(:current_page?).with(:page)
|
@@ -198,10 +203,16 @@ module SimpleNavigation
|
|
198
203
|
end
|
199
204
|
|
200
205
|
context "when the adapter's template is not set" do
|
201
|
-
before { adapter.
|
206
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
202
207
|
|
203
208
|
it 'returns false' do
|
204
|
-
expect(adapter
|
209
|
+
expect(adapter.current_page?(:page)).to be_falsey
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when the given url is nil' do
|
214
|
+
it 'returns false' do
|
215
|
+
expect(adapter.current_page?(nil)).to be_falsey
|
205
216
|
end
|
206
217
|
end
|
207
218
|
end
|
@@ -210,7 +221,7 @@ module SimpleNavigation
|
|
210
221
|
let(:options) { double(:options) }
|
211
222
|
|
212
223
|
context "when the adapter's template is set" do
|
213
|
-
before { adapter.
|
224
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
214
225
|
|
215
226
|
context 'with considering item names as safe' do
|
216
227
|
before { SimpleNavigation.config.consider_item_names_as_safe = true }
|
@@ -232,11 +243,10 @@ module SimpleNavigation
|
|
232
243
|
end
|
233
244
|
end
|
234
245
|
|
235
|
-
|
236
246
|
end
|
237
247
|
|
238
248
|
context "when the adapter's template is not set" do
|
239
|
-
before { adapter.
|
249
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
240
250
|
|
241
251
|
it 'returns nil' do
|
242
252
|
expect(adapter.link_to('text', 'url', options)).to be_nil
|
@@ -248,7 +258,7 @@ module SimpleNavigation
|
|
248
258
|
let(:options) { double(:options) }
|
249
259
|
|
250
260
|
context "when the adapter's template is set" do
|
251
|
-
before { adapter.
|
261
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
252
262
|
|
253
263
|
it 'delegates the call to the template (with html_safe text)' do
|
254
264
|
expect(template).to receive(:content_tag)
|
@@ -258,7 +268,7 @@ module SimpleNavigation
|
|
258
268
|
end
|
259
269
|
|
260
270
|
context "when the adapter's template is not set" do
|
261
|
-
before { adapter.
|
271
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
262
272
|
|
263
273
|
it 'returns nil' do
|
264
274
|
expect(adapter.content_tag(:div, 'text', options)).to be_nil
|
@@ -266,67 +276,6 @@ module SimpleNavigation
|
|
266
276
|
end
|
267
277
|
end
|
268
278
|
|
269
|
-
describe '#extract_controller_from' do
|
270
|
-
context 'when context responds to controller' do
|
271
|
-
it 'returns the controller' do
|
272
|
-
expect(adapter.send(:extract_controller_from, context)).to be controller
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context 'when context does not respond to controller' do
|
277
|
-
let(:context) { double(:context) }
|
278
|
-
|
279
|
-
it 'returns the context' do
|
280
|
-
expect(adapter.send(:extract_controller_from, context)).to be context
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe '#html_safe' do
|
286
|
-
let(:input) { double(:input) }
|
287
|
-
|
288
|
-
context 'when input responds to html_safe' do
|
289
|
-
let(:safe) { double(:safe) }
|
290
|
-
|
291
|
-
before { input.stub(html_safe: safe) }
|
292
|
-
|
293
|
-
it 'returns the html safe version of the input' do
|
294
|
-
expect(adapter.send(:html_safe, input)).to be safe
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'when input does not respond to html_safe' do
|
299
|
-
it 'returns the input' do
|
300
|
-
expect(adapter.send(:html_safe, input)).to be input
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe '#link_title' do
|
306
|
-
let(:name) { double(:name, html_safe: safe) }
|
307
|
-
let(:safe) { double(:safe) }
|
308
|
-
|
309
|
-
context 'when config option consider_item_names_as_safe is true' do
|
310
|
-
before { SimpleNavigation.config.consider_item_names_as_safe = true }
|
311
|
-
after { SimpleNavigation.config.consider_item_names_as_safe = false }
|
312
|
-
|
313
|
-
it 'uses the html_safe version of the name' do
|
314
|
-
expect(adapter.send(:link_title, name)).to be safe
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
# TODO: Does it make sense ?
|
319
|
-
context 'when config option consider_item_names_as_safe is false (default)' do
|
320
|
-
before do
|
321
|
-
SimpleNavigation.config.consider_item_names_as_safe = false
|
322
|
-
adapter.stub(template: template)
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'uses the item name' do
|
326
|
-
expect(adapter.send(:link_title, name)).to be name
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
279
|
end
|
331
280
|
end
|
332
281
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe SimpleNavigation::Adapters::Sinatra do
|
4
2
|
let(:adapter) { SimpleNavigation::Adapters::Sinatra.new(context) }
|
5
3
|
let(:context) { double(:context) }
|
6
4
|
let(:request) { double(:request, fullpath: '/full?param=true', path: '/full') }
|
7
5
|
|
8
|
-
before { context.
|
6
|
+
before { allow(context).to receive_messages(request: request) }
|
9
7
|
|
10
8
|
describe '#context_for_eval' do
|
11
9
|
context "when adapter's context is not set" do
|
12
10
|
it 'raises an exception' do
|
13
|
-
adapter.
|
11
|
+
allow(adapter).to receive_messages(context: nil)
|
14
12
|
expect{ adapter.context_for_eval }.to raise_error
|
15
13
|
end
|
16
14
|
end
|
@@ -35,7 +33,7 @@ describe SimpleNavigation::Adapters::Sinatra do
|
|
35
33
|
end
|
36
34
|
|
37
35
|
describe '#current_page?' do
|
38
|
-
before { request.
|
36
|
+
before { allow(request).to receive_messages(scheme: 'http', host_with_port: 'my_host:5000') }
|
39
37
|
|
40
38
|
shared_examples 'detecting current page' do |url, expected|
|
41
39
|
context "when url is #{url}" do
|
@@ -59,7 +57,7 @@ describe SimpleNavigation::Adapters::Sinatra do
|
|
59
57
|
|
60
58
|
context 'when URL is encoded' do
|
61
59
|
before do
|
62
|
-
request.
|
60
|
+
allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true',
|
63
61
|
path: '/full%20with%20spaces')
|
64
62
|
end
|
65
63
|
|