simple-navigation 3.11.0 → 3.12.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.
- 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,80 +1,91 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SimpleNavigation::Adapters::Sinatra do
|
4
|
+
let(:adapter) { SimpleNavigation::Adapters::Sinatra.new(context) }
|
5
|
+
let(:context) { double(:context) }
|
6
|
+
let(:request) { double(:request, fullpath: '/full?param=true', path: '/full') }
|
4
7
|
|
5
|
-
|
6
|
-
SimpleNavigation::Adapters::Sinatra.new(@context)
|
7
|
-
end
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@context = stub(:context)
|
11
|
-
@request = stub(:request, :fullpath => '/full?param=true', :path => '/full')
|
12
|
-
@context.stub!(:request => @request)
|
13
|
-
@adapter = create_adapter
|
14
|
-
end
|
8
|
+
before { context.stub(request: request) }
|
15
9
|
|
16
|
-
describe 'context_for_eval' do
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
describe '#context_for_eval' do
|
11
|
+
context "when adapter's context is not set" do
|
12
|
+
it 'raises an exception' do
|
13
|
+
adapter.stub(context: nil)
|
14
|
+
expect{ adapter.context_for_eval }.to raise_error
|
15
|
+
end
|
20
16
|
end
|
21
|
-
|
22
|
-
|
17
|
+
|
18
|
+
context "when adapter's context is set" do
|
19
|
+
it 'returns the context' do
|
20
|
+
expect(adapter.context_for_eval).to be context
|
21
|
+
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
describe 'request_uri' do
|
27
|
-
it
|
25
|
+
describe '#request_uri' do
|
26
|
+
it 'returns the request.fullpath' do
|
27
|
+
expect(adapter.request_uri).to eq '/full?param=true'
|
28
|
+
end
|
28
29
|
end
|
29
30
|
|
30
|
-
describe 'request_path' do
|
31
|
-
it
|
31
|
+
describe '#request_path' do
|
32
|
+
it 'returns the request.path' do
|
33
|
+
expect(adapter.request_path).to eq '/full'
|
34
|
+
end
|
32
35
|
end
|
33
36
|
|
34
|
-
describe 'current_page?' do
|
35
|
-
before(:
|
36
|
-
|
37
|
+
describe '#current_page?' do
|
38
|
+
before { request.stub(scheme: 'http', host_with_port: 'my_host:5000') }
|
39
|
+
|
40
|
+
shared_examples 'detecting current page' do |url, expected|
|
41
|
+
context "when url is #{url}" do
|
42
|
+
it "returns #{expected}" do
|
43
|
+
expect(adapter.current_page?(url)).to be expected
|
44
|
+
end
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
context 'when URL is not encoded' do
|
49
|
+
it_behaves_like 'detecting current page', '/full?param=true', true
|
50
|
+
it_behaves_like 'detecting current page', '/full?param3=true', false
|
51
|
+
it_behaves_like 'detecting current page', '/full', true
|
52
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full?param=true', true
|
53
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full?param3=true', false
|
54
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full', true
|
55
|
+
it_behaves_like 'detecting current page', 'https://my_host:5000/full', false
|
56
|
+
it_behaves_like 'detecting current page', 'http://my_host:6000/full', false
|
57
|
+
it_behaves_like 'detecting current page', 'http://my_other_host:5000/full', false
|
49
58
|
end
|
50
59
|
|
51
|
-
|
52
|
-
before
|
53
|
-
|
60
|
+
context 'when URL is encoded' do
|
61
|
+
before do
|
62
|
+
request.stub(fullpath: '/full%20with%20spaces?param=true',
|
63
|
+
path: '/full%20with%20spaces')
|
54
64
|
end
|
55
65
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
it_behaves_like 'detecting current page', '/full%20with%20spaces?param=true', true
|
67
|
+
it_behaves_like 'detecting current page', '/full%20with%20spaces?param3=true', false
|
68
|
+
it_behaves_like 'detecting current page', '/full%20with%20spaces', true
|
69
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces?param=true', true
|
70
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces?param3=true', false
|
71
|
+
it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces', true
|
72
|
+
it_behaves_like 'detecting current page', 'https://my_host:5000/full%20with%20spaces', false
|
73
|
+
it_behaves_like 'detecting current page', 'http://my_host:6000/full%20with%20spaces', false
|
74
|
+
it_behaves_like 'detecting current page', 'http://my_other_host:5000/full%20with%20spaces', false
|
65
75
|
end
|
66
76
|
end
|
67
77
|
|
68
|
-
describe 'link_to' do
|
69
|
-
it
|
70
|
-
|
78
|
+
describe '#link_to' do
|
79
|
+
it 'returns a link with the correct class and id' do
|
80
|
+
link = adapter.link_to('link', 'url', class: 'clazz', id: 'id')
|
81
|
+
expect(link).to eq "<a href='url' class='clazz' id='id'>link</a>"
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
74
|
-
describe 'content_tag' do
|
75
|
-
it
|
76
|
-
|
85
|
+
describe '#content_tag' do
|
86
|
+
it 'returns a tag with the correct class and id' do
|
87
|
+
tag = adapter.content_tag(:div, 'content', class: 'clazz', id: 'id')
|
88
|
+
expect(tag).to eq "<div class='clazz' id='id'>content</div>"
|
77
89
|
end
|
78
90
|
end
|
79
|
-
|
80
|
-
end
|
91
|
+
end
|
@@ -1,128 +1,150 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
describe Configuration do
|
5
|
+
subject(:config) { Configuration.instance }
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
describe 'self.run' do
|
10
|
-
it "should yield the singleton Configuration object" do
|
11
|
-
SimpleNavigation::Configuration.run do |c|
|
12
|
-
c.should == @config
|
7
|
+
describe '.run' do
|
8
|
+
it "yields the singleton Configuration object" do
|
9
|
+
expect{ |blk| Configuration.run(&blk) }.to yield_with_args(config)
|
13
10
|
end
|
14
11
|
end
|
15
|
-
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@context.stub!(:instance_eval)
|
21
|
-
SimpleNavigation.stub!(:context_for_eval => @context)
|
22
|
-
@config_files = {:default => 'default', :my_context => 'my_context'}
|
23
|
-
SimpleNavigation.stub!(:config_files).and_return(@config_files)
|
24
|
-
end
|
25
|
-
context "with default navigation context" do
|
26
|
-
it "should instance_eval the default config_file-string inside the context" do
|
27
|
-
@context.should_receive(:instance_eval).with('default')
|
28
|
-
SimpleNavigation::Configuration.eval_config
|
29
|
-
end
|
30
|
-
end
|
31
|
-
context 'with non default navigation context' do
|
32
|
-
it "should instance_eval the specified config_file-string inside the context" do
|
33
|
-
@context.should_receive(:instance_eval).with('my_context')
|
34
|
-
SimpleNavigation::Configuration.eval_config(:my_context)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
13
|
+
describe '.eval_config' do
|
14
|
+
let(:config_files) {{ default: 'default', my_context: 'my_context' }}
|
15
|
+
let(:eval_context) { double(:eval_context) }
|
38
16
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
it "should set the selected_class to 'selected' as default" do
|
44
|
-
@config.selected_class.should == 'selected'
|
45
|
-
end
|
46
|
-
it "should set the active_leaf_class to 'simple-navigation-active-leaf' as default" do
|
47
|
-
@config.active_leaf_class.should == 'simple-navigation-active-leaf'
|
48
|
-
end
|
49
|
-
it "should set autogenerate_item_ids to true as default" do
|
50
|
-
@config.autogenerate_item_ids.should be_true
|
51
|
-
end
|
52
|
-
it "should set auto_highlight to true as default" do
|
53
|
-
@config.auto_highlight.should be_true
|
54
|
-
end
|
55
|
-
it "should set the id_generator" do
|
56
|
-
@config.id_generator.should_not be_nil
|
57
|
-
end
|
58
|
-
it "should set the name_generator" do
|
59
|
-
@config.name_generator.should_not be_nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
describe 'items' do
|
63
|
-
before(:each) do
|
64
|
-
@container = stub(:items_container)
|
65
|
-
SimpleNavigation::ItemContainer.stub!(:new).and_return(@container)
|
66
|
-
end
|
67
|
-
context 'block given' do
|
68
|
-
context 'items_provider specified' do
|
69
|
-
it {lambda {@config.items(stub(:provider)) {}}.should raise_error}
|
17
|
+
before do
|
18
|
+
eval_context.stub(:instance_eval)
|
19
|
+
SimpleNavigation.stub(context_for_eval: eval_context,
|
20
|
+
config_files: config_files)
|
70
21
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
it "should assign the ItemContainer to an instance-var" do
|
78
|
-
@config.items {}
|
79
|
-
@config.primary_navigation.should == @container
|
22
|
+
|
23
|
+
context "with default navigation context" do
|
24
|
+
it "should instance_eval the default config_file-string inside the context" do
|
25
|
+
expect(eval_context).to receive(:instance_eval).with('default')
|
26
|
+
Configuration.eval_config
|
80
27
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with non default navigation context' do
|
31
|
+
it "should instance_eval the specified config_file-string inside the context" do
|
32
|
+
expect(eval_context).to receive(:instance_eval).with('my_context')
|
33
|
+
Configuration.eval_config(:my_context)
|
84
34
|
end
|
85
35
|
end
|
86
36
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
37
|
+
|
38
|
+
describe '#initialize' do
|
39
|
+
it 'sets the List-Renderer as default' do
|
40
|
+
expect(config.renderer).to be Renderer::List
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets the selected_class to "selected" as default' do
|
44
|
+
expect(config.selected_class).to eq 'selected'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the active_leaf_class to "simple-navigation-active-leaf" as default' do
|
48
|
+
expect(config.active_leaf_class).to eq 'simple-navigation-active-leaf'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets autogenerate_item_ids to true as default' do
|
52
|
+
expect(config.autogenerate_item_ids).to be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'sets auto_highlight to true as default' do
|
56
|
+
expect(config.auto_highlight).to be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should set the id_generator' do
|
60
|
+
expect(config.id_generator).not_to be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should set the name_generator' do
|
64
|
+
expect(config.name_generator).not_to be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#items' do
|
69
|
+
let(:container) { double(:items_container) }
|
70
|
+
|
71
|
+
before { ItemContainer.stub(:new).and_return(container) }
|
72
|
+
|
73
|
+
context 'when a block is given' do
|
74
|
+
context 'and items_provider is specified' do
|
75
|
+
let(:provider) { double(:provider) }
|
76
|
+
|
77
|
+
it 'raises an exception' do
|
78
|
+
expect{ config.items(provider) {} }.to raise_error
|
79
|
+
end
|
95
80
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
81
|
+
|
82
|
+
context 'when no items_provider is specified' do
|
83
|
+
it 'yields an new ItemContainer' do
|
84
|
+
expect{ |blk| config.items(&blk) }.to yield_with_args(container)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'assigns the ItemContainer to an instance-var' do
|
88
|
+
config.items {}
|
89
|
+
expect(config.primary_navigation).to be container
|
90
|
+
end
|
91
|
+
|
92
|
+
it "doesn't set the items on the container" do
|
93
|
+
expect(container).not_to receive(:items=)
|
94
|
+
config.items {}
|
95
|
+
end
|
99
96
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when no block is given' do
|
100
|
+
context 'and items_provider is specified' do
|
101
|
+
let(:external_provider) { double(:external_provider) }
|
102
|
+
let(:items) { double(:items) }
|
103
|
+
let(:items_provider) { double(:items_provider, items: items) }
|
104
|
+
|
105
|
+
before do
|
106
|
+
SimpleNavigation::ItemsProvider.stub(new: items_provider)
|
107
|
+
container.stub(:items=)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'creates a new Provider object for the specified provider' do
|
111
|
+
expect(ItemsProvider).to receive(:new).with(external_provider)
|
112
|
+
config.items(external_provider)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'calls items on the provider object' do
|
116
|
+
expect(items_provider).to receive(:items)
|
117
|
+
config.items(external_provider)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'sets the items on the container' do
|
121
|
+
expect(container).to receive(:items=).with(items)
|
122
|
+
config.items(external_provider)
|
123
|
+
end
|
103
124
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
125
|
+
|
126
|
+
context 'when items_provider is not specified' do
|
127
|
+
it "raises an exception" do
|
128
|
+
expect{ config.items }.to raise_error
|
129
|
+
end
|
107
130
|
end
|
108
131
|
end
|
109
|
-
context 'items_provider not specified' do
|
110
|
-
it {lambda {@config.items}.should raise_error}
|
111
|
-
end
|
112
132
|
end
|
113
|
-
end
|
114
133
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
describe '#loaded?' do
|
135
|
+
context 'when primary_nav is set' do
|
136
|
+
it 'returns true' do
|
137
|
+
config.instance_variable_set(:@primary_navigation, :bla)
|
138
|
+
expect(config).to be_loaded
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when primary_nav is not set' do
|
143
|
+
it "should return false if no primary_nav is set" do
|
144
|
+
config.instance_variable_set(:@primary_navigation, nil)
|
145
|
+
expect(config).not_to be_loaded
|
146
|
+
end
|
147
|
+
end
|
123
148
|
end
|
124
149
|
end
|
125
|
-
|
126
150
|
end
|
127
|
-
|
128
|
-
|