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.
Files changed (46) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG +11 -0
  5. data/Gemfile +2 -16
  6. data/Guardfile +5 -0
  7. data/LICENSE +22 -0
  8. data/README.md +40 -0
  9. data/Rakefile +6 -39
  10. data/generators/navigation_config/templates/config/navigation.rb +7 -5
  11. data/init.rb +1 -0
  12. data/install.rb +5 -0
  13. data/lib/simple_navigation/adapters/rails.rb +5 -1
  14. data/lib/simple_navigation/core/configuration.rb +5 -1
  15. data/lib/simple_navigation/core/item.rb +2 -1
  16. data/lib/simple_navigation/core/item_adapter.rb +4 -4
  17. data/lib/simple_navigation/core/item_container.rb +6 -1
  18. data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
  19. data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
  20. data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
  21. data/lib/simple_navigation/version.rb +3 -0
  22. data/lib/simple_navigation.rb +1 -0
  23. data/simple-navigation.gemspec +40 -0
  24. data/spec/initializers/have_css_matcher.rb +13 -0
  25. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
  26. data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
  27. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
  28. data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
  29. data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
  30. data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
  31. data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
  32. data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
  33. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
  34. data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
  35. data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
  36. data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
  37. data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
  38. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
  39. data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
  40. data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
  41. data/spec/lib/simple_navigation_spec.rb +207 -225
  42. data/spec/spec_helper.rb +53 -82
  43. data/uninstall.rb +1 -0
  44. metadata +100 -22
  45. data/README +0 -22
  46. 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
- def create_adapter
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
- it "should raise error if no context" do
18
- @adapter.stub!(:context => nil)
19
- lambda {@adapter.context_for_eval}.should raise_error
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
- it "should return the context" do
22
- @adapter.context_for_eval.should == @context
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 {@adapter.request_uri.should == '/full?param=true'}
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 {@adapter.request_path.should == '/full'}
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(:each) do
36
- @request.stub!(:scheme => 'http', :host_with_port => 'my_host:5000')
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
- describe 'when URL is not encoded' do
40
- it {@adapter.current_page?('/full?param=true').should be_true}
41
- it {@adapter.current_page?('/full?param3=true').should be_false}
42
- it {@adapter.current_page?('/full').should be_true}
43
- it {@adapter.current_page?('http://my_host:5000/full?param=true').should be_true}
44
- it {@adapter.current_page?('http://my_host:5000/full?param3=true').should be_false}
45
- it {@adapter.current_page?('http://my_host:5000/full').should be_true}
46
- it {@adapter.current_page?('https://my_host:5000/full').should be_false}
47
- it {@adapter.current_page?('http://my_host:6000/full').should be_false}
48
- it {@adapter.current_page?('http://my_other_host:5000/full').should be_false}
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
- describe 'when URL is encoded' do
52
- before(:each) do
53
- @request.stub!(:fullpath => '/full%20with%20spaces?param=true', :path => '/full%20with%20spaces')
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
- it {@adapter.current_page?('/full%20with%20spaces?param=true').should be_true}
57
- it {@adapter.current_page?('/full%20with%20spaces?param3=true').should be_false}
58
- it {@adapter.current_page?('/full%20with%20spaces').should be_true}
59
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param=true').should be_true}
60
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param3=true').should be_false}
61
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces').should be_true}
62
- it {@adapter.current_page?('https://my_host:5000/full%20with%20spaces').should be_false}
63
- it {@adapter.current_page?('http://my_host:6000/full%20with%20spaces').should be_false}
64
- it {@adapter.current_page?('http://my_other_host:5000/full%20with%20spaces').should be_false}
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 "should return a link" do
70
- @adapter.link_to('link', 'url', :class => 'clazz', :id => 'id').should == "<a href='url' class='clazz' id='id'>link</a>"
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 "should return a tag" do
76
- @adapter.content_tag(:div, 'content', :class => 'clazz', :id => 'id').should == "<div class='clazz' id='id'>content</div>"
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
- describe SimpleNavigation::Configuration do
3
+ module SimpleNavigation
4
+ describe Configuration do
5
+ subject(:config) { Configuration.instance }
4
6
 
5
- before(:each) do
6
- @config = SimpleNavigation::Configuration.instance
7
- end
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
- describe 'self.eval_config' do
18
- before(:each) do
19
- @context = mock(:context)
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
- describe 'initialize' do
40
- it "should set the List-Renderer as default upon initialize" do
41
- @config.renderer.should == SimpleNavigation::Renderer::List
42
- end
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
- context 'no items_provider specified' do
72
- it "should should yield an new ItemContainer" do
73
- @config.items do |container|
74
- container.should == @container
75
- end
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
- it "should not set the items on the container" do
82
- @container.should_not_receive(:items=)
83
- @config.items {}
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
- context 'no block given' do
88
- context 'items_provider specified' do
89
- before(:each) do
90
- @external_provider = stub(:external_provider)
91
- @items = stub(:items)
92
- @items_provider = stub(:items_provider, :items => @items)
93
- SimpleNavigation::ItemsProvider.stub!(:new => @items_provider)
94
- @container.stub!(:items=)
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
- it "should create an new Provider object for the specified provider" do
97
- SimpleNavigation::ItemsProvider.should_receive(:new).with(@external_provider)
98
- @config.items(@external_provider)
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
- it "should call items on the provider object" do
101
- @items_provider.should_receive(:items)
102
- @config.items(@external_provider)
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
- it "should set the items on the container" do
105
- @container.should_receive(:items=).with(@items)
106
- @config.items(@external_provider)
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
- describe 'loaded?' do
116
- it "should return true if primary_nav is set" do
117
- @config.instance_variable_set(:@primary_navigation, :bla)
118
- @config.should be_loaded
119
- end
120
- it "should return false if no primary_nav is set" do
121
- @config.instance_variable_set(:@primary_navigation, nil)
122
- @config.should_not be_loaded
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
-