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.
Files changed (46) hide show
  1. data/CHANGELOG +14 -4
  2. data/README +1 -2
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +4 -4
  5. data/generators/navigation_config/templates/config/navigation.rb +14 -14
  6. data/lib/simple_navigation.rb +69 -151
  7. data/lib/simple_navigation/adapters.rb +9 -0
  8. data/lib/simple_navigation/adapters/base.rb +37 -0
  9. data/lib/simple_navigation/adapters/padrino.rb +20 -0
  10. data/lib/simple_navigation/adapters/rails.rb +93 -0
  11. data/lib/simple_navigation/adapters/sinatra.rb +76 -0
  12. data/lib/simple_navigation/core.rb +5 -0
  13. data/lib/simple_navigation/{configuration.rb → core/configuration.rb} +14 -19
  14. data/lib/simple_navigation/{item.rb → core/item.rb} +10 -11
  15. data/lib/simple_navigation/{item_adapter.rb → core/item_adapter.rb} +11 -7
  16. data/lib/simple_navigation/{item_container.rb → core/item_container.rb} +14 -21
  17. data/lib/simple_navigation/{items_provider.rb → core/items_provider.rb} +7 -7
  18. data/lib/simple_navigation/{controller_methods.rb → rails_controller_methods.rb} +67 -5
  19. data/lib/simple_navigation/rendering.rb +10 -0
  20. data/lib/simple_navigation/{helpers.rb → rendering/helpers.rb} +16 -18
  21. data/lib/simple_navigation/{renderer → rendering/renderer}/base.rb +20 -37
  22. data/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs.rb +7 -7
  23. data/lib/simple_navigation/{renderer → rendering/renderer}/links.rb +7 -7
  24. data/lib/simple_navigation/{renderer → rendering/renderer}/list.rb +6 -6
  25. data/rails/init.rb +1 -5
  26. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +29 -0
  27. data/spec/lib/simple_navigation/adapters/rails_spec.rb +269 -0
  28. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +60 -0
  29. data/spec/lib/simple_navigation/{configuration_spec.rb → core/configuration_spec.rb} +7 -18
  30. data/spec/lib/simple_navigation/{item_adapter_spec.rb → core/item_adapter_spec.rb} +11 -11
  31. data/spec/lib/simple_navigation/{item_container_spec.rb → core/item_container_spec.rb} +29 -46
  32. data/spec/lib/simple_navigation/{item_spec.rb → core/item_spec.rb} +30 -64
  33. data/spec/lib/simple_navigation/{items_provider_spec.rb → core/items_provider_spec.rb} +7 -7
  34. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +251 -0
  35. data/spec/lib/simple_navigation/{helpers_spec.rb → rendering/helpers_spec.rb} +34 -53
  36. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/base_spec.rb +11 -62
  37. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs_spec.rb +9 -51
  38. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +59 -0
  39. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/list_spec.rb +17 -58
  40. data/spec/lib/simple_navigation_spec.rb +51 -298
  41. data/spec/spec_helper.rb +16 -5
  42. metadata +67 -48
  43. data/lib/simple_navigation/initializer.rb +0 -21
  44. data/lib/simple_navigation/railtie.rb +0 -7
  45. data/spec/lib/simple_navigation/controller_methods_spec.rb +0 -90
  46. data/spec/lib/simple_navigation/renderer/links_spec.rb +0 -121
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe SimpleNavigation::Adapters::Padrino do
4
+
5
+ def create_adapter
6
+ SimpleNavigation::Adapters::Padrino.new(@context)
7
+ end
8
+
9
+ before(:each) do
10
+ @request = stub(:request)
11
+ @context = stub(:context, :request => @request)
12
+ @adapter = create_adapter
13
+ end
14
+
15
+ describe 'link_to' do
16
+ it "should delegate to context" do
17
+ @context.should_receive(:link_to).with('name', 'url', :my_option => true)
18
+ @adapter.link_to('name', 'url', :my_option => true)
19
+ end
20
+ end
21
+
22
+ describe 'content_tag' do
23
+ it "should delegate to context" do
24
+ @context.should_receive(:content_tag).with('type', 'content', :my_option => true)
25
+ @adapter.content_tag('type', 'content', :my_option => true)
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,269 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe SimpleNavigation::Adapters::Rails do
4
+
5
+ def create_adapter
6
+ SimpleNavigation::Adapters::Rails.new(@context)
7
+ end
8
+
9
+ before(:each) do
10
+ @context = stub(:context)
11
+ @controller = stub(:controller)
12
+ @context.stub!(:controller => @controller)
13
+ @request = stub(:request)
14
+ @template = stub(:template, :request => @request)
15
+ @adapter = create_adapter
16
+ end
17
+
18
+ describe 'self.register' do
19
+ before(:each) do
20
+ ActionController::Base.stub!(:include)
21
+ end
22
+ it "should call set_env" do
23
+ SimpleNavigation.should_receive(:set_env).with('./', 'test')
24
+ SimpleNavigation.register
25
+ end
26
+ it "should extend the ActionController::Base with the Helpers" do
27
+ ActionController::Base.should_receive(:include).with(SimpleNavigation::Helpers)
28
+ SimpleNavigation.register
29
+ end
30
+ it "should install the helper methods in the controller" do
31
+ ActionController::Base.should_receive(:helper_method).with(:render_navigation)
32
+ SimpleNavigation.register
33
+ end
34
+
35
+ end
36
+
37
+ describe 'initialize' do
38
+ context 'regarding setting the request' do
39
+ context 'template is present' do
40
+ before(:each) do
41
+ @controller.stub!(:instance_variable_get => @template)
42
+ @adapter = create_adapter
43
+ end
44
+ it {@adapter.request.should == @request}
45
+ end
46
+ context 'template is not present' do
47
+ before(:each) do
48
+ @controller.stub!(:instance_variable_get => nil)
49
+ end
50
+ it {@adapter.request.should be_nil}
51
+ end
52
+ end
53
+ context 'regarding setting the controller' do
54
+ it "should set the controller" do
55
+ @adapter.controller.should == @controller
56
+ end
57
+ end
58
+ context 'regarding setting the template' do
59
+ context 'template is stored in controller as instance_var (Rails2)' do
60
+ context 'template is set' do
61
+ before(:each) do
62
+ @controller.stub!(:instance_variable_get => @template)
63
+ @adapter = create_adapter
64
+ end
65
+ it {@adapter.template.should == @template}
66
+ end
67
+ context 'template is not set' do
68
+ before(:each) do
69
+ @controller.stub!(:instance_variable_get => nil)
70
+ @adapter = create_adapter
71
+ end
72
+ it {@adapter.template.should be_nil}
73
+ end
74
+ end
75
+ context 'template is stored in controller as view_context (Rails3)' do
76
+ context 'template is set' do
77
+ before(:each) do
78
+ @controller.stub!(:view_context => @template)
79
+ @adapter = create_adapter
80
+ end
81
+ it {@adapter.template.should == @template}
82
+ end
83
+ context 'template is not set' do
84
+ before(:each) do
85
+ @controller.stub!(:view_context => nil)
86
+ @adapter = create_adapter
87
+ end
88
+ it {@adapter.template.should be_nil}
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ describe 'request_uri' do
95
+ context 'request is set' do
96
+ context 'fullpath is defined on request' do
97
+ before(:each) do
98
+ @request = stub(:request, :fullpath => '/fullpath')
99
+ @adapter.stub!(:request => @request)
100
+ end
101
+ it {@adapter.request_uri.should == '/fullpath'}
102
+ end
103
+ context 'fullpath is not defined on request' do
104
+ before(:each) do
105
+ @request = stub(:request, :request_uri => '/request_uri')
106
+ @adapter.stub!(:request => @request)
107
+ end
108
+ it {@adapter.request_uri.should == '/request_uri'}
109
+ end
110
+ end
111
+ context 'request is not set' do
112
+ before(:each) do
113
+ @adapter.stub!(:request => nil)
114
+ end
115
+ it {@adapter.request_uri.should == ''}
116
+ end
117
+ end
118
+
119
+ describe 'request_path' do
120
+ context 'request is set' do
121
+ before(:each) do
122
+ @request = stub(:request, :path => '/request_path')
123
+ @adapter.stub!(:request => @request)
124
+ end
125
+ it {@adapter.request_path.should == '/request_path'}
126
+ end
127
+ context 'request is not set' do
128
+ before(:each) do
129
+ @adapter.stub!(:request => nil)
130
+ end
131
+ it {@adapter.request_path.should == ''}
132
+ end
133
+ end
134
+
135
+ describe 'context_for_eval' do
136
+ context 'controller is present' do
137
+ before(:each) do
138
+ @controller = stub(:controller)
139
+ @adapter.instance_variable_set(:@controller, @controller)
140
+ end
141
+ context 'template is present' do
142
+ before(:each) do
143
+ @template = stub(:template)
144
+ @adapter.instance_variable_set(:@template, @template)
145
+ end
146
+ it {@adapter.context_for_eval.should == @template}
147
+ end
148
+ context 'template is not present' do
149
+ before(:each) do
150
+ @adapter.instance_variable_set(:@template, nil)
151
+ end
152
+ it {@adapter.context_for_eval.should == @controller}
153
+ end
154
+ end
155
+ context 'controller is not present' do
156
+ before(:each) do
157
+ @adapter.instance_variable_set(:@controller, nil)
158
+ end
159
+ context 'template is present' do
160
+ before(:each) do
161
+ @template = stub(:template)
162
+ @adapter.instance_variable_set(:@template, @template)
163
+ end
164
+ it {@adapter.context_for_eval.should == @template}
165
+ end
166
+ context 'template is not present' do
167
+ before(:each) do
168
+ @adapter.instance_variable_set(:@template, nil)
169
+ end
170
+ it {lambda {@adapter.context_for_eval}.should raise_error}
171
+ end
172
+ end
173
+ end
174
+
175
+ describe 'current_page?' do
176
+ context 'template is set' do
177
+ before(:each) do
178
+ @adapter.stub!(:template => @template)
179
+ end
180
+ it "should delegate the call to the template" do
181
+ @template.should_receive(:current_page?).with(:page)
182
+ @adapter.current_page?(:page)
183
+ end
184
+ end
185
+ context 'template is not set' do
186
+ before(:each) do
187
+ @adapter.stub!(:template => nil)
188
+ end
189
+ it {@adapter.should_not be_current_page(:page)}
190
+ end
191
+ end
192
+
193
+ describe 'link_to' do
194
+ context 'template is set' do
195
+ before(:each) do
196
+ @adapter.stub!(:template => @template)
197
+ @adapter.stub!(:html_safe => 'safe_text')
198
+ @options = stub(:options)
199
+ end
200
+ it "should delegate the call to the template (with html_safe text)" do
201
+ @template.should_receive(:link_to).with('safe_text', 'url', @options)
202
+ @adapter.link_to('text', 'url', @options)
203
+ end
204
+ end
205
+ context 'template is not set' do
206
+ before(:each) do
207
+ @adapter.stub!(:template => nil)
208
+ end
209
+ it {@adapter.link_to('text', 'url', @options).should be_nil}
210
+ end
211
+ end
212
+
213
+ describe 'content_tag' do
214
+ context 'template is set' do
215
+ before(:each) do
216
+ @adapter.stub!(:template => @template)
217
+ @adapter.stub!(:html_safe => 'safe_text')
218
+ @options = stub(:options)
219
+ end
220
+ it "should delegate the call to the template (with html_safe text)" do
221
+ @template.should_receive(:content_tag).with(:div, 'safe_text', @options)
222
+ @adapter.content_tag(:div, 'text', @options)
223
+ end
224
+ end
225
+ context 'template is not set' do
226
+ before(:each) do
227
+ @adapter.stub!(:template => nil)
228
+ end
229
+ it {@adapter.content_tag(:div, 'text', @options).should be_nil}
230
+ end
231
+ end
232
+
233
+ describe 'self.extract_controller_from' do
234
+ context 'object responds to controller' do
235
+ before(:each) do
236
+ @context.stub!(:controller => @controller)
237
+ end
238
+ it "should return the controller" do
239
+ @adapter.send(:extract_controller_from, @context).should == @controller
240
+ end
241
+ end
242
+ context 'object does not respond to controller' do
243
+ before(:each) do
244
+ @context = stub(:context)
245
+ end
246
+ it "should return the context" do
247
+ @adapter.send(:extract_controller_from, @context).should == @context
248
+ end
249
+ end
250
+ end
251
+
252
+ describe 'html_safe' do
253
+ before(:each) do
254
+ @input = stub :input
255
+ end
256
+ context 'input does respond to html_safe' do
257
+ before(:each) do
258
+ @safe = stub :safe
259
+ @input.stub!(:html_safe => @safe)
260
+ end
261
+ it {@adapter.send(:html_safe, @input).should == @safe}
262
+ end
263
+ context 'input does not respond to html_safe' do
264
+ it {@adapter.send(:html_safe, @input).should == @input}
265
+ end
266
+ end
267
+
268
+
269
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe SimpleNavigation::Adapters::Sinatra do
4
+
5
+ def create_adapter
6
+ SimpleNavigation::Adapters::Sinatra.new(@context)
7
+ end
8
+
9
+ before(:each) do
10
+ @context = stub(:context)
11
+ @request = stub(:request, :fullpath => '/full?param=true', :path => '/full')
12
+ @context.stub!(:request => @request)
13
+ @adapter = create_adapter
14
+ end
15
+
16
+ describe 'context_for_eval' do
17
+ it "should raise error if no context" do
18
+ @adapter.stub!(:context => nil)
19
+ lambda {@adapter.context_for_eval}.should raise_error
20
+ end
21
+ it "should return the context" do
22
+ @adapter.context_for_eval.should == @context
23
+ end
24
+ end
25
+
26
+ describe 'request_uri' do
27
+ it {@adapter.request_uri.should == '/full?param=true'}
28
+ end
29
+
30
+ describe 'request_path' do
31
+ it {@adapter.request_path.should == '/full'}
32
+ end
33
+
34
+ describe 'current_page?' do
35
+ before(:each) do
36
+ @request.stub!(:protocol => 'http://', :host_with_port => 'my_host:5000')
37
+ end
38
+ it {@adapter.current_page?('/full?param=true').should be_true}
39
+ it {@adapter.current_page?('/full?param3=true').should be_false}
40
+ it {@adapter.current_page?('/full').should be_true}
41
+ it {@adapter.current_page?('http://my_host:5000/full?param=true').should be_true}
42
+ it {@adapter.current_page?('http://my_host:5000/full?param3=true').should be_false}
43
+ it {@adapter.current_page?('http://my_host:5000/full').should be_true}
44
+ it {@adapter.current_page?('http://my_host:6000/full').should be_false}
45
+ it {@adapter.current_page?('http://my_other_host:5000/full').should be_false}
46
+ end
47
+
48
+ describe 'link_to' do
49
+ it "should return a link" do
50
+ @adapter.link_to('link', 'url', :class => 'clazz', :id => 'id').should == "<a href='url' class='clazz' id='id'>link</a>"
51
+ end
52
+ end
53
+
54
+ describe 'content_tag' do
55
+ it "should return a tag" do
56
+ @adapter.content_tag(:div, 'content', :class => 'clazz', :id => 'id').should == "<div class='clazz' id='id'>content</div>"
57
+ end
58
+ end
59
+
60
+ end
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Configuration do
4
-
4
+
5
5
  before(:each) do
6
6
  @config = SimpleNavigation::Configuration.instance
7
7
  end
8
-
8
+
9
9
  describe 'self.run' do
10
10
  it "should yield the singleton Configuration object" do
11
11
  SimpleNavigation::Configuration.run do |c|
@@ -25,21 +25,17 @@ describe SimpleNavigation::Configuration do
25
25
  context "with default navigation context" do
26
26
  it "should instance_eval the default config_file-string inside the context" do
27
27
  @context.should_receive(:instance_eval).with('default')
28
- SimpleNavigation::Configuration.eval_config(@context)
28
+ SimpleNavigation::Configuration.eval_config
29
29
  end
30
30
  end
31
31
  context 'with non default navigation context' do
32
32
  it "should instance_eval the specified config_file-string inside the context" do
33
33
  @context.should_receive(:instance_eval).with('my_context')
34
- SimpleNavigation::Configuration.eval_config(@context, :my_context)
34
+ SimpleNavigation::Configuration.eval_config(:my_context)
35
35
  end
36
36
  end
37
- it "should set the template from the specified context" do
38
- SimpleNavigation.should_receive(:set_template_from).with(@context)
39
- SimpleNavigation::Configuration.eval_config(@context, :my_context)
40
- end
41
37
  end
42
-
38
+
43
39
  describe 'initialize' do
44
40
  it "should set the List-Renderer as default upon initialize" do
45
41
  @config.renderer.should == SimpleNavigation::Renderer::List
@@ -56,7 +52,7 @@ describe SimpleNavigation::Configuration do
56
52
  it "should set the id_generator" do
57
53
  @config.id_generator.should_not be_nil
58
54
  end
59
- end
55
+ end
60
56
  describe 'items' do
61
57
  before(:each) do
62
58
  @container = stub(:items_container)
@@ -130,13 +126,6 @@ describe SimpleNavigation::Configuration do
130
126
  end
131
127
  end
132
128
 
133
- describe 'context_for_eval' do
134
- it "should delegate to the Configuration class" do
135
- @config.class.should_receive(:context_for_eval)
136
- @config.context_for_eval
137
- end
138
- end
139
-
140
129
  end
141
130
 
142
131
 
@@ -1,39 +1,39 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
2
 
3
3
  describe SimpleNavigation::ItemAdapter do
4
-
4
+
5
5
  before(:each) do
6
6
  @item = stub(:item)
7
7
  @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
8
8
  end
9
-
9
+
10
10
  describe 'key' do
11
11
  it "should delegate key to item" do
12
12
  @item.should_receive(:key)
13
13
  @item_adapter.key
14
14
  end
15
- end
16
-
15
+ end
16
+
17
17
  describe 'url' do
18
18
  it "should delegate url to item" do
19
19
  @item.should_receive(:url)
20
20
  @item_adapter.url
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe 'name' do
25
25
  it "should delegate name to item" do
26
26
  @item.should_receive(:name)
27
27
  @item_adapter.name
28
28
  end
29
29
  end
30
-
30
+
31
31
  describe 'initialize' do
32
32
  it "should set the item" do
33
33
  @item_adapter.item.should == @item
34
34
  end
35
35
  end
36
-
36
+
37
37
  describe 'options' do
38
38
  context 'item does respond to options' do
39
39
  before(:each) do
@@ -50,7 +50,7 @@ describe SimpleNavigation::ItemAdapter do
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  describe 'items' do
55
55
  context 'item does respond to items' do
56
56
  context 'items is nil' do
@@ -87,7 +87,7 @@ describe SimpleNavigation::ItemAdapter do
87
87
  end
88
88
  end
89
89
  end
90
-
90
+
91
91
  describe 'to_simple_navigation_item' do
92
92
  before(:each) do
93
93
  @container = stub(:container)
@@ -98,5 +98,5 @@ describe SimpleNavigation::ItemAdapter do
98
98
  @item_adapter.to_simple_navigation_item(@container)
99
99
  end
100
100
  end
101
-
101
+
102
102
  end