jordanyeo-simple-navigation 3.11.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/CHANGELOG +265 -0
- data/Gemfile +17 -0
- data/README +22 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/generators/navigation_config/USAGE +1 -0
- data/generators/navigation_config/navigation_config_generator.rb +8 -0
- data/generators/navigation_config/templates/config/navigation.rb +76 -0
- data/lib/generators/navigation_config/navigation_config_generator.rb +12 -0
- data/lib/simple-navigation.rb +1 -0
- data/lib/simple_navigation.rb +167 -0
- data/lib/simple_navigation/adapters.rb +10 -0
- data/lib/simple_navigation/adapters/base.rb +37 -0
- data/lib/simple_navigation/adapters/nanoc.rb +45 -0
- data/lib/simple_navigation/adapters/padrino.rb +20 -0
- data/lib/simple_navigation/adapters/rails.rb +93 -0
- data/lib/simple_navigation/adapters/sinatra.rb +69 -0
- data/lib/simple_navigation/core.rb +5 -0
- data/lib/simple_navigation/core/configuration.rb +72 -0
- data/lib/simple_navigation/core/item.rb +144 -0
- data/lib/simple_navigation/core/item_adapter.rb +63 -0
- data/lib/simple_navigation/core/item_container.rb +147 -0
- data/lib/simple_navigation/core/items_provider.rb +35 -0
- data/lib/simple_navigation/rails_controller_methods.rb +144 -0
- data/lib/simple_navigation/rendering.rb +12 -0
- data/lib/simple_navigation/rendering/helpers.rb +123 -0
- data/lib/simple_navigation/rendering/renderer/base.rb +107 -0
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +59 -0
- data/lib/simple_navigation/rendering/renderer/json.rb +29 -0
- data/lib/simple_navigation/rendering/renderer/links.rb +32 -0
- data/lib/simple_navigation/rendering/renderer/list.rb +29 -0
- data/lib/simple_navigation/rendering/renderer/text.rb +26 -0
- data/rails/init.rb +1 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +31 -0
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +287 -0
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +80 -0
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -0
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +212 -0
- data/spec/lib/simple_navigation/core/item_container_spec.rb +451 -0
- data/spec/lib/simple_navigation/core/item_spec.rb +566 -0
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +60 -0
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +249 -0
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +276 -0
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +199 -0
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +101 -0
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +48 -0
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +64 -0
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +211 -0
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -0
- data/spec/lib/simple_navigation_spec.rb +307 -0
- data/spec/spec_helper.rb +108 -0
- metadata +199 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleNavigation::ItemsProvider do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@provider = stub(:provider)
|
7
|
+
@items_provider = SimpleNavigation::ItemsProvider.new(@provider)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'initialize' do
|
11
|
+
it "should set the provider" do
|
12
|
+
@items_provider.provider.should == @provider
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'items' do
|
17
|
+
before(:each) do
|
18
|
+
@items = stub(:items)
|
19
|
+
end
|
20
|
+
context 'provider is symbol' do
|
21
|
+
before(:each) do
|
22
|
+
@items_provider.instance_variable_set(:@provider, :provider_method)
|
23
|
+
@context = stub(:context, :provider_method => @items)
|
24
|
+
SimpleNavigation.stub!(:context_for_eval => @context)
|
25
|
+
end
|
26
|
+
it "should call the method specified by symbol on the context" do
|
27
|
+
@context.should_receive(:provider_method)
|
28
|
+
@items_provider.items
|
29
|
+
end
|
30
|
+
it "should return the items returned by the helper method" do
|
31
|
+
@items_provider.items.should == @items
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context 'provider responds to items' do
|
35
|
+
before(:each) do
|
36
|
+
@provider.stub!(:items => @items)
|
37
|
+
end
|
38
|
+
it "should get the items from the items_provider" do
|
39
|
+
@provider.should_receive(:items)
|
40
|
+
@items_provider.items
|
41
|
+
end
|
42
|
+
it "should return the items of the provider" do
|
43
|
+
@items_provider.items.should == @items
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'provider is a collection' do
|
47
|
+
before(:each) do
|
48
|
+
@items_collection = []
|
49
|
+
@items_provider.instance_variable_set(:@provider, @items_collection)
|
50
|
+
end
|
51
|
+
it "should return the collection itsself" do
|
52
|
+
@items_provider.items.should == @items_collection
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context 'neither symbol nor items_provider.items nor collection' do
|
56
|
+
it {lambda {@items_provider.items}.should raise_error}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -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, true).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,276 @@
|
|
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
|
+
SimpleNavigation.stub!(:load_config)
|
11
|
+
SimpleNavigation::Configuration.stub!(:eval_config)
|
12
|
+
setup_adapter_for :rails
|
13
|
+
@primary_container, @subnav_container = containers
|
14
|
+
@subnav1_item = sub_item(:subnav1)
|
15
|
+
@invoices_item = primary_item(:invoices)
|
16
|
+
SimpleNavigation.stub!(:primary_navigation => @primary_container)
|
17
|
+
end
|
18
|
+
|
19
|
+
def whitebox_setup
|
20
|
+
@controller = ControllerMock.new
|
21
|
+
SimpleNavigation.stub!(:load_config)
|
22
|
+
SimpleNavigation::Configuration.stub!(:eval_config)
|
23
|
+
@primary_navigation = stub(:primary_navigation).as_null_object
|
24
|
+
SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
|
25
|
+
SimpleNavigation.stub!(:config_file? => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'active_navigation_item_name' do
|
29
|
+
before(:each) do
|
30
|
+
blackbox_setup
|
31
|
+
end
|
32
|
+
context 'active item_container for desired level exists' do
|
33
|
+
context 'container has selected item' do
|
34
|
+
before(:each) do
|
35
|
+
select_item(:subnav1)
|
36
|
+
end
|
37
|
+
it {@controller.active_navigation_item_name(:level => 2).should == 'subnav1'}
|
38
|
+
it {@controller.active_navigation_item_name.should == 'subnav1'}
|
39
|
+
it {@controller.active_navigation_item_name(:level => 1).should == 'invoices'}
|
40
|
+
it {@controller.active_navigation_item_name(:level => :all).should == 'subnav1'}
|
41
|
+
end
|
42
|
+
context 'container does not have selected item' do
|
43
|
+
it {@controller.active_navigation_item_name.should == ''}
|
44
|
+
end
|
45
|
+
context 'custom name generator set' do
|
46
|
+
before(:each) do
|
47
|
+
select_item(:subnav1)
|
48
|
+
SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
|
49
|
+
end
|
50
|
+
it "should not apply the generator" do
|
51
|
+
@controller.active_navigation_item_name(:level => 1).should == 'invoices'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context 'no active item_container for desired level' do
|
56
|
+
it {@controller.active_navigation_item_name(:level => 5).should == ''}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'active_navigation_item_key' do
|
61
|
+
before(:each) do
|
62
|
+
blackbox_setup
|
63
|
+
end
|
64
|
+
context 'active item_container for desired level exists' do
|
65
|
+
context 'container has selected item' do
|
66
|
+
before(:each) do
|
67
|
+
select_item(:subnav1)
|
68
|
+
end
|
69
|
+
it {@controller.active_navigation_item_key(:level => 2).should == :subnav1}
|
70
|
+
it {@controller.active_navigation_item_key.should == :subnav1}
|
71
|
+
it {@controller.active_navigation_item_key(:level => 1).should == :invoices}
|
72
|
+
it {@controller.active_navigation_item_key(:level => :all).should == :subnav1}
|
73
|
+
end
|
74
|
+
context 'container does not have selected item' do
|
75
|
+
it {@controller.active_navigation_item_key.should == nil}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context 'no active item_container for desired level' do
|
79
|
+
it {@controller.active_navigation_item_key(:level => 5).should == nil}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'active_navigation_item' do
|
84
|
+
before(:each) do
|
85
|
+
blackbox_setup
|
86
|
+
end
|
87
|
+
context 'active item_container for desired level exists' do
|
88
|
+
context 'container has selected item' do
|
89
|
+
before(:each) do
|
90
|
+
select_item(:subnav1)
|
91
|
+
end
|
92
|
+
it {@controller.active_navigation_item(:level => 2).should eq(@subnav1_item)}
|
93
|
+
it {@controller.active_navigation_item.should eq(@subnav1_item)}
|
94
|
+
it {@controller.active_navigation_item(:level => 1).should eq(@invoices_item)}
|
95
|
+
it {@controller.active_navigation_item(:level => :all).should eq(@subnav1_item)}
|
96
|
+
end
|
97
|
+
context 'container does not have selected item' do
|
98
|
+
context 'return value defaults to nil' do
|
99
|
+
it {@controller.active_navigation_item.should == nil}
|
100
|
+
end
|
101
|
+
context 'return value reflects passed in value' do
|
102
|
+
it {@controller.active_navigation_item({},'none').should == 'none'}
|
103
|
+
it {@controller.active_navigation_item({},@invoices_item).should eq(@invoices_item)}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
context 'no active item_container for desired level' do
|
108
|
+
it {@controller.active_navigation_item(:level => 5).should == nil}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'active_navigation_item_container' do
|
113
|
+
before(:each) do
|
114
|
+
blackbox_setup
|
115
|
+
end
|
116
|
+
context 'active item_container for desired level exists' do
|
117
|
+
before(:each) do
|
118
|
+
select_item(:subnav1)
|
119
|
+
end
|
120
|
+
it {@controller.active_navigation_item_container(:level => 2).should == @subnav_container}
|
121
|
+
it {@controller.active_navigation_item_container.should == @primary_container}
|
122
|
+
it {@controller.active_navigation_item_container(:level => 1).should == @primary_container}
|
123
|
+
it {@controller.active_navigation_item_container(:level => :all).should == @primary_container}
|
124
|
+
end
|
125
|
+
context 'no active item_container for desired level' do
|
126
|
+
it {@controller.active_navigation_item_container(:level => 5).should == nil}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'render_navigation' do
|
131
|
+
|
132
|
+
before(:each) do
|
133
|
+
whitebox_setup
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'regarding loading of the config-file' do
|
137
|
+
context 'no options specified' do
|
138
|
+
it "should load the config-file for the default context" do
|
139
|
+
SimpleNavigation.should_receive(:load_config).with(:default)
|
140
|
+
@controller.render_navigation
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'with options specified' do
|
145
|
+
it "should load the config-file for the specified context" do
|
146
|
+
SimpleNavigation.should_receive(:load_config).with(:my_context)
|
147
|
+
@controller.render_navigation(:context => :my_context)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should eval the config on every request" do
|
153
|
+
SimpleNavigation::Configuration.should_receive(:eval_config).with(:default)
|
154
|
+
@controller.render_navigation
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'regarding setting of items' do
|
158
|
+
context 'not items specified in options' do
|
159
|
+
it "should not set the items directly" do
|
160
|
+
SimpleNavigation.config.should_not_receive(:items)
|
161
|
+
@controller.render_navigation
|
162
|
+
end
|
163
|
+
end
|
164
|
+
context 'items specified in options' do
|
165
|
+
before(:each) do
|
166
|
+
@items = stub(:items)
|
167
|
+
end
|
168
|
+
it "should set the items directly" do
|
169
|
+
SimpleNavigation.config.should_receive(:items).with(@items)
|
170
|
+
@controller.render_navigation(:items => @items)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context 'block given' do
|
174
|
+
it 'should use block' do
|
175
|
+
block_executed = 0
|
176
|
+
expect do
|
177
|
+
@controller.render_navigation do |menu|
|
178
|
+
menu.class.should == SimpleNavigation::ItemContainer
|
179
|
+
block_executed += 1
|
180
|
+
end
|
181
|
+
end.to change{block_executed}.by(1)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'no primary navigation defined' do
|
187
|
+
before(:each) do
|
188
|
+
SimpleNavigation.stub!(:primary_navigation => nil)
|
189
|
+
end
|
190
|
+
it {lambda {@controller.render_navigation}.should raise_error}
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'rendering of the item_container' do
|
194
|
+
before(:each) do
|
195
|
+
@active_item_container = stub(:item_container).as_null_object
|
196
|
+
SimpleNavigation.stub!(:active_item_container_for => @active_item_container)
|
197
|
+
end
|
198
|
+
it "should lookup the active_item_container based on the level" do
|
199
|
+
SimpleNavigation.should_receive(:active_item_container_for).with(:all)
|
200
|
+
@controller.render_navigation
|
201
|
+
end
|
202
|
+
context 'active_item_container is nil' do
|
203
|
+
before(:each) do
|
204
|
+
SimpleNavigation.stub!(:active_item_container_for => nil)
|
205
|
+
end
|
206
|
+
it "should not call render" do
|
207
|
+
@active_item_container.should_not_receive(:render)
|
208
|
+
@controller.render_navigation
|
209
|
+
end
|
210
|
+
end
|
211
|
+
context 'active_item_container is not nil' do
|
212
|
+
it "should call render on the container" do
|
213
|
+
@active_item_container.should_receive(:render)
|
214
|
+
@controller.render_navigation
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'primary' do
|
220
|
+
it "should call render on the primary_navigation (specifying level through options)" do
|
221
|
+
@primary_navigation.should_receive(:render).with(:level => 1)
|
222
|
+
@controller.render_navigation(:level => 1)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'secondary' do
|
227
|
+
context 'with current_primary_navigation set' do
|
228
|
+
before(:each) do
|
229
|
+
@selected_item_container = stub(:selected_container).as_null_object
|
230
|
+
SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
|
231
|
+
end
|
232
|
+
it "should find the selected sub_navigation for the specified level" do
|
233
|
+
SimpleNavigation.should_receive(:active_item_container_for).with(2)
|
234
|
+
@controller.render_navigation(:level => 2)
|
235
|
+
end
|
236
|
+
it "should find the selected sub_navigation for the specified level" do
|
237
|
+
SimpleNavigation.should_receive(:active_item_container_for).with(1)
|
238
|
+
@controller.render_navigation(:level => 1)
|
239
|
+
end
|
240
|
+
it "should call render on the active item_container" do
|
241
|
+
@selected_item_container.should_receive(:render).with(:level => 2)
|
242
|
+
@controller.render_navigation(:level => 2)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
context 'without an active item_container set' do
|
246
|
+
before(:each) do
|
247
|
+
SimpleNavigation.stub!(:active_item_container_for => nil)
|
248
|
+
end
|
249
|
+
it "should not raise an error" do
|
250
|
+
lambda {@controller.render_navigation(:level => 2)}.should_not raise_error
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'unknown level' do
|
257
|
+
it "should raise an error" do
|
258
|
+
lambda {@controller.render_navigation(:level => :unknown)}.should raise_error(ArgumentError)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "should treat :level and :levels options the same" do
|
265
|
+
before(:each) do
|
266
|
+
whitebox_setup
|
267
|
+
@selected_item_container = stub(:selected_container).as_null_object
|
268
|
+
SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
|
269
|
+
end
|
270
|
+
it "should pass a valid levels options as level" do
|
271
|
+
@selected_item_container.should_receive(:render).with(:level => 2)
|
272
|
+
@controller.render_navigation(:levels => 2)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|