simple-navigation 2.7.3 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -4
- data/README +1 -2
- data/Rakefile +1 -0
- data/VERSION.yml +4 -4
- data/generators/navigation_config/templates/config/navigation.rb +14 -14
- data/lib/simple_navigation.rb +69 -151
- data/lib/simple_navigation/adapters.rb +9 -0
- data/lib/simple_navigation/adapters/base.rb +37 -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 +76 -0
- data/lib/simple_navigation/core.rb +5 -0
- data/lib/simple_navigation/{configuration.rb → core/configuration.rb} +14 -19
- data/lib/simple_navigation/{item.rb → core/item.rb} +10 -11
- data/lib/simple_navigation/{item_adapter.rb → core/item_adapter.rb} +11 -7
- data/lib/simple_navigation/{item_container.rb → core/item_container.rb} +14 -21
- data/lib/simple_navigation/{items_provider.rb → core/items_provider.rb} +7 -7
- data/lib/simple_navigation/{controller_methods.rb → rails_controller_methods.rb} +67 -5
- data/lib/simple_navigation/rendering.rb +10 -0
- data/lib/simple_navigation/{helpers.rb → rendering/helpers.rb} +16 -18
- data/lib/simple_navigation/{renderer → rendering/renderer}/base.rb +20 -37
- data/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs.rb +7 -7
- data/lib/simple_navigation/{renderer → rendering/renderer}/links.rb +7 -7
- data/lib/simple_navigation/{renderer → rendering/renderer}/list.rb +6 -6
- data/rails/init.rb +1 -5
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +29 -0
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +269 -0
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +60 -0
- data/spec/lib/simple_navigation/{configuration_spec.rb → core/configuration_spec.rb} +7 -18
- data/spec/lib/simple_navigation/{item_adapter_spec.rb → core/item_adapter_spec.rb} +11 -11
- data/spec/lib/simple_navigation/{item_container_spec.rb → core/item_container_spec.rb} +29 -46
- data/spec/lib/simple_navigation/{item_spec.rb → core/item_spec.rb} +30 -64
- data/spec/lib/simple_navigation/{items_provider_spec.rb → core/items_provider_spec.rb} +7 -7
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +251 -0
- data/spec/lib/simple_navigation/{helpers_spec.rb → rendering/helpers_spec.rb} +34 -53
- data/spec/lib/simple_navigation/{renderer → rendering/renderer}/base_spec.rb +11 -62
- data/spec/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs_spec.rb +9 -51
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +59 -0
- data/spec/lib/simple_navigation/{renderer → rendering/renderer}/list_spec.rb +17 -58
- data/spec/lib/simple_navigation_spec.rb +51 -298
- data/spec/spec_helper.rb +16 -5
- metadata +67 -48
- data/lib/simple_navigation/initializer.rb +0 -21
- data/lib/simple_navigation/railtie.rb +0 -7
- data/spec/lib/simple_navigation/controller_methods_spec.rb +0 -90
- data/spec/lib/simple_navigation/renderer/links_spec.rb +0 -121
@@ -1,19 +1,19 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
2
2
|
require 'html/document' unless defined? HTML::Document
|
3
3
|
|
4
4
|
describe SimpleNavigation::Renderer::Breadcrumbs do
|
5
|
-
|
5
|
+
|
6
6
|
describe 'render' do
|
7
|
-
|
7
|
+
|
8
8
|
def render(current_nav=nil, options={:level => :all})
|
9
9
|
primary_navigation = primary_container
|
10
10
|
select_item(current_nav) if current_nav
|
11
|
-
|
11
|
+
setup_renderer_for SimpleNavigation::Renderer::Breadcrumbs, :rails, options
|
12
12
|
HTML::Document.new(@renderer.render(primary_navigation)).root
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
context 'regarding result' do
|
16
|
-
|
16
|
+
|
17
17
|
it "should render a div-tag around the items" do
|
18
18
|
HTML::Selector.new('div').select(render).should have(1).entries
|
19
19
|
end
|
@@ -29,7 +29,7 @@ describe SimpleNavigation::Renderer::Breadcrumbs do
|
|
29
29
|
HTML::Selector.new('div a').select(render).should have(0).entries
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
context 'with current_navigation set' do
|
34
34
|
before :all do
|
35
35
|
@selection = HTML::Selector.new('div a').select(render(:invoices))
|
@@ -46,55 +46,13 @@ describe SimpleNavigation::Renderer::Breadcrumbs do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
|
-
|
49
|
+
|
50
|
+
|
51
51
|
context 'nested sub_navigation' do
|
52
52
|
it "should add an a tag for each selected item" do
|
53
53
|
HTML::Selector.new('div a').select(render(:subnav1)).should have(2).entries
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
|
-
context 'regarding method calls' do
|
59
|
-
|
60
|
-
context 'regarding the list_content' do
|
61
|
-
before(:each) do
|
62
|
-
@primary_navigation = primary_container
|
63
|
-
@list_content = stub(:list_content)
|
64
|
-
@list_items = stub(:list_items, :join => @list_content)
|
65
|
-
@items.stub!(:inject => @list_items)
|
66
|
-
@renderer = SimpleNavigation::Renderer::Breadcrumbs.new(options)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should join the list_items" do
|
70
|
-
@list_items.should_receive(:join)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should html_saferize the list_content" do
|
74
|
-
@renderer.should_receive(:html_safe).with(@list_content)
|
75
|
-
end
|
76
|
-
|
77
|
-
after(:each) do
|
78
|
-
@renderer.render(@primary_navigation)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'regarding the items' do
|
83
|
-
before(:each) do
|
84
|
-
@primary_navigation = primary_container
|
85
|
-
select_item(:invoices)
|
86
|
-
@renderer = SimpleNavigation::Renderer::Breadcrumbs.new(options)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should call html_safe on every rendered item's name" do
|
90
|
-
@items.each do |item|
|
91
|
-
@renderer.should_receive(:html_safe).with(item.name) if item.selected?
|
92
|
-
end
|
93
|
-
@renderer.should_receive(:html_safe).with(anything).twice()
|
94
|
-
@renderer.render(@primary_navigation)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
57
|
end
|
100
58
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
2
|
+
require 'html/document' unless defined? HTML::Document
|
3
|
+
|
4
|
+
describe SimpleNavigation::Renderer::Links do
|
5
|
+
|
6
|
+
|
7
|
+
describe 'render' do
|
8
|
+
|
9
|
+
|
10
|
+
def render(current_nav=nil, options={:level => :all})
|
11
|
+
primary_navigation = primary_container
|
12
|
+
select_item(current_nav) if current_nav
|
13
|
+
setup_renderer_for SimpleNavigation::Renderer::Links, :rails, options
|
14
|
+
HTML::Document.new(@renderer.render(primary_navigation)).root
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'regarding result' do
|
18
|
+
|
19
|
+
it "should render a div-tag around the items" do
|
20
|
+
HTML::Selector.new('div').select(render).should have(1).entries
|
21
|
+
end
|
22
|
+
it "the rendered div-tag should have the specified dom_id" do
|
23
|
+
HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
|
24
|
+
end
|
25
|
+
it "the rendered div-tag should have the specified class" do
|
26
|
+
HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
|
27
|
+
end
|
28
|
+
it "should render an a-tag for each item" do
|
29
|
+
HTML::Selector.new('a').select(render).should have(3).entries
|
30
|
+
end
|
31
|
+
it "should pass the specified html_options to the a element" do
|
32
|
+
HTML::Selector.new('a[style=float:right]').select(render).should have(1).entries
|
33
|
+
end
|
34
|
+
it "should give the a-tag the id specified in the html_options" do
|
35
|
+
HTML::Selector.new('a#my_id').select(render).should have(1).entries
|
36
|
+
end
|
37
|
+
it "should give the a-tag the default id (stringified key) if no id is specified in the html_options" do
|
38
|
+
HTML::Selector.new('a#invoices').select(render).should have(1).entries
|
39
|
+
end
|
40
|
+
it "should not apply the the default id where there is an id specified in the html_options" do
|
41
|
+
HTML::Selector.new('a#users').select(render).should be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with current_navigation set' do
|
45
|
+
it "should mark the matching a-item as selected (with the css_class specified in configuration)" do
|
46
|
+
HTML::Selector.new('a.selected').select(render(:invoices)).should have(1).entries
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'without current_navigation set' do
|
51
|
+
it "should not mark any of the items as selected" do
|
52
|
+
HTML::Selector.new('a.selected').select(render).should be_empty
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
2
2
|
require 'html/document' unless defined? HTML::Document
|
3
3
|
|
4
4
|
describe SimpleNavigation::Renderer::List do
|
5
|
-
|
5
|
+
|
6
6
|
describe 'render' do
|
7
|
-
|
7
|
+
|
8
8
|
def render(current_nav=nil, options={:level => :all})
|
9
9
|
primary_navigation = primary_container
|
10
10
|
select_item(current_nav) if current_nav
|
11
|
-
|
11
|
+
setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
|
12
12
|
HTML::Document.new(@renderer.render(primary_navigation)).root
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
context 'regarding result' do
|
16
|
-
|
16
|
+
|
17
17
|
it "should render a ul-tag around the items" do
|
18
18
|
HTML::Selector.new('ul').select(render).should have(1).entries
|
19
19
|
end
|
@@ -41,7 +41,7 @@ describe SimpleNavigation::Renderer::List do
|
|
41
41
|
it "should not apply the the default id where there is an id specified in the html_options" do
|
42
42
|
HTML::Selector.new('ul li#users').select(render).should be_empty
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
context 'with current_navigation set' do
|
46
46
|
it "should mark the matching li-item as selected (with the css_class specified in configuration)" do
|
47
47
|
HTML::Selector.new('li.selected').select(render(:invoices)).should have(1).entries
|
@@ -49,9 +49,9 @@ describe SimpleNavigation::Renderer::List do
|
|
49
49
|
it "should also mark the links inside the selected li's as selected" do
|
50
50
|
HTML::Selector.new('li.selected a.selected').select(render(:invoices)).should have(1).entries
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
context 'without current_navigation set' do
|
56
56
|
it "should not mark any of the items as selected" do
|
57
57
|
HTML::Selector.new('li.selected').select(render).should be_empty
|
@@ -60,7 +60,7 @@ describe SimpleNavigation::Renderer::List do
|
|
60
60
|
HTML::Selector.new('a.selected').select(render).should be_empty
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
context 'nested sub_navigation' do
|
65
65
|
it "should nest the current_primary's subnavigation inside the selected li-element" do
|
66
66
|
HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
|
@@ -74,23 +74,23 @@ describe SimpleNavigation::Renderer::List do
|
|
74
74
|
HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
context 'expand_all => true' do
|
79
79
|
it "should render the invoices submenu even if the user-primary is active" do
|
80
80
|
HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
|
81
81
|
HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
context 'skip_if_empty' do
|
88
|
-
|
88
|
+
|
89
89
|
def render_container(options={})
|
90
|
-
|
90
|
+
setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
|
91
91
|
HTML::Document.new(@renderer.render(@container)).root
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
context 'container is empty' do
|
95
95
|
before(:each) do
|
96
96
|
@container = SimpleNavigation::ItemContainer.new(0)
|
@@ -106,7 +106,7 @@ describe SimpleNavigation::Renderer::List do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
context 'container is not empty' do
|
111
111
|
before(:each) do
|
112
112
|
@container = primary_container
|
@@ -125,46 +125,5 @@ describe SimpleNavigation::Renderer::List do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
context 'regarding method calls' do
|
129
|
-
|
130
|
-
context 'regarding the list_content' do
|
131
|
-
before(:each) do
|
132
|
-
@primary_navigation = primary_container
|
133
|
-
@list_content = stub(:list_content)
|
134
|
-
@list_items = stub(:list_items, :join => @list_content)
|
135
|
-
@items.stub!(:inject => @list_items)
|
136
|
-
@renderer = SimpleNavigation::Renderer::List.new(options)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should join the list_items" do
|
140
|
-
@list_items.should_receive(:join)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should html_saferize the list_content" do
|
144
|
-
@renderer.should_receive(:html_safe).with(@list_content)
|
145
|
-
end
|
146
|
-
|
147
|
-
after(:each) do
|
148
|
-
@renderer.render(@primary_navigation)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'regarding the items' do
|
153
|
-
before(:each) do
|
154
|
-
@primary_navigation = primary_container
|
155
|
-
@renderer = SimpleNavigation::Renderer::List.new(options)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should call html_safe on every item's name" do
|
159
|
-
@items.each do |item|
|
160
|
-
@renderer.should_receive(:html_safe).with(item.name)
|
161
|
-
end
|
162
|
-
@renderer.should_receive(:html_safe).with(anything)
|
163
|
-
@renderer.render(@primary_navigation)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
128
|
end
|
170
129
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe SimpleNavigation do
|
4
|
-
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
SimpleNavigation.config_file_path = 'path_to_config'
|
7
|
+
end
|
8
|
+
|
5
9
|
describe 'config_file_name' do
|
6
10
|
context 'for :default navigation_context' do
|
7
11
|
it "should return the name of the default config file" do
|
@@ -18,33 +22,6 @@ describe SimpleNavigation do
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
describe 'config_file_paths_sentence' do
|
22
|
-
context 'no paths are set' do
|
23
|
-
before(:each) do
|
24
|
-
SimpleNavigation.config_file_paths = []
|
25
|
-
end
|
26
|
-
it {SimpleNavigation.config_file_paths_sentence.should == ''}
|
27
|
-
end
|
28
|
-
context 'one path is set' do
|
29
|
-
before(:each) do
|
30
|
-
SimpleNavigation.config_file_paths = ['first_path']
|
31
|
-
end
|
32
|
-
it {SimpleNavigation.config_file_paths_sentence.should == 'first_path'}
|
33
|
-
end
|
34
|
-
context 'two paths are set' do
|
35
|
-
before(:each) do
|
36
|
-
SimpleNavigation.config_file_paths = ['first_path', 'second_path']
|
37
|
-
end
|
38
|
-
it {SimpleNavigation.config_file_paths_sentence.should == 'first_path or second_path'}
|
39
|
-
end
|
40
|
-
context 'three pahts are set' do
|
41
|
-
before(:each) do
|
42
|
-
SimpleNavigation.config_file_paths = ['first_path', 'second_path', 'third_path']
|
43
|
-
end
|
44
|
-
it {SimpleNavigation.config_file_paths_sentence.should == 'first_path, second_path, or third_path'}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
25
|
describe 'config_file_path=' do
|
49
26
|
before(:each) do
|
50
27
|
SimpleNavigation.config_file_paths = ['existing_path']
|
@@ -122,161 +99,19 @@ describe SimpleNavigation do
|
|
122
99
|
it {SimpleNavigation.config_file?.should be_false}
|
123
100
|
end
|
124
101
|
end
|
125
|
-
|
126
|
-
describe 'set_template_from' do
|
127
|
-
before(:each) do
|
128
|
-
@context = stub :context
|
129
|
-
SimpleNavigation.stub!(:extract_controller_from => @controller)
|
130
|
-
end
|
131
|
-
context 'regarding setting the controller' do
|
132
|
-
it "should set the controller" do
|
133
|
-
@controller = Object.new
|
134
|
-
SimpleNavigation.should_receive(:extract_controller_from).with(@context).and_return(@controller)
|
135
|
-
SimpleNavigation.should_receive(:controller=).with(@controller)
|
136
|
-
SimpleNavigation.set_template_from @context
|
137
|
-
end
|
138
|
-
end
|
139
|
-
context 'regarding setting the template' do
|
140
|
-
before(:each) do
|
141
|
-
@template = stub :template
|
142
|
-
@controller = Object.new
|
143
|
-
SimpleNavigation.stub!(:controller => @controller)
|
144
|
-
end
|
145
|
-
context 'template is stored in controller as instance_var (Rails2)' do
|
146
|
-
context 'template is set' do
|
147
|
-
before(:each) do
|
148
|
-
@controller.stub!(:instance_variable_get => @template)
|
149
|
-
end
|
150
|
-
it {SimpleNavigation.should_receive(:template=).with(@template)}
|
151
|
-
end
|
152
|
-
context 'template is not set' do
|
153
|
-
before(:each) do
|
154
|
-
@controller.stub!(:instance_variable_get => nil)
|
155
|
-
end
|
156
|
-
it {SimpleNavigation.should_receive(:template=).with(nil)}
|
157
|
-
end
|
158
|
-
end
|
159
|
-
context 'template is stored in controller as view_context (Rails3)' do
|
160
|
-
context 'template is set' do
|
161
|
-
before(:each) do
|
162
|
-
@controller.stub!(:view_context => @template)
|
163
|
-
end
|
164
|
-
it {SimpleNavigation.should_receive(:template=).with(@template)}
|
165
|
-
end
|
166
|
-
context 'template is not set' do
|
167
|
-
before(:each) do
|
168
|
-
@controller.stub!(:view_context => nil)
|
169
|
-
end
|
170
|
-
it {SimpleNavigation.should_receive(:template=).with(nil)}
|
171
|
-
end
|
172
|
-
end
|
173
|
-
after(:each) do
|
174
|
-
SimpleNavigation.set_template_from @context
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe 'self.init_rails' do
|
181
|
-
before(:each) do
|
182
|
-
SimpleNavigation.config_file_paths = []
|
183
|
-
SimpleNavigation.stub!(:default_config_file_path => 'default_path')
|
184
|
-
ActionController::Base.stub!(:include)
|
185
|
-
end
|
186
|
-
context 'SimpleNavigation.config_file_path is already set' do
|
187
|
-
before(:each) do
|
188
|
-
SimpleNavigation.config_file_path = 'my_path'
|
189
|
-
end
|
190
|
-
it "should have both the default_path and the new path" do
|
191
|
-
SimpleNavigation.init_rails
|
192
|
-
SimpleNavigation.config_file_paths.should == ['my_path', 'default_path']
|
193
|
-
end
|
194
|
-
end
|
195
|
-
context 'SimpleNavigation.config_file_paths are not set' do
|
196
|
-
it "should set the config_file_path to the default" do
|
197
|
-
SimpleNavigation.init_rails
|
198
|
-
SimpleNavigation.config_file_paths.should == ['default_path']
|
199
|
-
end
|
200
|
-
end
|
201
|
-
it "should extend the ActionController::Base" do
|
202
|
-
ActionController::Base.should_receive(:include).with(SimpleNavigation::ControllerMethods)
|
203
|
-
SimpleNavigation.init_rails
|
204
|
-
end
|
205
|
-
end
|
206
102
|
|
207
103
|
describe 'self.default_config_file_path' do
|
208
|
-
it {SimpleNavigation.default_config_file_path.should == './config'}
|
209
|
-
end
|
210
|
-
|
211
|
-
describe 'self.extract_controller_from' do
|
212
104
|
before(:each) do
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
context 'object responds to controller' do
|
217
|
-
before(:each) do
|
218
|
-
@controller = stub(:controller)
|
219
|
-
@nav_context.stub!(:controller).and_return(@controller)
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should return the controller" do
|
223
|
-
SimpleNavigation.send(:extract_controller_from, @nav_context).should == @controller
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'object does not respond to controller' do
|
229
|
-
it "should return the nav_context" do
|
230
|
-
SimpleNavigation.send(:extract_controller_from, @nav_context).should == @nav_context
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe 'context_for_eval' do
|
236
|
-
context 'controller is present' do
|
237
|
-
before(:each) do
|
238
|
-
@controller = stub(:controller)
|
239
|
-
SimpleNavigation.stub!(:controller => @controller)
|
240
|
-
end
|
241
|
-
context 'template is present' do
|
242
|
-
before(:each) do
|
243
|
-
@template = stub(:template)
|
244
|
-
SimpleNavigation.stub!(:template => @template)
|
245
|
-
end
|
246
|
-
it {SimpleNavigation.context_for_eval.should == @template}
|
247
|
-
end
|
248
|
-
context 'template is not present' do
|
249
|
-
before(:each) do
|
250
|
-
SimpleNavigation.stub!(:template => nil)
|
251
|
-
end
|
252
|
-
it {SimpleNavigation.context_for_eval.should == @controller}
|
253
|
-
end
|
254
|
-
end
|
255
|
-
context 'controller is not present' do
|
256
|
-
before(:each) do
|
257
|
-
SimpleNavigation.stub!(:controller => nil)
|
258
|
-
end
|
259
|
-
context 'template is present' do
|
260
|
-
before(:each) do
|
261
|
-
@template = stub(:template)
|
262
|
-
SimpleNavigation.stub!(:template => @template)
|
263
|
-
end
|
264
|
-
it {SimpleNavigation.context_for_eval.should == @template}
|
265
|
-
end
|
266
|
-
context 'template is not present' do
|
267
|
-
before(:each) do
|
268
|
-
SimpleNavigation.stub!(:template => nil)
|
269
|
-
end
|
270
|
-
it {lambda {SimpleNavigation.context_for_eval}.should raise_error}
|
271
|
-
end
|
105
|
+
SimpleNavigation.stub!(:root => 'root')
|
272
106
|
end
|
107
|
+
it {SimpleNavigation.default_config_file_path.should == 'root/config'}
|
273
108
|
end
|
274
109
|
|
275
110
|
describe 'regarding renderers' do
|
276
111
|
it "should have registered the builtin renderers by default" do
|
277
112
|
SimpleNavigation.registered_renderers.should_not be_empty
|
278
113
|
end
|
279
|
-
|
114
|
+
|
280
115
|
describe 'register_renderer' do
|
281
116
|
before(:each) do
|
282
117
|
@renderer = stub(:renderer)
|
@@ -286,9 +121,25 @@ describe SimpleNavigation do
|
|
286
121
|
SimpleNavigation.registered_renderers[:my_renderer].should == @renderer
|
287
122
|
end
|
288
123
|
end
|
289
|
-
|
124
|
+
|
290
125
|
end
|
291
126
|
|
127
|
+
describe 'set_env' do
|
128
|
+
before(:each) do
|
129
|
+
SimpleNavigation.config_file_paths = []
|
130
|
+
SimpleNavigation.stub!(:default_config_file_path => 'default_path')
|
131
|
+
SimpleNavigation.set_env('root', 'my_env')
|
132
|
+
end
|
133
|
+
it "should set the root" do
|
134
|
+
SimpleNavigation.root.should == 'root'
|
135
|
+
end
|
136
|
+
it "should set the environment" do
|
137
|
+
SimpleNavigation.environment.should == 'my_env'
|
138
|
+
end
|
139
|
+
it "should add the default-config path to the list of config_file_paths" do
|
140
|
+
SimpleNavigation.config_file_paths.should == ['default_path']
|
141
|
+
end
|
142
|
+
end
|
292
143
|
|
293
144
|
describe 'load_config' do
|
294
145
|
context 'config_file_path is set' do
|
@@ -340,9 +191,9 @@ describe SimpleNavigation do
|
|
340
191
|
SimpleNavigation.config_file_path = 'path_to_config'
|
341
192
|
File.stub!(:exists? => true)
|
342
193
|
end
|
343
|
-
context "
|
194
|
+
context "environment undefined" do
|
344
195
|
before(:each) do
|
345
|
-
SimpleNavigation.
|
196
|
+
SimpleNavigation.stub!(:environment => nil)
|
346
197
|
end
|
347
198
|
it "should load the config file twice" do
|
348
199
|
IO.should_receive(:read).twice
|
@@ -350,11 +201,11 @@ describe SimpleNavigation do
|
|
350
201
|
SimpleNavigation.load_config
|
351
202
|
end
|
352
203
|
end
|
353
|
-
context "
|
204
|
+
context "environment defined" do
|
354
205
|
before(:each) do
|
355
|
-
SimpleNavigation.
|
206
|
+
SimpleNavigation.stub!(:environment => 'production')
|
356
207
|
end
|
357
|
-
context "
|
208
|
+
context "environment=production" do
|
358
209
|
it "should load the config file only once" do
|
359
210
|
IO.should_receive(:read).once
|
360
211
|
SimpleNavigation.load_config
|
@@ -362,9 +213,9 @@ describe SimpleNavigation do
|
|
362
213
|
end
|
363
214
|
end
|
364
215
|
|
365
|
-
context "
|
216
|
+
context "environment=development" do
|
366
217
|
before(:each) do
|
367
|
-
SimpleNavigation.
|
218
|
+
SimpleNavigation.stub!(:environment => 'development')
|
368
219
|
end
|
369
220
|
it "should load the config file twice" do
|
370
221
|
IO.should_receive(:read).twice
|
@@ -373,9 +224,9 @@ describe SimpleNavigation do
|
|
373
224
|
end
|
374
225
|
end
|
375
226
|
|
376
|
-
context "
|
227
|
+
context "environment=test" do
|
377
228
|
before(:each) do
|
378
|
-
SimpleNavigation.
|
229
|
+
SimpleNavigation.stub!(:environment => 'test')
|
379
230
|
end
|
380
231
|
it "should load the config file twice" do
|
381
232
|
IO.should_receive(:read).twice
|
@@ -390,59 +241,10 @@ describe SimpleNavigation do
|
|
390
241
|
end
|
391
242
|
end
|
392
243
|
|
393
|
-
describe 'request' do
|
394
|
-
context 'template is set' do
|
395
|
-
before(:each) do
|
396
|
-
@request = stub(:request)
|
397
|
-
SimpleNavigation.stub!(:template => stub(:template, :request => @request))
|
398
|
-
end
|
399
|
-
it {SimpleNavigation.request.should == @request}
|
400
|
-
end
|
401
|
-
context 'template is not set' do
|
402
|
-
it {SimpleNavigation.request.should be_nil}
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
describe 'request_uri' do
|
407
|
-
context 'request is set' do
|
408
|
-
context 'fullpath is defined on request' do
|
409
|
-
before(:each) do
|
410
|
-
@request = stub(:request, :fullpath => '/fullpath')
|
411
|
-
SimpleNavigation.stub!(:request => @request)
|
412
|
-
end
|
413
|
-
it {SimpleNavigation.request_uri.should == '/fullpath'}
|
414
|
-
end
|
415
|
-
context 'fullpath is not defined on request' do
|
416
|
-
before(:each) do
|
417
|
-
@request = stub(:request, :request_uri => '/request_uri')
|
418
|
-
SimpleNavigation.stub!(:request => @request)
|
419
|
-
end
|
420
|
-
it {SimpleNavigation.request_uri.should == '/request_uri'}
|
421
|
-
end
|
422
|
-
end
|
423
|
-
context 'request is not set' do
|
424
|
-
before(:each) do
|
425
|
-
SimpleNavigation.stub!(:request => nil)
|
426
|
-
end
|
427
|
-
it {SimpleNavigation.request_uri.should == ''}
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
244
|
describe 'config' do
|
432
245
|
it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
|
433
246
|
end
|
434
247
|
|
435
|
-
describe 'current_navigation_for' do
|
436
|
-
before(:each) do
|
437
|
-
@controller = stub(:controller)
|
438
|
-
SimpleNavigation.stub!(:controller => @controller)
|
439
|
-
end
|
440
|
-
it "should access the correct instance_var in the controller" do
|
441
|
-
@controller.should_receive(:instance_variable_get).with(:@sn_current_navigation_1)
|
442
|
-
SimpleNavigation.current_navigation_for(1)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
248
|
describe 'active_item_container_for' do
|
447
249
|
before(:each) do
|
448
250
|
@primary = stub(:primary)
|
@@ -472,77 +274,28 @@ describe SimpleNavigation do
|
|
472
274
|
end
|
473
275
|
end
|
474
276
|
|
475
|
-
describe '
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
before(:each) do
|
481
|
-
@controller = stub(:controller)
|
482
|
-
SimpleNavigation.stub!(:controller => @controller)
|
483
|
-
end
|
484
|
-
|
485
|
-
context 'with explicit navigation set' do
|
486
|
-
context 'list of navigations' do
|
487
|
-
before(:each) do
|
488
|
-
args :first, :second, :third
|
489
|
-
end
|
490
|
-
it "should set the correct instance var in the controller" do
|
491
|
-
@controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_3, :third)
|
492
|
-
SimpleNavigation.handle_explicit_navigation
|
493
|
-
end
|
494
|
-
end
|
495
|
-
context 'single navigation' do
|
496
|
-
context 'specified key is a valid navigation item' do
|
497
|
-
before(:each) do
|
498
|
-
@primary = stub(:primary, :level_for_item => 2)
|
499
|
-
SimpleNavigation.stub!(:primary_navigation => @primary)
|
500
|
-
args :key
|
501
|
-
end
|
502
|
-
it "should set the correct instance var in the controller" do
|
503
|
-
@controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
|
504
|
-
SimpleNavigation.handle_explicit_navigation
|
505
|
-
end
|
506
|
-
end
|
507
|
-
context 'specified key is an invalid navigation item' do
|
508
|
-
before(:each) do
|
509
|
-
@primary = stub(:primary, :level_for_item => nil)
|
510
|
-
SimpleNavigation.stub!(:primary_navigation => @primary)
|
511
|
-
args :key
|
512
|
-
end
|
513
|
-
it "should not raise an ArgumentError" do
|
514
|
-
lambda {SimpleNavigation.handle_explicit_navigation}.should_not raise_error(ArgumentError)
|
515
|
-
end
|
516
|
-
end
|
517
|
-
end
|
518
|
-
context 'hash with level' do
|
519
|
-
before(:each) do
|
520
|
-
args :level_2 => :key
|
521
|
-
end
|
522
|
-
it "should set the correct instance var in the controller" do
|
523
|
-
@controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
|
524
|
-
SimpleNavigation.handle_explicit_navigation
|
525
|
-
end
|
526
|
-
end
|
527
|
-
context 'hash with multiple_levels' do
|
528
|
-
before(:each) do
|
529
|
-
args :level_2 => :key, :level_1 => :bla
|
530
|
-
end
|
531
|
-
it "should set the correct instance var in the controller" do
|
532
|
-
@controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
|
533
|
-
SimpleNavigation.handle_explicit_navigation
|
534
|
-
end
|
277
|
+
describe 'load_adapter' do
|
278
|
+
context 'Rails' do
|
279
|
+
before(:each) do
|
280
|
+
SimpleNavigation.stub!(:framework => :rails)
|
281
|
+
SimpleNavigation.load_adapter
|
535
282
|
end
|
283
|
+
it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Rails}
|
536
284
|
end
|
537
|
-
context '
|
285
|
+
context 'Padrino' do
|
538
286
|
before(:each) do
|
539
|
-
|
287
|
+
SimpleNavigation.stub!(:framework => :padrino)
|
288
|
+
SimpleNavigation.load_adapter
|
540
289
|
end
|
541
|
-
it
|
542
|
-
|
543
|
-
|
290
|
+
it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Padrino}
|
291
|
+
end
|
292
|
+
context 'Sinatra' do
|
293
|
+
before(:each) do
|
294
|
+
SimpleNavigation.stub!(:framework => :sinatra)
|
295
|
+
SimpleNavigation.load_adapter
|
544
296
|
end
|
297
|
+
it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Sinatra}
|
545
298
|
end
|
546
299
|
end
|
547
|
-
|
300
|
+
|
548
301
|
end
|