simple-navigation-ext 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG +177 -0
  2. data/README +22 -0
  3. data/Rakefile +48 -0
  4. data/VERSION +1 -0
  5. data/generators/navigation_config/USAGE +1 -0
  6. data/generators/navigation_config/navigation_config_generator.rb +8 -0
  7. data/generators/navigation_config/templates/config/navigation.rb +67 -0
  8. data/lib/generators/navigation_config/navigation_config_generator.rb +12 -0
  9. data/lib/simple-navigation.rb +1 -0
  10. data/lib/simple_navigation/adapters/base.rb +37 -0
  11. data/lib/simple_navigation/adapters/padrino.rb +20 -0
  12. data/lib/simple_navigation/adapters/rails.rb +94 -0
  13. data/lib/simple_navigation/adapters/sinatra.rb +68 -0
  14. data/lib/simple_navigation/adapters.rb +9 -0
  15. data/lib/simple_navigation/core/configuration.rb +70 -0
  16. data/lib/simple_navigation/core/item.rb +117 -0
  17. data/lib/simple_navigation/core/item_adapter.rb +63 -0
  18. data/lib/simple_navigation/core/item_container.rb +146 -0
  19. data/lib/simple_navigation/core/items_provider.rb +35 -0
  20. data/lib/simple_navigation/core.rb +5 -0
  21. data/lib/simple_navigation/rails_controller_methods.rb +144 -0
  22. data/lib/simple_navigation/rendering/helpers.rb +82 -0
  23. data/lib/simple_navigation/rendering/renderer/base.rb +71 -0
  24. data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +37 -0
  25. data/lib/simple_navigation/rendering/renderer/links.rb +25 -0
  26. data/lib/simple_navigation/rendering/renderer/list.rb +47 -0
  27. data/lib/simple_navigation/rendering.rb +10 -0
  28. data/lib/simple_navigation.rb +162 -0
  29. data/rails/init.rb +1 -0
  30. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +29 -0
  31. data/spec/lib/simple_navigation/adapters/rails_spec.rb +284 -0
  32. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +60 -0
  33. data/spec/lib/simple_navigation/core/configuration_spec.rb +122 -0
  34. data/spec/lib/simple_navigation/core/item_adapter_spec.rb +209 -0
  35. data/spec/lib/simple_navigation/core/item_container_spec.rb +396 -0
  36. data/spec/lib/simple_navigation/core/item_spec.rb +513 -0
  37. data/spec/lib/simple_navigation/core/items_provider_spec.rb +60 -0
  38. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +249 -0
  39. data/spec/lib/simple_navigation/rendering/helpers_spec.rb +183 -0
  40. data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +199 -0
  41. data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +58 -0
  42. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +58 -0
  43. data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +189 -0
  44. data/spec/lib/simple_navigation_spec.rb +307 -0
  45. data/spec/spec_helper.rb +96 -0
  46. metadata +158 -0
@@ -0,0 +1,249 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'explicit navigation in rails' do
4
+ require 'simple_navigation/rails_controller_methods'
5
+
6
+ it 'should have enhanced the ActionController after loading the extensions' do
7
+ ActionController::Base.instance_methods.map {|m| m.to_s}.should include('current_navigation')
8
+ end
9
+
10
+ describe SimpleNavigation::ControllerMethods do
11
+
12
+ def stub_loading_config
13
+ SimpleNavigation::Configuration.stub!(:load)
14
+ end
15
+
16
+ before(:each) do
17
+ stub_loading_config
18
+ class TestController
19
+ class << self
20
+ def helper_method(*args)
21
+ @helper_methods = args
22
+ end
23
+ def before_filter(*args)
24
+ @before_filters = args
25
+ end
26
+ end
27
+ end
28
+ TestController.send(:include, SimpleNavigation::ControllerMethods)
29
+ @controller = TestController.new
30
+ end
31
+
32
+ describe 'when being included' do
33
+ it "should extend the ClassMethods" do
34
+ @controller.class.should respond_to(:navigation)
35
+ end
36
+ it "should include the InstanceMethods" do
37
+ @controller.should respond_to(:current_navigation)
38
+ end
39
+ end
40
+
41
+ describe 'class_methods' do
42
+
43
+ describe 'navigation' do
44
+
45
+ def call_navigation(key1, key2=nil)
46
+ @controller.class_eval do
47
+ navigation key1, key2
48
+ end
49
+ end
50
+
51
+ it "should not have an instance-method 'sn_set_navigation' if navigation-method has not been called" do
52
+ @controller.respond_to?(:sn_set_navigation).should be_false
53
+ end
54
+ it 'should create an instance-method "sn_set_navigation" when being called' do
55
+ call_navigation(:key)
56
+ @controller.respond_to?(:sn_set_navigation).should be_true
57
+ end
58
+ it "the created method should not be public" do
59
+ call_navigation(:key)
60
+ @controller.public_methods.map(&:to_sym).should_not include(:sn_set_navigation)
61
+ end
62
+ it "the created method should be protected" do
63
+ call_navigation(:key)
64
+ @controller.protected_methods.map(&:to_sym).should include(:sn_set_navigation)
65
+ end
66
+ it 'the created method should call current_navigation with the specified keys' do
67
+ call_navigation(:primary, :secondary)
68
+ @controller.should_receive(:current_navigation).with(:primary, :secondary)
69
+ @controller.send(:sn_set_navigation)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ describe 'instance_methods' do
76
+
77
+ describe 'current_navigation' do
78
+ it "should set the sn_current_navigation_args as specified" do
79
+ @controller.current_navigation(:first)
80
+ @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first]
81
+ end
82
+ it "should set the sn_current_navigation_args as specified" do
83
+ @controller.current_navigation(:first, :second)
84
+ @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first, :second]
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ describe 'SimpleNavigation module additions' do
93
+
94
+ describe 'handle_explicit_navigation' do
95
+ def args(*args)
96
+ SimpleNavigation.stub!(:explicit_navigation_args => args.compact.empty? ? nil : args)
97
+ end
98
+
99
+ before(:each) do
100
+ @controller = stub(:controller)
101
+ @adapter = stub(:adapter, :controller => @controller)
102
+ SimpleNavigation.stub!(:adapter => @adapter)
103
+ end
104
+
105
+ context 'with explicit navigation set' do
106
+ context 'list of navigations' do
107
+ before(:each) do
108
+ args :first, :second, :third
109
+ end
110
+ it "should set the correct instance var in the controller" do
111
+ @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_3, :third)
112
+ SimpleNavigation.handle_explicit_navigation
113
+ end
114
+ end
115
+ context 'single navigation' do
116
+ context 'specified key is a valid navigation item' do
117
+ before(:each) do
118
+ @primary = stub(:primary, :level_for_item => 2)
119
+ SimpleNavigation.stub!(:primary_navigation => @primary)
120
+ args :key
121
+ end
122
+ it "should set the correct instance var in the controller" do
123
+ @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
124
+ SimpleNavigation.handle_explicit_navigation
125
+ end
126
+ end
127
+ context 'specified key is an invalid navigation item' do
128
+ before(:each) do
129
+ @primary = stub(:primary, :level_for_item => nil)
130
+ SimpleNavigation.stub!(:primary_navigation => @primary)
131
+ args :key
132
+ end
133
+ it "should raise an ArgumentError" do
134
+ lambda {SimpleNavigation.handle_explicit_navigation}.should raise_error(ArgumentError)
135
+ end
136
+ end
137
+ end
138
+ context 'hash with level' do
139
+ before(:each) do
140
+ args :level_2 => :key
141
+ end
142
+ it "should set the correct instance var in the controller" do
143
+ @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
144
+ SimpleNavigation.handle_explicit_navigation
145
+ end
146
+ end
147
+ context 'hash with multiple_levels' do
148
+ before(:each) do
149
+ args :level_2 => :key, :level_1 => :bla
150
+ end
151
+ it "should set the correct instance var in the controller" do
152
+ @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
153
+ SimpleNavigation.handle_explicit_navigation
154
+ end
155
+ end
156
+ end
157
+ context 'without explicit navigation set' do
158
+ before(:each) do
159
+ args nil
160
+ end
161
+ it "should not set the current_navigation instance var in the controller" do
162
+ @controller.should_not_receive(:instance_variable_set)
163
+ SimpleNavigation.handle_explicit_navigation
164
+ end
165
+ end
166
+ end
167
+
168
+ describe 'current_navigation_for' do
169
+ before(:each) do
170
+ @controller = stub(:controller)
171
+ @adapter = stub(:adapter, :controller => @controller)
172
+ SimpleNavigation.stub!(:adapter => @adapter)
173
+ end
174
+ it "should access the correct instance_var in the controller" do
175
+ @controller.should_receive(:instance_variable_get).with(:@sn_current_navigation_1)
176
+ SimpleNavigation.current_navigation_for(1)
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ describe SimpleNavigation::Item do
183
+ before(:each) do
184
+ @item_container = stub(:item_container, :level => 1)
185
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
186
+
187
+ end
188
+ describe 'selected_by_config?' do
189
+ context 'navigation explicitly set' do
190
+ it "should return true if current matches key" do
191
+ SimpleNavigation.stub!(:current_navigation_for => :my_key)
192
+ @item.should be_selected_by_config
193
+ end
194
+ it "should return false if current does not match key" do
195
+ SimpleNavigation.stub!(:current_navigation_for => :other_key)
196
+ @item.should_not be_selected_by_config
197
+ end
198
+ end
199
+ context 'navigation not explicitly set' do
200
+ before(:each) do
201
+ SimpleNavigation.stub!(:current_navigation_for => nil)
202
+ end
203
+ it {@item.should_not be_selected_by_config}
204
+ end
205
+ end
206
+ end
207
+
208
+ describe SimpleNavigation::ItemContainer do
209
+ describe 'selected_item' do
210
+ before(:each) do
211
+ SimpleNavigation.stub!(:current_navigation_for)
212
+ @item_container = SimpleNavigation::ItemContainer.new
213
+
214
+ @item_1 = stub(:item, :selected? => false)
215
+ @item_2 = stub(:item, :selected? => false)
216
+ @item_container.instance_variable_set(:@items, [@item_1, @item_2])
217
+ end
218
+ context 'navigation explicitely set' do
219
+ before(:each) do
220
+ @item_container.stub!(:[] => @item_1)
221
+ end
222
+ it "should return the explicitely selected item" do
223
+ @item_container.selected_item.should == @item_1
224
+ end
225
+ end
226
+ context 'navigation not explicitely set' do
227
+ before(:each) do
228
+ @item_container.stub!(:[] => nil)
229
+ end
230
+ context 'no item selected' do
231
+ it "should return nil" do
232
+ @item_container.selected_item.should be_nil
233
+ end
234
+ end
235
+ context 'one item selected' do
236
+ before(:each) do
237
+ @item_1.stub!(:selected? => true)
238
+ end
239
+ it "should return the selected item" do
240
+ @item_container.selected_item.should == @item_1
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ end
247
+
248
+ end
249
+
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleNavigation::Helpers do
4
+ class ControllerMock
5
+ include SimpleNavigation::Helpers
6
+ end
7
+
8
+ def blackbox_setup()
9
+ @controller = ControllerMock.new
10
+ @controller.stub!(:load_config)
11
+ setup_adapter_for :rails
12
+ primary_navigation = primary_container
13
+ SimpleNavigation.stub!(:primary_navigation => primary_navigation)
14
+ end
15
+
16
+ def whitebox_setup
17
+ @controller = ControllerMock.new
18
+ SimpleNavigation.stub!(:load_config)
19
+ SimpleNavigation::Configuration.stub!(:eval_config)
20
+ @primary_navigation = stub(:primary_navigation).as_null_object
21
+ SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
22
+ SimpleNavigation.stub!(:config_file? => true)
23
+ end
24
+
25
+ describe 'active_navigation_item_name' do
26
+ before(:each) do
27
+ blackbox_setup
28
+ end
29
+ context 'active item_container for desired level exists' do
30
+ context 'container has selected item' do
31
+ before(:each) do
32
+ select_item(:subnav1)
33
+ end
34
+ it {@controller.active_navigation_item_name(:level => 2).should == 'subnav1'}
35
+ it {@controller.active_navigation_item_name.should == 'subnav1'}
36
+ it {@controller.active_navigation_item_name(:level => 1).should == 'invoices'}
37
+ it {@controller.active_navigation_item_name(:level => :all).should == 'subnav1'}
38
+ end
39
+ context 'container does not have selected item' do
40
+ it {@controller.active_navigation_item_name.should == ''}
41
+ end
42
+ end
43
+ context 'no active item_container for desired level' do
44
+ it {@controller.active_navigation_item_name(:level => 5).should == ''}
45
+ end
46
+ end
47
+
48
+ describe 'render_navigation' do
49
+
50
+ before(:each) do
51
+ whitebox_setup
52
+ end
53
+
54
+ describe 'regarding loading of the config-file' do
55
+ context 'no options specified' do
56
+ it "should load the config-file for the default context" do
57
+ SimpleNavigation.should_receive(:load_config).with(:default)
58
+ @controller.render_navigation
59
+ end
60
+ end
61
+
62
+ context 'with options specified' do
63
+ it "should load the config-file for the specified context" do
64
+ SimpleNavigation.should_receive(:load_config).with(:my_context)
65
+ @controller.render_navigation(:context => :my_context)
66
+ end
67
+ end
68
+ end
69
+
70
+ it "should eval the config on every request" do
71
+ SimpleNavigation::Configuration.should_receive(:eval_config).with(:default)
72
+ @controller.render_navigation
73
+ end
74
+
75
+ describe 'regarding setting of items' do
76
+ context 'not items specified in options' do
77
+ it "should not set the items directly" do
78
+ SimpleNavigation.config.should_not_receive(:items)
79
+ @controller.render_navigation
80
+ end
81
+ end
82
+ context 'items specified in options' do
83
+ before(:each) do
84
+ @items = stub(:items)
85
+ end
86
+ it "should set the items directly" do
87
+ SimpleNavigation.config.should_receive(:items).with(@items)
88
+ @controller.render_navigation(:items => @items)
89
+ end
90
+ end
91
+ end
92
+
93
+ describe 'no primary navigation defined' do
94
+ before(:each) do
95
+ SimpleNavigation.stub!(:primary_navigation => nil)
96
+ end
97
+ it {lambda {@controller.render_navigation}.should raise_error}
98
+ end
99
+
100
+ context 'rendering of the item_container' do
101
+ before(:each) do
102
+ @active_item_container = stub(:item_container).as_null_object
103
+ SimpleNavigation.stub!(:active_item_container_for => @active_item_container)
104
+ end
105
+ it "should lookup the active_item_container based on the level" do
106
+ SimpleNavigation.should_receive(:active_item_container_for).with(:all)
107
+ @controller.render_navigation
108
+ end
109
+ context 'active_item_container is nil' do
110
+ before(:each) do
111
+ SimpleNavigation.stub!(:active_item_container_for => nil)
112
+ end
113
+ it "should not call render" do
114
+ @active_item_container.should_not_receive(:render)
115
+ @controller.render_navigation
116
+ end
117
+ end
118
+ context 'active_item_container is not nil' do
119
+ it "should call render on the container" do
120
+ @active_item_container.should_receive(:render)
121
+ @controller.render_navigation
122
+ end
123
+ end
124
+ end
125
+
126
+ context 'primary' do
127
+ it "should call render on the primary_navigation (specifying level through options)" do
128
+ @primary_navigation.should_receive(:render).with(:level => 1)
129
+ @controller.render_navigation(:level => 1)
130
+ end
131
+ end
132
+
133
+ context 'secondary' do
134
+ context 'with current_primary_navigation set' do
135
+ before(:each) do
136
+ @selected_item_container = stub(:selected_container).as_null_object
137
+ SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
138
+ end
139
+ it "should find the selected sub_navigation for the specified level" do
140
+ SimpleNavigation.should_receive(:active_item_container_for).with(2)
141
+ @controller.render_navigation(:level => 2)
142
+ end
143
+ it "should find the selected sub_navigation for the specified level" do
144
+ SimpleNavigation.should_receive(:active_item_container_for).with(1)
145
+ @controller.render_navigation(:level => 1)
146
+ end
147
+ it "should call render on the active item_container" do
148
+ @selected_item_container.should_receive(:render).with(:level => 2)
149
+ @controller.render_navigation(:level => 2)
150
+ end
151
+ end
152
+ context 'without an active item_container set' do
153
+ before(:each) do
154
+ SimpleNavigation.stub!(:active_item_container_for => nil)
155
+ end
156
+ it "should not raise an error" do
157
+ lambda {@controller.render_navigation(:level => 2)}.should_not raise_error
158
+ end
159
+ end
160
+
161
+ end
162
+
163
+ context 'unknown level' do
164
+ it "should raise an error" do
165
+ lambda {@controller.render_navigation(:level => :unknown)}.should raise_error(ArgumentError)
166
+ end
167
+ end
168
+
169
+ end
170
+
171
+ describe "should treat :level and :levels options the same" do
172
+ before(:each) do
173
+ whitebox_setup
174
+ @selected_item_container = stub(:selected_container).as_null_object
175
+ SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
176
+ end
177
+ it "should pass a valid levels options as level" do
178
+ @selected_item_container.should_receive(:render).with(:level => 2)
179
+ @controller.render_navigation(:levels => 2)
180
+ end
181
+ end
182
+
183
+ end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleNavigation::Renderer::Base do
4
+ before(:each) do
5
+ @options = stub(:options).as_null_object
6
+ @adapter = stub(:adapter)
7
+ SimpleNavigation.stub!(:adapter => @adapter)
8
+ @base_renderer = SimpleNavigation::Renderer::Base.new(@options)
9
+ end
10
+
11
+ describe 'delegated methods' do
12
+ it {@base_renderer.should respond_to(:link_to)}
13
+ it {@base_renderer.should respond_to(:content_tag)}
14
+ end
15
+
16
+ describe 'initialize' do
17
+ it {@base_renderer.adapter.should == @adapter}
18
+ it {@base_renderer.options.should == @options}
19
+ end
20
+
21
+ describe 'render' do
22
+ it "be subclass responsability" do
23
+ lambda {@base_renderer.render(:container)}.should raise_error('subclass responsibility')
24
+ end
25
+ end
26
+
27
+ describe 'expand_all?' do
28
+ context 'option is set' do
29
+ context 'expand_all is true' do
30
+ before(:each) do
31
+ @base_renderer.stub!(:options => {:expand_all => true})
32
+ end
33
+ it {@base_renderer.expand_all?.should be_true}
34
+ end
35
+ context 'expand_all is false' do
36
+ before(:each) do
37
+ @base_renderer.stub!(:options => {:expand_all => false})
38
+ end
39
+ it {@base_renderer.expand_all?.should be_false}
40
+ end
41
+ end
42
+ context 'option is not set' do
43
+ before(:each) do
44
+ @base_renderer.stub!(:options => {})
45
+ end
46
+ it {@base_renderer.expand_all?.should be_false}
47
+ end
48
+ end
49
+
50
+ describe 'skip_if_empty?' do
51
+ context 'option is set' do
52
+ context 'skip_if_empty is true' do
53
+ before(:each) do
54
+ @base_renderer.stub!(:options => {:skip_if_empty => true})
55
+ end
56
+ it {@base_renderer.skip_if_empty?.should be_true}
57
+ end
58
+ context 'skip_if_empty is false' do
59
+ before(:each) do
60
+ @base_renderer.stub!(:options => {:skip_if_empty => false})
61
+ end
62
+ it {@base_renderer.skip_if_empty?.should be_false}
63
+ end
64
+ end
65
+ context 'option is not set' do
66
+ before(:each) do
67
+ @base_renderer.stub!(:options => {})
68
+ end
69
+ it {@base_renderer.skip_if_empty?.should be_false}
70
+ end
71
+ end
72
+
73
+ describe 'level' do
74
+ context 'options[level] is set' do
75
+ before(:each) do
76
+ @base_renderer.stub!(:options => {:level => 1})
77
+ end
78
+ it {@base_renderer.level.should == 1}
79
+ end
80
+ context 'options[level] is not set' do
81
+ before(:each) do
82
+ @base_renderer.stub!(:options => {})
83
+ end
84
+ it {@base_renderer.level.should == :all}
85
+ end
86
+ end
87
+
88
+ describe 'consider_sub_navigation?' do
89
+ before(:each) do
90
+ @item = stub(:item)
91
+ end
92
+ context 'item has no subnavigation' do
93
+ before(:each) do
94
+ @item.stub!(:sub_navigation => nil)
95
+ end
96
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
97
+ end
98
+ context 'item has subnavigation' do
99
+ before(:each) do
100
+ @sub_navigation = stub(:sub_navigation)
101
+ @item.stub!(:sub_navigation => @sub_navigation)
102
+ end
103
+ context 'level is something unknown' do
104
+ before(:each) do
105
+ @base_renderer.stub!(:level => 'unknown')
106
+ end
107
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
108
+ end
109
+ context 'level is :all' do
110
+ before(:each) do
111
+ @base_renderer.stub!(:level => :all)
112
+ end
113
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
114
+ end
115
+ context 'level is an Integer' do
116
+ before(:each) do
117
+ @base_renderer.stub!(:level => 2)
118
+ end
119
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
120
+ end
121
+ context 'level is a Range' do
122
+ before(:each) do
123
+ @base_renderer.stub!(:level => 2..3)
124
+ end
125
+ context 'subnavs level > range.max' do
126
+ before(:each) do
127
+ @sub_navigation.stub!(:level => 4)
128
+ end
129
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
130
+ end
131
+ context 'subnavs level = range.max' do
132
+ before(:each) do
133
+ @sub_navigation.stub!(:level => 3)
134
+ end
135
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
136
+
137
+ end
138
+ context 'subnavs level < range.max' do
139
+ before(:each) do
140
+ @sub_navigation.stub!(:level => 2)
141
+ end
142
+ it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ describe 'include_sub_navigation?' do
149
+ before(:each) do
150
+ @item = stub(:item)
151
+ end
152
+ context 'consider_sub_navigation? is true' do
153
+ before(:each) do
154
+ @base_renderer.stub!(:consider_sub_navigation? => true)
155
+ end
156
+ context 'expand_sub_navigation? is true' do
157
+ before(:each) do
158
+ @base_renderer.stub!(:expand_sub_navigation? => true)
159
+ end
160
+ it {@base_renderer.include_sub_navigation?(@item).should be_true}
161
+ end
162
+ context 'expand_sub_navigation? is false' do
163
+ before(:each) do
164
+ @base_renderer.stub!(:expand_sub_navigation? => false)
165
+ end
166
+ it {@base_renderer.include_sub_navigation?(@item).should be_false}
167
+ end
168
+ end
169
+ context 'consider_sub_navigation is false' do
170
+ before(:each) do
171
+ @base_renderer.stub!(:consider_sub_navigation? => false)
172
+ end
173
+ context 'expand_sub_navigation? is true' do
174
+ before(:each) do
175
+ @base_renderer.stub!(:expand_sub_navigation? => true)
176
+ end
177
+ it {@base_renderer.include_sub_navigation?(@item).should be_false}
178
+ end
179
+ context 'expand_sub_navigation? is false' do
180
+ before(:each) do
181
+ @base_renderer.stub!(:expand_sub_navigation? => false)
182
+ end
183
+ it {@base_renderer.include_sub_navigation?(@item).should be_false}
184
+ end
185
+ end
186
+ end
187
+
188
+ describe 'render_sub_navigation_for' do
189
+ before(:each) do
190
+ @sub_navigation = stub(:sub_navigation)
191
+ @item = stub(:item, :sub_navigation => @sub_navigation)
192
+ end
193
+ it "should call render on the sub_navigation (passing the options)" do
194
+ @sub_navigation.should_receive(:render).with(@options)
195
+ @base_renderer.render_sub_navigation_for(@item)
196
+ end
197
+ end
198
+
199
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'html/document'# unless defined? HTML::Document
3
+
4
+ describe SimpleNavigation::Renderer::Breadcrumbs do
5
+
6
+ describe 'render' do
7
+
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::Breadcrumbs, :rails, options
12
+ HTML::Document.new(@renderer.render(primary_navigation)).root
13
+ end
14
+
15
+ context 'regarding result' do
16
+
17
+ it "should render a div-tag around the items" do
18
+ HTML::Selector.new('div').select(render).should have(1).entries
19
+ end
20
+ it "the rendered div-tag should have the specified dom_id" do
21
+ HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
22
+ end
23
+ it "the rendered div-tag should have the specified class" do
24
+ HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
25
+ end
26
+
27
+ context 'without current_navigation set' do
28
+ it "should not render any a-tag in the div-tag" do
29
+ HTML::Selector.new('div a').select(render).should have(0).entries
30
+ end
31
+ end
32
+
33
+ context 'with current_navigation set' do
34
+ before(:each) do
35
+ @selection = HTML::Selector.new('div a').select(render(:invoices))
36
+ end
37
+ it "should render the selected a tags" do
38
+ @selection.should have(1).entries
39
+ end
40
+
41
+ it "should not render class or id" do
42
+ @selection.each do |tag|
43
+ raise unless tag.name == "a"
44
+ tag["id"].should be_nil
45
+ tag["class"].should be_nil
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ context 'nested sub_navigation' do
52
+ it "should add an a tag for each selected item" do
53
+ HTML::Selector.new('div a').select(render(:subnav1)).should have(2).entries
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end