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,48 +1,69 @@
1
1
  require 'spec_helper'
2
+ require 'json_spec'
2
3
 
3
- describe SimpleNavigation::Renderer::Json do
4
+ RSpec.configure { |config| config.include JsonSpec::Helpers }
4
5
 
5
- describe 'render' do
6
+ module SimpleNavigation
7
+ module Renderer
8
+ describe Json do
9
+ describe '#render' do
10
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
6
11
 
7
- def render(current_nav=nil, options={})
8
- primary_navigation = primary_container
9
- select_item(current_nav)
10
- setup_renderer_for SimpleNavigation::Renderer::Json, :rails, options
11
- @renderer.render(primary_navigation)
12
- end
12
+ let(:item) { :invoices }
13
+ let(:options) {{ level: :all }}
14
+ let(:output) { renderer.render(navigation) }
15
+ let(:parsed_output) { parse_json(output) }
16
+ let(:renderer) { setup_renderer(Json, options) }
13
17
 
14
- def prerendered_menu
15
- '[{"name":"users","url":"first_url","selected":false,"items":null},{"name":"invoices","url":"second_url","selected":true,"items":[{"name":"subnav1","url":"subnav1_url","selected":false,"items":null},{"name":"subnav2","url":"subnav2_url","selected":false,"items":null}]},{"name":"accounts","url":"third_url","selected":false,"items":null},{"name":"miscellany","url":null,"selected":false,"items":null}]'
16
- end
18
+ before { select_an_item(navigation[item]) if item }
17
19
 
18
- context 'regarding result' do
20
+ context 'when an item is selected' do
19
21
 
20
- it "should return a string" do
21
- render(:invoices).class.should == String
22
- end
22
+ it 'renders the selected page' do
23
+ invoices_item = parsed_output.find { |item| item['name'] == 'Invoices' }
24
+ expect(invoices_item).to include('selected' => true)
25
+ end
26
+ end
27
+
28
+ # FIXME: not sure if :as_hash returning an array makes sense...
29
+ context 'when the :as_hash option is true' do
30
+ let(:options) {{ level: :all, as_hash: true }}
31
+
32
+ it 'returns a hash' do
33
+ expect(output).to be_an Array
34
+ end
23
35
 
24
- it "should render the selected page" do
25
- json = parse_json(render(:invoices))
26
- found = json.any? do |item|
27
- item["name"] == "invoices" and item["selected"]
36
+ it 'renders the selected page' do
37
+ invoices_item = output.find { |item| item[:name] == 'Invoices' }
38
+ expect(invoices_item).to include(selected: true)
39
+ end
28
40
  end
29
- found.should == true
30
- end
31
41
 
32
- end
42
+ context 'when a sub navigation item is selected' do
43
+ let(:invoices_item) do
44
+ parsed_output.find { |item| item['name'] == 'Invoices' }
45
+ end
46
+ let(:unpaid_item) do
47
+ invoices_item['items'].find { |item| item['name'] == 'Unpaid' }
48
+ end
33
49
 
34
- context 'regarding hash result' do
35
- it "should return a hash" do
36
- render(:invoices, :as_hash => true).class.should == Array
37
- end
50
+ before do
51
+ navigation[:invoices].stub(selected?: true)
38
52
 
39
- it "should render the selected page" do
40
- found = render(:invoices, :as_hash => true).any? do |item|
41
- item[:name] == "invoices" and item[:selected]
53
+ navigation[:invoices]
54
+ .sub_navigation[:unpaid]
55
+ .stub(selected?: true, selected_by_condition?: true)
56
+ end
57
+
58
+ it 'marks all the parent items as selected' do
59
+ expect(invoices_item).to include('selected' => true)
60
+ end
61
+
62
+ it 'marks the item as selected' do
63
+ expect(unpaid_item).to include('selected' => true)
64
+ end
42
65
  end
43
- found.should == true
44
66
  end
45
-
46
67
  end
47
68
  end
48
69
  end
@@ -1,64 +1,91 @@
1
1
  require 'spec_helper'
2
- require 'html/document' unless defined? HTML::Document
3
2
 
4
- describe SimpleNavigation::Renderer::Links do
3
+ module SimpleNavigation
4
+ module Renderer
5
+ describe Links do
6
+ describe '#render' do
7
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
5
8
 
6
-
7
- describe 'render' do
9
+ let(:item) { nil }
10
+ let(:options) {{ level: :all }}
11
+ let(:output) { HTML::Document.new(raw_output).root }
12
+ let(:raw_output) { renderer.render(navigation) }
13
+ let(:renderer) { setup_renderer(Links, options) }
8
14
 
9
- def render(current_nav=nil, options={:level => :all})
10
- primary_navigation = primary_container
11
- select_item(current_nav) if current_nav
12
- setup_renderer_for SimpleNavigation::Renderer::Links, :rails, options
13
- HTML::Document.new(@renderer.render(primary_navigation)).root
14
- end
15
+ before { select_an_item(navigation[item]) if item }
15
16
 
16
- context 'regarding result' do
17
+ it "renders a 'div' tag for the navigation" do
18
+ expect(output).to have_css('div')
19
+ end
17
20
 
18
- it "should render a div-tag around the items" do
19
- HTML::Selector.new('div').select(render).should have(1).entries
20
- end
21
- it "the rendered div-tag should have the specified dom_id" do
22
- HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
23
- end
24
- it "the rendered div-tag should have the specified class" do
25
- HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
26
- end
27
- it "should render an a-tag for each item" do
28
- HTML::Selector.new('a').select(render).should have(3).entries
29
- end
30
- it "should pass the specified html_options to the a element" do
31
- HTML::Selector.new('a[style=float:right]').select(render).should have(1).entries
32
- end
33
- it "should give the a-tag the id specified in the html_options" do
34
- HTML::Selector.new('a#my_id').select(render).should have(1).entries
35
- end
36
- it "should give the a-tag the default id (stringified key) if no id is specified in the html_options" do
37
- HTML::Selector.new('a#invoices').select(render).should have(1).entries
38
- end
39
- it "should not apply the the default id where there is an id specified in the html_options" do
40
- HTML::Selector.new('a#users').select(render).should be_empty
41
- end
21
+ it "sets the right html id on the rendered 'div' tag" do
22
+ expect(output).to have_css('div#nav_id')
23
+ end
42
24
 
43
- context 'with current_navigation set' do
44
- it "should mark the matching a-item as selected (with the css_class specified in configuration)" do
45
- HTML::Selector.new('a.selected').select(render(:invoices)).should have(1).entries
25
+ it "sets the right html classes on the rendered 'div' tag" do
26
+ expect(output).to have_css('div.nav_class')
46
27
  end
47
- end
48
28
 
49
- context 'without current_navigation set' do
50
- it "should not mark any of the items as selected" do
51
- HTML::Selector.new('a.selected').select(render).should be_empty
29
+ it "renders an 'a' tag for each item" do
30
+ expect(output).to have_css('a', 3)
52
31
  end
53
- end
54
32
 
55
- context 'with a custom seperator specified' do
56
- it "should separate the items with the separator" do
57
- HTML::Selector.new('div').select_first(render(:subnav1, :join_with => " | ")).to_s.split(" | ").should have(4).entries
33
+ it "renders the 'a' tags with the corresponding item's :html_options" do
34
+ expect(output).to have_css('a[style=float:right]')
35
+ end
36
+
37
+ context 'when an item has a specified id' do
38
+ it "renders the 'a' tags with the specified id" do
39
+ expect(output).to have_css('a#users_id')
40
+ end
41
+ end
42
+
43
+ context 'when an item has no specified id' do
44
+ it "uses a default id by stringifying the item's key" do
45
+ expect(output).to have_css('a#invoices')
46
+ end
47
+ end
48
+
49
+ context 'when no item is selected' do
50
+ it "renders items without the 'selected' class" do
51
+ expect(output).not_to have_css('a.selected')
52
+ end
53
+ end
54
+
55
+ context 'when an item is selected' do
56
+ let(:item) { :invoices }
57
+
58
+ it "renders the selected item with the 'selected' class" do
59
+ expect(output).to have_css('a#invoices.selected')
60
+ end
61
+ end
62
+
63
+ context "when the :join_with option is set" do
64
+ let(:options) {{ level: :all, join_with: ' | ' }}
65
+
66
+ it 'separates the items with the specified separator' do
67
+ expect(raw_output.scan(' | ')).to have(3).items
68
+ end
69
+ end
70
+
71
+ context 'when a sub navigation item is selected' do
72
+ before do
73
+ navigation[:invoices].stub(selected?: true)
74
+
75
+ navigation[:invoices]
76
+ .sub_navigation[:unpaid]
77
+ .stub(selected?: true, selected_by_condition?: true)
78
+ end
79
+
80
+ it 'renders the main parent as selected' do
81
+ expect(output).to have_css('a#invoices.selected')
82
+ end
83
+
84
+ it "doesn't render the nested item's link" do
85
+ expect(output).not_to have_css('a#unpaid')
86
+ end
58
87
  end
59
88
  end
60
-
61
89
  end
62
-
63
90
  end
64
91
  end
@@ -1,211 +1,99 @@
1
1
  require 'spec_helper'
2
- require 'html/document' unless defined? HTML::Document
3
2
 
4
- describe SimpleNavigation::Renderer::List do
3
+ module SimpleNavigation
4
+ module Renderer
5
+ describe List do
6
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
5
7
 
6
- describe 'render' do
8
+ let(:item) { nil }
9
+ let(:options) {{ level: :all }}
10
+ let(:output) { HTML::Document.new(raw_output).root }
11
+ let(:raw_output) { renderer.render(navigation) }
12
+ let(:renderer) { setup_renderer(List, options) }
7
13
 
8
- def render(current_nav=nil, options={:level => :all})
9
- primary_navigation = primary_container
10
- select_item(current_nav) if current_nav
11
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
12
- HTML::Document.new(@renderer.render(primary_navigation)).root
13
- end
14
+ before { select_an_item(navigation[item]) if item }
14
15
 
15
- context 'regarding result' do
16
+ describe '#render' do
17
+ it "renders an 'ul' tag for the navigation" do
18
+ expect(output).to have_css('ul')
19
+ end
16
20
 
17
- it "should render a ul-tag around the items" do
18
- HTML::Selector.new('ul').select(render).should have(1).entries
19
- end
20
- it "the rendered ul-tag should have the specified dom_id" do
21
- HTML::Selector.new('ul#nav_dom_id').select(render).should have(1).entries
22
- end
23
- it "the rendered ul-tag should have the specified class" do
24
- HTML::Selector.new('ul.nav_dom_class').select(render).should have(1).entries
25
- end
26
- it "should render a li tag for each item" do
27
- HTML::Selector.new('li').select(render).should have(4).entries
28
- end
29
- it "should render an a-tag inside each li-tag (for items with links)" do
30
- HTML::Selector.new('li a').select(render).should have(3).entries
31
- end
32
- it "should render a span-tag inside each li-tag (for items without links)" do
33
- HTML::Selector.new('li span').select(render).should have(1).entries
34
- end
21
+ it "sets the right html id on the rendered 'ul' tag" do
22
+ expect(output).to have_css('ul#nav_id')
23
+ end
35
24
 
36
- context 'concerning item names' do
37
- context 'with a custom name generator defined' do
38
- before(:each) do
39
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
40
- end
41
- it "should apply the name generator" do
42
- HTML::Selector.new('li a span').select(render).should have(3).entries
43
- end
25
+ it "sets the right html classes on the rendered 'ul' tag" do
26
+ expect(output).to have_css('ul.nav_class')
44
27
  end
45
- context 'no customer generator defined' do
46
- before(:each) do
47
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "name"})
48
- end
49
- it "should apply the name generator" do
50
- HTML::Selector.new('li a span').select(render).should have(0).entries
28
+
29
+ context 'when an item has no specified id' do
30
+ it "renders the item's 'li' tag with the item's stingified key as id" do
31
+ expect(output).to have_css('li#invoices')
51
32
  end
52
33
  end
53
- end
54
34
 
55
- context 'concerning html attributes' do
56
- context 'default case (no options defined for link tag)' do
57
- it "should pass the specified html_options to the li element" do
58
- HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
59
- end
60
- it "should give the li the id specified in the html_options" do
61
- HTML::Selector.new('li#my_id').select(render).should have(1).entries
62
- end
63
- it "should give the li the default id (stringified key) if no id is specified in the html_options" do
64
- HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
65
- end
66
- it "should not apply the the default id where there is an id specified in the html_options" do
67
- HTML::Selector.new('ul li#users').select(render).should be_empty
35
+ context 'when an item has a specified id' do
36
+ it "renders the item's 'li' tag with the specified id" do
37
+ expect(output).to have_css('li#users_id')
68
38
  end
69
39
  end
70
- context 'with attributes defined for the link tag as well' do
71
- it "should add the link attributes to the link" do
72
- HTML::Selector.new('a[style=float:left]').select(render).should have(1).entries
73
- end
74
- it "should add the li attributes to the li element" do
75
- HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
76
- end
77
- it "should give the li the default id (stringified key) if no id is specified in the html_options for the li-element" do
78
- HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
40
+
41
+ context 'when no item is selected' do
42
+ it "renders each item as 'li' tag without any selected class" do
43
+ expect(output).not_to have_css('ul li.selected')
79
44
  end
80
- it "should not apply the the default id where there is an id specified in the html_options for th li-element" do
81
- HTML::Selector.new('ul li#users').select(render).should be_empty
45
+
46
+ it "renders each item as 'a' tag without any selected class" do
47
+ expect(output).not_to have_css('ul li a.selected')
82
48
  end
83
49
  end
84
- end
85
-
86
- context 'with current_navigation set' do
87
- it "should mark the matching li-item as selected (with the css_class specified in configuration)" do
88
- HTML::Selector.new('li.selected').select(render(:invoices)).should have(1).entries
89
- end
90
- it "should also mark the links inside the selected li's as selected" do
91
- HTML::Selector.new('li.selected a.selected').select(render(:invoices)).should have(1).entries
92
- end
93
- end
94
50
 
95
- context 'without current_navigation set' do
96
- it "should not mark any of the items as selected" do
97
- HTML::Selector.new('li.selected').select(render).should be_empty
98
- end
99
- it "should not mark any links as selected" do
100
- HTML::Selector.new('a.selected').select(render).should be_empty
101
- end
102
- end
51
+ context 'when an item is selected' do
52
+ let(:item) { :invoices }
103
53
 
104
- context 'nested sub_navigation' do
105
- it "should nest the current_primary's subnavigation inside the selected li-element" do
106
- HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
107
- end
108
- it "should be possible to identify sub items using an html selector (using ids)" do
109
- HTML::Selector.new('#invoices #subnav1').select(render(:invoices)).should have(1).entries
110
- end
111
- context 'expand_all => false' do
112
- it "should not render the invoices submenu if the user-primary is active" do
113
- HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => false)).should be_empty
114
- HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
54
+ it "renders the item's 'li' tag with its id and selected classes" do
55
+ expect(output).to have_css('li#invoices.selected')
115
56
  end
116
- end
117
57
 
118
- context 'expand_all => true' do
119
- it "should render the invoices submenu even if the user-primary is active" do
120
- HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
121
- HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
58
+ it "renders the item's 'a' tag with the selected classes" do
59
+ expect(output).to have_css('li#invoices a.selected')
122
60
  end
123
61
  end
124
62
 
125
- end
63
+ context 'when the :ordered option is true' do
64
+ let(:options) {{ level: :all, ordered: true }}
126
65
 
127
- context 'skip_if_empty' do
128
-
129
- def render_container(options={})
130
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
131
- HTML::Document.new(@renderer.render(@container)).root
132
- end
133
-
134
- context 'container is empty' do
135
- before(:each) do
136
- @container = SimpleNavigation::ItemContainer.new(0)
66
+ it "renders an 'ol' tag for the navigation" do
67
+ expect(output).to have_css('ol')
137
68
  end
138
- context 'skip_if_empty is true' do
139
- it "should not render a ul tag for the empty container" do
140
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should be_empty
141
- end
142
- end
143
- context 'skip_if_empty is false' do
144
- it "should render a ul tag for the empty container" do
145
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
146
- end
147
- end
148
- end
149
69
 
150
- context 'container is not empty' do
151
- before(:each) do
152
- @container = primary_container
70
+ it "sets the right html id on the rendered 'ol' tag" do
71
+ expect(output).to have_css('ol#nav_id')
153
72
  end
154
- context 'skip_if_empty is true' do
155
- it "should render a ul tag for the container" do
156
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should have(1).entry
157
- end
158
- end
159
- context 'skip_if_empty is false' do
160
- it "should render a ul tag for the container" do
161
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
162
- end
73
+
74
+ it "sets the right html classes on the rendered 'ol' tag" do
75
+ expect(output).to have_css('ol.nav_class')
163
76
  end
164
77
  end
165
- end
166
- end
167
-
168
- describe 'link_options_for' do
169
- before(:each) do
170
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, {}
171
- end
172
- context 'no link options specified' do
173
- context 'method specified' do
174
- context 'item selected' do
175
- before(:each) do
176
- @item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {})
177
- end
178
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'selected'}}
78
+
79
+ context 'when a sub navigation item is selected' do
80
+ before do
81
+ navigation[:invoices].stub(selected?: true)
82
+
83
+ navigation[:invoices]
84
+ .sub_navigation[:unpaid]
85
+ .stub(selected?: true, selected_by_condition?: true)
179
86
  end
180
- context 'item not selected' do
181
- before(:each) do
182
- @item = stub(:item, :method => :delete, :selected_class => nil, :html_options => {})
183
- end
184
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete}}
87
+
88
+ it 'renders the parent items as selected' do
89
+ expect(output).to have_css('li#invoices.selected')
185
90
  end
186
- end
187
- context 'method not specified' do
188
- context 'item selected' do
189
- before(:each) do
190
- @item = stub(:item, :method => nil, :selected_class => 'selected', :html_options => {})
191
- end
192
- it {@renderer.send(:link_options_for, @item).should == {:class => 'selected'}}
91
+
92
+ it "renders the selected nested item's link as selected" do
93
+ expect(output).to have_css('li#unpaid.selected')
193
94
  end
194
- context 'item not selected' do
195
- before(:each) do
196
- @item = stub(:item, :method => nil, :selected_class => nil, :html_options => {})
197
- end
198
- it {@renderer.send(:link_options_for, @item).should == {}}
199
- end
200
- end
201
- end
202
- context 'link options specified' do
203
- before(:each) do
204
- @item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {:link => {:class => 'link_class', :style => 'float:left'}})
205
95
  end
206
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'link_class selected', :style => 'float:left'}}
207
96
  end
208
97
  end
209
-
210
98
  end
211
99
  end
@@ -1,39 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SimpleNavigation::Renderer::Text do
3
+ module SimpleNavigation
4
+ module Renderer
5
+ describe Text do
6
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
4
7
 
5
- describe 'render' do
8
+ let(:item) { nil }
9
+ let(:options) {{ level: :all }}
10
+ let(:output) { renderer.render(navigation) }
11
+ let(:renderer) { setup_renderer(Text, options) }
6
12
 
7
- def render(current_nav=nil, options={:level => :all})
8
- primary_navigation = primary_container
9
- select_item(current_nav)
10
- setup_renderer_for SimpleNavigation::Renderer::Text, :rails, options
11
- @renderer.render(primary_navigation)
12
- end
13
- context 'regarding result' do
14
-
15
- it "should render the selected page" do
16
- render(:invoices).should == "invoices"
17
- end
13
+ before { select_an_item(navigation[item]) if item }
18
14
 
19
- context 'nested sub_navigation' do
20
- it "should add an entry for each selected item" do
21
- render(:subnav1).should == "invoices subnav1"
15
+ describe '#render' do
16
+ context 'when no item is selected' do
17
+ it 'renders an empty string' do
18
+ expect(output).to eq ''
19
+ end
22
20
  end
23
- end
24
21
 
25
- context 'with a custom seperator specified' do
26
- it "should separate the items with the separator" do
27
- render(:subnav1, :join_with => " | ").should == "invoices | subnav1"
28
- end
29
- end
30
-
31
- context 'custom name generator is set' do
32
- before(:each) do
33
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
22
+ context 'when an item is selected' do
23
+ let(:item) { :invoices }
24
+
25
+ it "renders the selected item's name" do
26
+ expect(output).to eq 'Invoices'
27
+ end
34
28
  end
35
- it "should not apply the name generator (since it is text only)" do
36
- render(:subnav1, :join_with => " | ").should == "invoices | subnav1"
29
+
30
+ context 'when a sub navigation item is selected' do
31
+ before do
32
+ navigation[:invoices].stub(selected?: true)
33
+
34
+ navigation[:invoices]
35
+ .sub_navigation[:unpaid]
36
+ .stub(selected?: true, selected_by_condition?: true)
37
+ end
38
+
39
+ it 'separates the items with a space' do
40
+ expect(output).to eq 'Invoices Unpaid'
41
+ end
42
+
43
+ context "and the :join_with option is set" do
44
+ let(:options) {{ level: :all, join_with: ' | ' }}
45
+
46
+ it 'separates the items with the specified separator' do
47
+ expect(output).to eq 'Invoices | Unpaid'
48
+ end
49
+ end
37
50
  end
38
51
  end
39
52
  end