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,307 +1,289 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SimpleNavigation do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
SimpleNavigation.config_file_path = 'path_to_config'
|
7
|
-
end
|
4
|
+
before { subject.config_file_path = 'path_to_config' }
|
8
5
|
|
9
6
|
describe 'config_file_name' do
|
10
|
-
context '
|
11
|
-
it
|
12
|
-
|
7
|
+
context 'when the navigation_context is :default' do
|
8
|
+
it 'returns the name of the default config file' do
|
9
|
+
expect(subject.config_file_name).to eq 'navigation.rb'
|
13
10
|
end
|
14
11
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
|
13
|
+
context 'when the navigation_context is NOT :default' do
|
14
|
+
it 'returns the name of the config file matching the specified context' do
|
15
|
+
file_name = subject.config_file_name(:my_other_context)
|
16
|
+
expect(file_name).to eq 'my_other_context_navigation.rb'
|
18
17
|
end
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
it 'converts camelcase-contexts to underscore' do
|
20
|
+
file_name = subject.config_file_name(:WhyWouldYouDoThis)
|
21
|
+
expect(file_name).to eq 'why_would_you_do_this_navigation.rb'
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
describe 'config_file_path=' do
|
26
|
-
before
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
SimpleNavigation.config_file_paths.should == ['new_path']
|
27
|
+
before { subject.config_file_paths = ['existing_path'] }
|
28
|
+
|
29
|
+
it 'overrides the config_file_paths' do
|
30
|
+
subject.config_file_path = 'new_path'
|
31
|
+
expect(subject.config_file_paths).to eq ['new_path']
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe 'config_file' do
|
36
|
-
context 'no config_file_paths are set' do
|
37
|
-
before
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
SimpleNavigation.config_file.should be_nil
|
36
|
+
context 'when no config_file_paths are set' do
|
37
|
+
before { subject.config_file_paths = [] }
|
38
|
+
|
39
|
+
it 'returns nil' do
|
40
|
+
expect(subject.config_file).to be_nil
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
context 'requested config file
|
49
|
-
before(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
SimpleNavigation.config_file.should == 'my_config_file_path/navigation.rb'
|
43
|
+
|
44
|
+
context 'when one config_file_path is set' do
|
45
|
+
before { subject.config_file_paths = ['my_config_file_path'] }
|
46
|
+
|
47
|
+
context 'and the requested config file exists' do
|
48
|
+
before { File.stub(exists?: true) }
|
49
|
+
|
50
|
+
it 'returns the path to the config_file' do
|
51
|
+
expect(subject.config_file).to eq 'my_config_file_path/navigation.rb'
|
54
52
|
end
|
55
53
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
it
|
61
|
-
|
54
|
+
|
55
|
+
context 'and the requested config file does not exist' do
|
56
|
+
before { File.stub(exists?: false) }
|
57
|
+
|
58
|
+
it 'returns nil' do
|
59
|
+
expect(subject.config_file).to be_nil
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
context 'requested config file
|
70
|
-
before(
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
SimpleNavigation.config_file.should == 'first_path/navigation.rb'
|
63
|
+
|
64
|
+
context 'when multiple config_file_paths are set' do
|
65
|
+
before { subject.config_file_paths = ['first_path', 'second_path'] }
|
66
|
+
|
67
|
+
context 'and the requested config file exists' do
|
68
|
+
before { File.stub(exists?: true) }
|
69
|
+
|
70
|
+
it 'returns the path to the first matching config_file' do
|
71
|
+
expect(subject.config_file).to eq 'first_path/navigation.rb'
|
75
72
|
end
|
76
73
|
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
it
|
82
|
-
|
74
|
+
|
75
|
+
context 'and the requested config file does not exist' do
|
76
|
+
before { File.stub(exists?: false) }
|
77
|
+
|
78
|
+
it 'returns nil' do
|
79
|
+
expect(subject.config_file).to be_nil
|
83
80
|
end
|
84
81
|
end
|
85
82
|
end
|
86
83
|
end
|
87
|
-
|
88
|
-
describe 'config_file?' do
|
89
|
-
context 'config_file present' do
|
90
|
-
before(:
|
91
|
-
|
84
|
+
|
85
|
+
describe '.config_file?' do
|
86
|
+
context 'when config_file is present' do
|
87
|
+
before { subject.stub(config_file: 'file') }
|
88
|
+
|
89
|
+
it 'returns true' do
|
90
|
+
expect(subject.config_file?).to be_true
|
92
91
|
end
|
93
|
-
it {SimpleNavigation.config_file?.should be_true}
|
94
92
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
|
94
|
+
context 'when config_file is not present' do
|
95
|
+
before { subject.stub(config_file: nil) }
|
96
|
+
|
97
|
+
it 'returns false' do
|
98
|
+
expect(subject.config_file?).to be_false
|
98
99
|
end
|
99
|
-
it {SimpleNavigation.config_file?.should be_false}
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe '
|
104
|
-
before(:
|
105
|
-
|
103
|
+
describe '.default_config_file_path' do
|
104
|
+
before { subject.stub(root: 'root') }
|
105
|
+
|
106
|
+
it 'returns the config file path according to :root setting' do
|
107
|
+
expect(subject.default_config_file_path).to eq 'root/config'
|
106
108
|
end
|
107
|
-
it {SimpleNavigation.default_config_file_path.should == 'root/config'}
|
108
109
|
end
|
109
|
-
|
110
|
-
describe '
|
111
|
-
it
|
112
|
-
|
110
|
+
|
111
|
+
describe 'Regarding renderers' do
|
112
|
+
it 'registers the builtin renderers by default' do
|
113
|
+
expect(subject.registered_renderers).not_to be_empty
|
113
114
|
end
|
114
115
|
|
115
|
-
describe 'register_renderer' do
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
SimpleNavigation.registered_renderers[:my_renderer].should == @renderer
|
116
|
+
describe '.register_renderer' do
|
117
|
+
let(:renderer) { double(:renderer) }
|
118
|
+
|
119
|
+
it 'adds the specified renderer to the list of renderers' do
|
120
|
+
subject.register_renderer(my_renderer: renderer)
|
121
|
+
expect(subject.registered_renderers[:my_renderer]).to be renderer
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
125
124
|
end
|
126
125
|
|
127
|
-
describe 'set_env' do
|
128
|
-
before
|
129
|
-
|
130
|
-
|
131
|
-
|
126
|
+
describe '.set_env' do
|
127
|
+
before do
|
128
|
+
subject.config_file_paths = []
|
129
|
+
subject.stub(default_config_file_path: 'default_path')
|
130
|
+
subject.set_env('root', 'my_env')
|
132
131
|
end
|
133
|
-
|
134
|
-
|
132
|
+
|
133
|
+
it 'sets the root' do
|
134
|
+
expect(subject.root).to eq 'root'
|
135
135
|
end
|
136
|
-
|
137
|
-
|
136
|
+
|
137
|
+
it 'sets the environment' do
|
138
|
+
expect(subject.environment).to eq 'my_env'
|
138
139
|
end
|
139
|
-
|
140
|
-
|
140
|
+
|
141
|
+
it 'adds the default-config path to the list of config_file_paths' do
|
142
|
+
expect(subject.config_file_paths).to eq ['default_path']
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
|
-
describe 'load_config' do
|
145
|
-
context 'config_file_path is set' do
|
146
|
-
before(:
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
IO.stub!(:read => 'file_content')
|
146
|
+
describe '.load_config' do
|
147
|
+
context 'when config_file_path is set' do
|
148
|
+
before { subject.stub(config_file: 'path_to_config_file') }
|
149
|
+
|
150
|
+
context 'and config_file exists' do
|
151
|
+
before do
|
152
|
+
subject.stub(config_file?: true)
|
153
|
+
IO.stub(read: 'file_content')
|
153
154
|
end
|
154
|
-
|
155
|
-
|
155
|
+
|
156
|
+
it "doesn't raise any error" do
|
157
|
+
expect{ subject.load_config }.not_to raise_error
|
156
158
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
159
|
+
|
160
|
+
it 'reads the specified config file from disc' do
|
161
|
+
expect(IO).to receive(:read).with('path_to_config_file')
|
162
|
+
subject.load_config
|
160
163
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
164
|
+
|
165
|
+
it 'stores the read content in the module (default context)' do
|
166
|
+
expect(subject).to receive(:config_file).with(:default)
|
167
|
+
subject.load_config
|
168
|
+
expect(subject.config_files[:default]).to eq 'file_content'
|
165
169
|
end
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
+
|
171
|
+
it 'stores the content in the module (non default context)' do
|
172
|
+
expect(subject).to receive(:config_file).with(:my_context)
|
173
|
+
subject.load_config(:my_context)
|
174
|
+
expect(subject.config_files[:my_context]).to eq 'file_content'
|
170
175
|
end
|
171
176
|
end
|
172
|
-
|
173
|
-
context 'config_file does not exist' do
|
174
|
-
before(
|
175
|
-
|
177
|
+
|
178
|
+
context 'and config_file does not exist' do
|
179
|
+
before { subject.stub(config_file?: false) }
|
180
|
+
|
181
|
+
it 'raises an exception' do
|
182
|
+
expect{ subject.load_config }.to raise_error
|
176
183
|
end
|
177
|
-
it {lambda{SimpleNavigation.load_config}.should raise_error}
|
178
184
|
end
|
179
185
|
end
|
180
|
-
|
181
|
-
context 'config_file_path is not set' do
|
182
|
-
before
|
183
|
-
|
186
|
+
|
187
|
+
context 'when config_file_path is not set' do
|
188
|
+
before { subject.config_file_path = nil }
|
189
|
+
|
190
|
+
it 'raises an exception' do
|
191
|
+
expect{ subject.load_config }.to raise_error
|
184
192
|
end
|
185
|
-
it {lambda{SimpleNavigation.load_config}.should raise_error}
|
186
193
|
end
|
187
|
-
|
188
|
-
describe '
|
189
|
-
before
|
190
|
-
|
191
|
-
|
192
|
-
File.stub
|
193
|
-
end
|
194
|
-
context "environment undefined" do
|
195
|
-
before(:each) do
|
196
|
-
SimpleNavigation.stub!(:environment => nil)
|
197
|
-
end
|
198
|
-
it "should load the config file twice" do
|
199
|
-
IO.should_receive(:read).twice
|
200
|
-
SimpleNavigation.load_config
|
201
|
-
SimpleNavigation.load_config
|
202
|
-
end
|
194
|
+
|
195
|
+
describe 'Regarding caching of the config-files' do
|
196
|
+
before do
|
197
|
+
subject.config_file_path = 'path_to_config'
|
198
|
+
IO.stub(:read).and_return('file_content')
|
199
|
+
File.stub(exists?: true)
|
203
200
|
end
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
context "environment
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
context "environment=development" do
|
217
|
-
before(:each) do
|
218
|
-
SimpleNavigation.stub!(:environment => 'development')
|
219
|
-
end
|
220
|
-
it "should load the config file twice" do
|
221
|
-
IO.should_receive(:read).twice
|
222
|
-
SimpleNavigation.load_config
|
223
|
-
SimpleNavigation.load_config
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context "environment=test" do
|
228
|
-
before(:each) do
|
229
|
-
SimpleNavigation.stub!(:environment => 'test')
|
230
|
-
end
|
231
|
-
it "should load the config file twice" do
|
232
|
-
IO.should_receive(:read).twice
|
233
|
-
SimpleNavigation.load_config
|
234
|
-
SimpleNavigation.load_config
|
201
|
+
|
202
|
+
after { subject.config_files = {} }
|
203
|
+
|
204
|
+
shared_examples 'loading config file' do |env, count|
|
205
|
+
context "when environment is '#{env}'" do
|
206
|
+
before { subject.stub(environment: env) }
|
207
|
+
|
208
|
+
it "loads the config file #{count}" do
|
209
|
+
expect(IO).to receive(:read).exactly(count)
|
210
|
+
2.times { subject.load_config }
|
235
211
|
end
|
236
212
|
end
|
237
213
|
end
|
238
|
-
|
239
|
-
|
240
|
-
|
214
|
+
|
215
|
+
it_behaves_like 'loading config file', nil, :twice
|
216
|
+
it_behaves_like 'loading config file', 'production', :once
|
217
|
+
it_behaves_like 'loading config file', 'development', :twice
|
218
|
+
it_behaves_like 'loading config file', 'test', :twice
|
241
219
|
end
|
242
220
|
end
|
243
|
-
|
244
|
-
describe 'config' do
|
245
|
-
it
|
246
|
-
|
247
|
-
|
248
|
-
describe 'active_item_container_for' do
|
249
|
-
before(:each) do
|
250
|
-
@primary = stub(:primary)
|
251
|
-
SimpleNavigation.config.stub!(:primary_navigation => @primary)
|
221
|
+
|
222
|
+
describe '.config' do
|
223
|
+
it 'returns the Configuration singleton instance' do
|
224
|
+
expect(subject.config).to be SimpleNavigation::Configuration.instance
|
252
225
|
end
|
253
|
-
|
254
|
-
|
255
|
-
|
226
|
+
end
|
227
|
+
|
228
|
+
describe '.active_item_container_for' do
|
229
|
+
let(:primary) { double(:primary) }
|
230
|
+
|
231
|
+
before { subject.config.stub(primary_navigation: primary) }
|
232
|
+
|
233
|
+
context 'when level is :all' do
|
234
|
+
it 'returns the primary_navigation' do
|
235
|
+
nav = subject.active_item_container_for(:all)
|
236
|
+
expect(nav).to be primary
|
256
237
|
end
|
257
238
|
end
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
239
|
+
|
240
|
+
context 'when level is :leaves' do
|
241
|
+
it 'returns the currently active leaf-container' do
|
242
|
+
expect(primary).to receive(:active_leaf_container)
|
243
|
+
subject.active_item_container_for(:leaves)
|
262
244
|
end
|
263
245
|
end
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
246
|
+
|
247
|
+
context 'when level is a Range' do
|
248
|
+
it 'takes the min of the range to lookup the active container' do
|
249
|
+
expect(primary).to receive(:active_item_container_for).with(2)
|
250
|
+
subject.active_item_container_for(2..3)
|
268
251
|
end
|
269
252
|
end
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
253
|
+
|
254
|
+
context 'when level is an Integer' do
|
255
|
+
it 'considers the Integer to lookup the active container' do
|
256
|
+
expect(primary).to receive(:active_item_container_for).with(1)
|
257
|
+
subject.active_item_container_for(1)
|
274
258
|
end
|
275
259
|
end
|
276
|
-
|
277
|
-
|
278
|
-
|
260
|
+
|
261
|
+
context 'when level is something else' do
|
262
|
+
it 'raises an exception' do
|
263
|
+
expect{
|
264
|
+
subject.active_item_container_for('something else')
|
265
|
+
}.to raise_error
|
279
266
|
end
|
280
267
|
end
|
281
268
|
end
|
282
269
|
|
283
|
-
describe 'load_adapter' do
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
end
|
296
|
-
it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Padrino}
|
297
|
-
end
|
298
|
-
context 'Sinatra' do
|
299
|
-
before(:each) do
|
300
|
-
SimpleNavigation.stub!(:framework => :sinatra)
|
301
|
-
SimpleNavigation.load_adapter
|
270
|
+
describe '.load_adapter' do
|
271
|
+
shared_examples 'loading the right adapter' do |framework, adapter|
|
272
|
+
context "when the context is #{framework}" do
|
273
|
+
before do
|
274
|
+
subject.stub(framework: framework)
|
275
|
+
subject.load_adapter
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns the #{framework} adapter" do
|
279
|
+
adapter_class = SimpleNavigation::Adapters.const_get(adapter)
|
280
|
+
expect(subject.adapter_class).to be adapter_class
|
281
|
+
end
|
302
282
|
end
|
303
|
-
it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Sinatra}
|
304
283
|
end
|
284
|
+
|
285
|
+
it_behaves_like 'loading the right adapter', :rails, :Rails
|
286
|
+
it_behaves_like 'loading the right adapter', :padrino, :Padrino
|
287
|
+
it_behaves_like 'loading the right adapter', :sinatra, :Sinatra
|
305
288
|
end
|
306
|
-
|
307
289
|
end
|