simple-navigation 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +11 -0
- data/Gemfile +2 -16
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -39
- data/generators/navigation_config/templates/config/navigation.rb +7 -5
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/adapters/rails.rb +5 -1
- data/lib/simple_navigation/core/configuration.rb +5 -1
- data/lib/simple_navigation/core/item.rb +2 -1
- data/lib/simple_navigation/core/item_adapter.rb +4 -4
- data/lib/simple_navigation/core/item_container.rb +6 -1
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
- data/lib/simple_navigation/version.rb +3 -0
- data/lib/simple_navigation.rb +1 -0
- data/simple-navigation.gemspec +40 -0
- data/spec/initializers/have_css_matcher.rb +13 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
- data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
- data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
- data/spec/lib/simple_navigation_spec.rb +207 -225
- data/spec/spec_helper.rb +53 -82
- data/uninstall.rb +1 -0
- metadata +100 -22
- data/README +0 -22
- data/VERSION +0 -1
@@ -1,287 +1,313 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
module Adapters
|
5
|
+
describe Rails do
|
6
|
+
let(:action_controller) { ActionController::Base }
|
7
|
+
let(:adapter) { SimpleNavigation::Adapters::Rails.new(context) }
|
8
|
+
let(:context) { double(:context, controller: controller) }
|
9
|
+
let(:controller) { double(:controller) }
|
10
|
+
let(:request) { double(:request) }
|
11
|
+
let(:simple_navigation) { SimpleNavigation }
|
12
|
+
let(:template) { double(:template, request: request) }
|
4
13
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
14
|
+
describe '.register' do
|
15
|
+
before { action_controller.stub(:include) }
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@request = stub(:request)
|
14
|
-
@template = stub(:template, :request => @request)
|
15
|
-
@adapter = create_adapter
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'self.register' do
|
19
|
-
before(:each) do
|
20
|
-
ActionController::Base.stub!(:include)
|
21
|
-
end
|
22
|
-
it "should call set_env" do
|
23
|
-
SimpleNavigation.should_receive(:set_env).with('./', 'test')
|
24
|
-
SimpleNavigation.register
|
25
|
-
end
|
26
|
-
it "should extend the ActionController::Base with the Helpers" do
|
27
|
-
ActionController::Base.should_receive(:include).with(SimpleNavigation::Helpers)
|
28
|
-
SimpleNavigation.register
|
29
|
-
end
|
30
|
-
it "should install the helper methods in the controller" do
|
31
|
-
ActionController::Base.should_receive(:helper_method).with(:render_navigation)
|
32
|
-
ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_name)
|
33
|
-
ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_key)
|
34
|
-
ActionController::Base.should_receive(:helper_method).with(:active_navigation_item)
|
35
|
-
ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_container)
|
36
|
-
SimpleNavigation.register
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
17
|
+
it 'calls set_env' do
|
18
|
+
expect(simple_navigation).to receive(:set_env).with('./', 'test')
|
19
|
+
simple_navigation.register
|
20
|
+
end
|
40
21
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@controller.stub!(:instance_variable_get => @template)
|
46
|
-
@adapter = create_adapter
|
22
|
+
it 'extends the ActionController::Base with the Helpers' do
|
23
|
+
expect(action_controller).to receive(:include)
|
24
|
+
.with(SimpleNavigation::Helpers)
|
25
|
+
simple_navigation.register
|
47
26
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
27
|
+
|
28
|
+
it 'installs the helper methods in the controller' do
|
29
|
+
expect(action_controller).to receive(:helper_method).with(:render_navigation)
|
30
|
+
expect(action_controller).to receive(:helper_method).with(:active_navigation_item_name)
|
31
|
+
expect(action_controller).to receive(:helper_method).with(:active_navigation_item_key)
|
32
|
+
expect(action_controller).to receive(:helper_method).with(:active_navigation_item)
|
33
|
+
expect(action_controller).to receive(:helper_method).with(:active_navigation_item_container)
|
34
|
+
simple_navigation.register
|
53
35
|
end
|
54
|
-
it {@adapter.request.should be_nil}
|
55
36
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
context 'template is stored in controller as instance_var (Rails2)' do
|
64
|
-
context 'template is set' do
|
65
|
-
before(:each) do
|
66
|
-
@controller.stub!(:instance_variable_get => @template)
|
67
|
-
@adapter = create_adapter
|
37
|
+
|
38
|
+
describe '#initialize' do
|
39
|
+
context "when the controller's template is set" do
|
40
|
+
before { controller.stub(instance_variable_get: template) }
|
41
|
+
|
42
|
+
it "sets the adapter's request accordingly" do
|
43
|
+
expect(adapter.request).to be request
|
68
44
|
end
|
69
|
-
|
70
|
-
|
71
|
-
context 'template is not set
|
72
|
-
before(:
|
73
|
-
|
74
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the controller's template is not set" do
|
48
|
+
before { controller.stub(instance_variable_get: nil) }
|
49
|
+
|
50
|
+
it "sets the adapter's request to nil" do
|
51
|
+
expect(adapter.request).to be_nil
|
75
52
|
end
|
76
|
-
it {@adapter.template.should be_nil}
|
77
53
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
54
|
+
|
55
|
+
it "sets the adapter's controller to the context's controller" do
|
56
|
+
expect(adapter.controller).to be controller
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the controller's template is stored as instance var (Rails2)" do
|
60
|
+
context "when the controller's template is set" do
|
61
|
+
before { controller.stub(instance_variable_get: template) }
|
62
|
+
|
63
|
+
it "sets the adapter's template accordingly" do
|
64
|
+
expect(adapter.template).to be template
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the controller's template is not set" do
|
69
|
+
before { controller.stub(instance_variable_get: nil) }
|
70
|
+
|
71
|
+
it "set the adapter's template to nil" do
|
72
|
+
expect(adapter.template).to be_nil
|
73
|
+
end
|
84
74
|
end
|
85
|
-
it {@adapter.template.should == @template}
|
86
75
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
76
|
+
|
77
|
+
context "when the controller's template is stored as view_context (Rails3)" do
|
78
|
+
context 'and the template is set' do
|
79
|
+
before { controller.stub(view_context: template) }
|
80
|
+
|
81
|
+
it "sets the adapter's template accordingly" do
|
82
|
+
expect(adapter.template).to be template
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'and the template is not set' do
|
87
|
+
before { controller.stub(view_context: nil) }
|
88
|
+
|
89
|
+
it "sets the adapter's template to nil" do
|
90
|
+
expect(adapter.template).to be_nil
|
91
|
+
end
|
91
92
|
end
|
92
|
-
it {@adapter.template.should be_nil}
|
93
93
|
end
|
94
94
|
end
|
95
|
-
end
|
96
|
-
end
|
97
95
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
describe '#request_uri' do
|
97
|
+
context "when the adapter's request is set" do
|
98
|
+
before { adapter.stub(request: request) }
|
99
|
+
|
100
|
+
context 'and request.fullpath is defined' do
|
101
|
+
let(:request) { double(:request, fullpath: '/fullpath') }
|
102
|
+
|
103
|
+
it "sets the adapter's request_uri to the request.fullpath" do
|
104
|
+
expect(adapter.request_uri).to eq '/fullpath'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'and request.fullpath is not defined' do
|
109
|
+
let(:request) { double(:request, request_uri: '/request_uri') }
|
110
|
+
|
111
|
+
before { adapter.stub(request: request) }
|
112
|
+
|
113
|
+
it "sets the adapter's request_uri to the request.request_uri" do
|
114
|
+
expect(adapter.request_uri).to eq '/request_uri'
|
115
|
+
end
|
116
|
+
end
|
104
117
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
118
|
+
|
119
|
+
context "when the adapter's request is not set" do
|
120
|
+
before { adapter.stub(request: nil) }
|
121
|
+
|
122
|
+
it "sets the adapter's request_uri to an empty string" do
|
123
|
+
expect(adapter.request_uri).to eq ''
|
124
|
+
end
|
111
125
|
end
|
112
|
-
it {@adapter.request_uri.should == '/request_uri'}
|
113
126
|
end
|
114
|
-
end
|
115
|
-
context 'request is not set' do
|
116
|
-
before(:each) do
|
117
|
-
@adapter.stub!(:request => nil)
|
118
|
-
end
|
119
|
-
it {@adapter.request_uri.should == ''}
|
120
|
-
end
|
121
|
-
end
|
122
127
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
before(:each) do
|
133
|
-
@adapter.stub!(:request => nil)
|
134
|
-
end
|
135
|
-
it {@adapter.request_path.should == ''}
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'context_for_eval' do
|
140
|
-
context 'controller is present' do
|
141
|
-
before(:each) do
|
142
|
-
@controller = stub(:controller)
|
143
|
-
@adapter.instance_variable_set(:@controller, @controller)
|
144
|
-
end
|
145
|
-
context 'template is present' do
|
146
|
-
before(:each) do
|
147
|
-
@template = stub(:template)
|
148
|
-
@adapter.instance_variable_set(:@template, @template)
|
128
|
+
describe '#request_path' do
|
129
|
+
context "when the adapter's request is set" do
|
130
|
+
let(:request) { double(:request, path: '/request_path') }
|
131
|
+
|
132
|
+
before { adapter.stub(request: request) }
|
133
|
+
|
134
|
+
it "sets the adapter's request_path to the request.path" do
|
135
|
+
expect(adapter.request_path).to eq '/request_path'
|
136
|
+
end
|
149
137
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
138
|
+
|
139
|
+
context "when the adapter's request is not set" do
|
140
|
+
before { adapter.stub(request: nil) }
|
141
|
+
|
142
|
+
it "sets the adapter's request_path to an empty string" do
|
143
|
+
expect(adapter.request_path).to eq ''
|
144
|
+
end
|
155
145
|
end
|
156
|
-
it {@adapter.context_for_eval.should == @controller}
|
157
146
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
147
|
+
|
148
|
+
describe '#context_for_eval' do
|
149
|
+
context "when the adapter's controller is set" do
|
150
|
+
before { adapter.instance_variable_set(:@controller, controller) }
|
151
|
+
|
152
|
+
context "and the adapter's template is set" do
|
153
|
+
before { adapter.instance_variable_set(:@template, template) }
|
154
|
+
|
155
|
+
it "sets the adapter's context_for_eval to the template" do
|
156
|
+
expect(adapter.context_for_eval).to be template
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "and the adapter's template is not set" do
|
161
|
+
before { adapter.instance_variable_set(:@template, nil) }
|
162
|
+
|
163
|
+
it "sets the adapter's context_for_eval to the controller" do
|
164
|
+
expect(adapter.context_for_eval).to be controller
|
165
|
+
end
|
166
|
+
end
|
167
167
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
168
|
+
|
169
|
+
context "when the adapter's controller is not set" do
|
170
|
+
before { adapter.instance_variable_set(:@controller, nil) }
|
171
|
+
|
172
|
+
context "and the adapter's template is set" do
|
173
|
+
before { adapter.instance_variable_set(:@template, template) }
|
174
|
+
|
175
|
+
it "sets the adapter's context_for_eval to the template" do
|
176
|
+
expect(adapter.context_for_eval).to be template
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "and the adapter's template is not set" do
|
181
|
+
before { adapter.instance_variable_set(:@template, nil) }
|
182
|
+
|
183
|
+
it 'raises an exception' do
|
184
|
+
expect{ adapter.context_for_eval }.to raise_error
|
185
|
+
end
|
186
|
+
end
|
173
187
|
end
|
174
|
-
it {lambda {@adapter.context_for_eval}.should raise_error}
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe 'current_page?' do
|
180
|
-
context 'template is set' do
|
181
|
-
before(:each) do
|
182
|
-
@adapter.stub!(:template => @template)
|
183
|
-
end
|
184
|
-
it "should delegate the call to the template" do
|
185
|
-
@template.should_receive(:current_page?).with(:page)
|
186
|
-
@adapter.current_page?(:page)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
context 'template is not set' do
|
190
|
-
before(:each) do
|
191
|
-
@adapter.stub!(:template => nil)
|
192
|
-
end
|
193
|
-
it {@adapter.should_not be_current_page(:page)}
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe 'link_to' do
|
198
|
-
context 'template is set' do
|
199
|
-
before(:each) do
|
200
|
-
@adapter.stub!(:template => @template)
|
201
|
-
@adapter.stub!(:html_safe => 'safe_text')
|
202
|
-
@options = stub(:options)
|
203
|
-
end
|
204
|
-
it "should delegate the call to the template (with html_safe text)" do
|
205
|
-
@template.should_receive(:link_to).with('safe_text', 'url', @options)
|
206
|
-
@adapter.link_to('text', 'url', @options)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
context 'template is not set' do
|
210
|
-
before(:each) do
|
211
|
-
@adapter.stub!(:template => nil)
|
212
188
|
end
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
@adapter.stub!(:template => nil)
|
232
|
-
end
|
233
|
-
it {@adapter.content_tag(:div, 'text', @options).should be_nil}
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe 'self.extract_controller_from' do
|
238
|
-
context 'object responds to controller' do
|
239
|
-
before(:each) do
|
240
|
-
@context.stub!(:controller => @controller)
|
241
|
-
end
|
242
|
-
it "should return the controller" do
|
243
|
-
@adapter.send(:extract_controller_from, @context).should == @controller
|
189
|
+
|
190
|
+
describe '#current_page?' do
|
191
|
+
context "when the adapter's template is set" do
|
192
|
+
before { adapter.stub(template: template) }
|
193
|
+
|
194
|
+
it 'delegates the call to the template' do
|
195
|
+
expect(template).to receive(:current_page?).with(:page)
|
196
|
+
adapter.current_page?(:page)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when the adapter's template is not set" do
|
201
|
+
before { adapter.stub(template: nil) }
|
202
|
+
|
203
|
+
it 'returns false' do
|
204
|
+
expect(adapter).not_to be_current_page(:page)
|
205
|
+
end
|
206
|
+
end
|
244
207
|
end
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
208
|
+
|
209
|
+
describe '#link_to' do
|
210
|
+
let(:options) { double(:options) }
|
211
|
+
|
212
|
+
context "when the adapter's template is set" do
|
213
|
+
before { adapter.stub(template: template, html_safe: 'safe_text') }
|
214
|
+
|
215
|
+
it 'delegates the call to the template (with html_safe text)' do
|
216
|
+
expect(template).to receive(:link_to)
|
217
|
+
.with('safe_text', 'url', options)
|
218
|
+
adapter.link_to('text', 'url', options)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when the adapter's template is not set" do
|
223
|
+
before { adapter.stub(template: nil) }
|
224
|
+
|
225
|
+
it 'returns nil' do
|
226
|
+
expect(adapter.link_to('text', 'url', options)).to be_nil
|
227
|
+
end
|
228
|
+
end
|
249
229
|
end
|
250
|
-
|
251
|
-
|
230
|
+
|
231
|
+
describe '#content_tag' do
|
232
|
+
let(:options) { double(:options) }
|
233
|
+
|
234
|
+
context "when the adapter's template is set" do
|
235
|
+
before { adapter.stub(template: template, html_safe: 'safe_text') }
|
236
|
+
|
237
|
+
it 'delegates the call to the template (with html_safe text)' do
|
238
|
+
expect(template).to receive(:content_tag)
|
239
|
+
.with(:div, 'safe_text', options)
|
240
|
+
adapter.content_tag(:div, 'text', options)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when the adapter's template is not set" do
|
245
|
+
before { adapter.stub(template: nil) }
|
246
|
+
|
247
|
+
it 'returns nil' do
|
248
|
+
expect(adapter.content_tag(:div, 'text', options)).to be_nil
|
249
|
+
end
|
250
|
+
end
|
252
251
|
end
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
252
|
+
|
253
|
+
describe '#extract_controller_from' do
|
254
|
+
context 'when context responds to controller' do
|
255
|
+
it 'returns the controller' do
|
256
|
+
expect(adapter.send(:extract_controller_from, context)).to be controller
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'when context does not respond to controller' do
|
261
|
+
let(:context) { double(:context) }
|
262
|
+
|
263
|
+
it 'returns the context' do
|
264
|
+
expect(adapter.send(:extract_controller_from, context)).to be context
|
265
|
+
end
|
266
|
+
end
|
264
267
|
end
|
265
|
-
it {@adapter.send(:html_safe, @input).should == @safe}
|
266
|
-
end
|
267
|
-
context 'input does not respond to html_safe' do
|
268
|
-
it {@adapter.send(:html_safe, @input).should == @input}
|
269
|
-
end
|
270
|
-
end
|
271
268
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
269
|
+
describe '#html_safe' do
|
270
|
+
let(:input) { double(:input) }
|
271
|
+
|
272
|
+
context 'when input responds to html_safe' do
|
273
|
+
let(:safe) { double(:safe) }
|
274
|
+
|
275
|
+
before { input.stub(html_safe: safe) }
|
276
|
+
|
277
|
+
it 'returns the html safe version of the input' do
|
278
|
+
expect(adapter.send(:html_safe, input)).to be safe
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when input does not respond to html_safe' do
|
283
|
+
it 'returns the input' do
|
284
|
+
expect(adapter.send(:html_safe, input)).to be input
|
285
|
+
end
|
286
|
+
end
|
276
287
|
end
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
288
|
+
|
289
|
+
describe '#link_title' do
|
290
|
+
let(:name) { double(:name, html_safe: safe) }
|
291
|
+
let(:safe) { double(:safe) }
|
292
|
+
|
293
|
+
context 'when config option consider_item_names_as_safe is true' do
|
294
|
+
it 'uses the html_safe version of the name' do
|
295
|
+
expect(adapter.send(:link_title, name)).to be safe
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# TODO: Does it make sense ?
|
300
|
+
context 'when config option consider_item_names_as_safe is false' do
|
301
|
+
before do
|
302
|
+
SimpleNavigation.config.consider_item_names_as_safe = false
|
303
|
+
adapter.stub(template: template)
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'uses the item name' do
|
307
|
+
expect(adapter.send(:link_title, name)).to be name
|
308
|
+
end
|
309
|
+
end
|
282
310
|
end
|
283
|
-
it {@adapter.send(:template_from, @controller).should == 'view'}
|
284
311
|
end
|
285
312
|
end
|
286
|
-
|
287
313
|
end
|