nav_lynx 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.md +29 -1
  3. data/Rakefile +1 -0
  4. data/app/helpers/nav_link_helper.rb +57 -46
  5. data/lib/nav_lynx/engine.rb +6 -0
  6. data/lib/nav_lynx/version.rb +1 -1
  7. data/lib/nav_lynx.rb +3 -2
  8. data/spec/dummy/config/application.rb +1 -11
  9. data/spec/dummy/config/boot.rb +3 -7
  10. data/spec/dummy/config/environments/development.rb +0 -7
  11. data/spec/dummy/config/environments/test.rb +2 -3
  12. data/spec/dummy/db/test.sqlite3 +0 -0
  13. data/spec/dummy/log/development.log +139 -0
  14. data/spec/dummy/log/test.log +1818 -0
  15. data/spec/dummy/tmp/cache/assets/test/sprockets/061366614f53b2e629f4ce5af7376503 +0 -0
  16. data/spec/dummy/tmp/cache/assets/test/sprockets/12e93292435b9fd9a8ead1d08efcc40b +0 -0
  17. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  18. data/spec/dummy/tmp/cache/assets/test/sprockets/16813814f2e3c416d514746de8977f71 +0 -0
  19. data/spec/dummy/tmp/cache/assets/test/sprockets/20bdd97a4de949dfc1ccc5b4881d5de6 +0 -0
  20. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  21. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/52ef98542a240e988c164c670087be82 +0 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/8528046f7875341a083dca3a0349725a +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/a45664b91391c11181b20e5903d4aa8f +0 -0
  25. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  26. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  27. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  28. data/spec/dummy/tmp/cache/assets/test/sprockets/fe314a8ef926518b95394d23d7967ac4 +0 -0
  29. data/spec/helpers/nav_link_helper_spec.rb +44 -26
  30. data/spec/spec_helper.rb +1 -0
  31. metadata +67 -7
@@ -11,14 +11,14 @@ describe NavLinkHelper do
11
11
  before { helper.stub(:request => :request) }
12
12
 
13
13
  it 'accepts only a title and a path' do
14
- NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
14
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", controller, {}, {})
15
15
  .and_return(link_generator)
16
16
 
17
17
  helper.nav_link_to("My Title", "/path")
18
18
  end
19
19
 
20
20
  it 'accepts a block that returns the title' do
21
- NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
21
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", controller, {}, {})
22
22
  .and_return(link_generator)
23
23
 
24
24
  helper.nav_link_to("/path") do
@@ -27,88 +27,97 @@ describe NavLinkHelper do
27
27
  end
28
28
 
29
29
  it "accepts options and html_options parameters" do
30
- NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", :html_options, :options)
30
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", controller, :html_options, :options)
31
31
  .and_return(link_generator)
32
32
 
33
33
  helper.nav_link_to("My Title", "/path", :html_options, :options)
34
34
  end
35
35
  end
36
36
 
37
- require 'spec_helper'
38
-
39
37
  describe NavLinkHelper::LinkGenerator do
40
38
  describe '#to_html' do
41
39
  subject { described_class::LinkGenerator }
42
40
  let(:request){ helper.request }
41
+ after { NavLYNX.selected_class = 'selected' }
43
42
 
44
43
  it "outputs a simple link when appropriate" do
45
- subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
44
+ subject.new(request, 'Hi', '/projects', controller).to_html.should == '<a href="/projects">Hi</a>'
45
+ end
46
+
47
+ it "accepts a hash for the URL parameter" do
48
+ subject.new(request, 'Hi', {:controller => 'projects', :action => 'index'}, controller).to_html.should == '<a href="/projects">Hi</a>'
46
49
  end
47
50
 
48
51
  it "knows when to flag the link as current" do
49
52
  request.stub(:fullpath).and_return('/projects')
50
- subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects" class="selected">Hi</a>'
53
+ subject.new(request, 'Hi', '/projects', controller).to_html.should have_tag("a.selected[href='/projects']", :text => "Hi")
54
+ end
55
+
56
+ it "knows use a globally defined selected class different from the default" do
57
+ NavLYNX.selected_class = 'current'
58
+ request.stub(:fullpath).and_return('/projects')
59
+ subject.new(request, 'Hi', '/projects', controller).to_html.should have_tag("a.current[href='/projects']", :text => "Hi")
51
60
  end
52
61
 
53
62
  it "does not flag the link as current if there are parameters in the path" do
54
63
  request.stub(:fullpath).and_return('/projects?all=true')
55
- subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
64
+ subject.new(request, 'Hi', '/projects', controller).to_html.should == '<a href="/projects">Hi</a>'
56
65
  end
57
66
 
58
67
  it "flags the link as selected if there are parameters in the path but we are ignoring parameters" do
59
68
  request.stub(:fullpath).and_return('/projects?all=true')
60
- subject.new(request, 'Hi', '/projects', {}, :ignore_params => true).to_html
61
- .should == '<a href="/projects" class="selected">Hi</a>'
69
+ subject.new(request, 'Hi', '/projects', controller, {}, {:ignore_params => true}).to_html
70
+ .should have_tag("a.selected[href='/projects']", :text => "Hi")
62
71
  end
63
72
 
64
73
  it "allows the specification of an alternate selected class" do
65
74
  request.stub(:fullpath).and_return('/projects')
66
- subject.new(request, 'Hi', '/projects', {}, :selected_class => 'current').to_html
67
- .should == '<a href="/projects" class="current">Hi</a>'
75
+ subject.new(request, 'Hi', '/projects', controller, {}, {:selected_class => 'current'}).to_html
76
+ .should have_tag("a.current[href='/projects']", :text => "Hi")
68
77
  end
69
78
 
70
79
  it "generates a wrapper for the link when specified" do
71
- subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li').to_html
80
+ subject.new(request, 'Hi', '/projects', controller, {}, {:wrapper => 'li'}).to_html
72
81
  .should == '<li><a href="/projects">Hi</a></li>'
73
82
  end
74
83
 
75
84
  it "provides a class for the wrapper when specified" do
76
- subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
85
+ subject.new(request, 'Hi', '/projects', controller, {}, {:wrapper => 'li', :wrapper_class => 'container'}).to_html
77
86
  .should == '<li class="container"><a href="/projects">Hi</a></li>'
78
87
  end
79
88
 
80
89
  it "provides a class for the wrapper when specified along with a selected class if neeeded" do
81
90
  request.stub(:fullpath).and_return('/projects')
82
- subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
91
+ subject.new(request, 'Hi', '/projects', controller, {}, {:wrapper => 'li', :wrapper_class => 'container'}).to_html
83
92
  .should == '<li class="selected container"><a href="/projects">Hi</a></li>'
84
93
  end
85
94
 
86
95
  it "allows specification of the link classes" do
87
- subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
88
- .should == '<a href="/projects" class="one two">Hi</a>'
96
+ subject.new(request, 'Hi', '/projects', controller, {:class => 'one two'}, {}).to_html
97
+ .should have_tag("a.one.two[href='/projects']", :text => "Hi")
89
98
  end
90
99
 
91
100
  it "combines custom link classes when the link is selected" do
92
101
  request.stub(:fullpath).and_return('/projects')
93
- subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
94
- .should == '<a href="/projects" class="one two selected">Hi</a>'
102
+ subject.new(request, 'Hi', '/projects', controller, {:class => 'one two'}, {}).to_html
103
+ .should have_tag("a.selected.one.two[href='/projects']", :text => "Hi")
95
104
  end
96
105
 
97
106
  it "ignores the ID in the path when provided with a segment" do
98
107
  request.stub(:fullpath).and_return('/projects/2')
99
- subject.new(request, 'Hi', '/projects', {}, :url_segment => 1).to_html
100
- .should == '<a href="/projects" class="selected">Hi</a>'
108
+ subject.new(request, 'Hi', '/projects', controller, {}, {:url_segment => 1}).to_html
109
+ .should have_tag("a.selected[href='/projects']", :text => "Hi")
101
110
  end
102
111
 
103
112
  it "handles deep URL segments" do
104
113
  request.stub(:fullpath).and_return('/projects/2/3')
105
- subject.new(request, 'Hi', '/projects/2', {}, :url_segment => 2).to_html
106
- .should == '<a href="/projects/2" class="selected">Hi</a>'
114
+ subject.new(request, 'Hi', '/projects/2', controller, {}, {:url_segment => 2}).to_html
115
+ .should have_tag("a.selected[href='/projects/2']", :text => "Hi")
107
116
  end
108
117
 
109
118
  it "knows to not match on the first segment when requested" do
110
119
  request.stub(:fullpath).and_return('/projects/2/3')
111
- subject.new(request, 'Hi', '/projects/1', {}, :url_segment => 2).to_html
120
+ subject.new(request, 'Hi', '/projects/1', controller, {}, {:url_segment => 2}).to_html
112
121
  .should == '<a href="/projects/1">Hi</a>'
113
122
  end
114
123
 
@@ -119,8 +128,17 @@ describe NavLinkHelper do
119
128
  request.stub(:fullpath).and_return('/members/pages/1')
120
129
  request.stub(:path).and_return('/members/pages/1')
121
130
 
122
- subject.new(request, 'Hi', '/members/1', {}, :controller_segment => 1).to_html
123
- .should == '<a href="/members/1" class="selected">Hi</a>'
131
+ subject.new(request, 'Hi', '/members/1', controller, {}, {:controller_segment => 1}).to_html
132
+ .should have_tag("a.selected[href='/members/1']", :text => "Hi")
133
+ end
134
+
135
+ it "handles the case when the current request path is a POST route & has no GET route" do
136
+ # scenario where a route exists only for POST, so GET fails
137
+ Rails.application.routes.stub(:recognize_path).with('/projects/something').and_raise(ActionController::RoutingError.new("No route matches '/projects'"))
138
+ Rails.application.routes.stub(:recognize_path).with('/projects').and_return(:controller => 'projects', :action => 'index')
139
+
140
+ request.stub(:fullpath => '/projects/something', :path => '/projects/something')
141
+ subject.new(request, 'Hi', '/projects', controller).to_html.should == '<a href="/projects">Hi</a>'
124
142
  end
125
143
  end
126
144
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test'
3
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
+ require 'rspec-html-matchers'
6
7
 
7
8
  Rails.backtrace_cleaner.remove_silencers!
8
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nav_lynx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,14 +11,14 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-06-12 00:00:00.000000000 Z
14
+ date: 2013-11-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
23
  version: 3.2.13
24
24
  type: :runtime
@@ -26,7 +26,7 @@ dependencies:
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  none: false
28
28
  requirements:
29
- - - ~>
29
+ - - ! '>='
30
30
  - !ruby/object:Gem::Version
31
31
  version: 3.2.13
32
32
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,38 @@ dependencies:
77
77
  - - ! '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: appraisal
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rspec-html-matchers
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
80
112
  description: Rails helper to generate navigation links with a selected class.
81
113
  email:
82
114
  - dan.tello@viget.com
@@ -129,6 +161,20 @@ files:
129
161
  - spec/dummy/public/500.html
130
162
  - spec/dummy/public/favicon.ico
131
163
  - spec/dummy/script/rails
164
+ - spec/dummy/tmp/cache/assets/test/sprockets/061366614f53b2e629f4ce5af7376503
165
+ - spec/dummy/tmp/cache/assets/test/sprockets/12e93292435b9fd9a8ead1d08efcc40b
166
+ - spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
167
+ - spec/dummy/tmp/cache/assets/test/sprockets/16813814f2e3c416d514746de8977f71
168
+ - spec/dummy/tmp/cache/assets/test/sprockets/20bdd97a4de949dfc1ccc5b4881d5de6
169
+ - spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
170
+ - spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
171
+ - spec/dummy/tmp/cache/assets/test/sprockets/52ef98542a240e988c164c670087be82
172
+ - spec/dummy/tmp/cache/assets/test/sprockets/8528046f7875341a083dca3a0349725a
173
+ - spec/dummy/tmp/cache/assets/test/sprockets/a45664b91391c11181b20e5903d4aa8f
174
+ - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
175
+ - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
176
+ - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
177
+ - spec/dummy/tmp/cache/assets/test/sprockets/fe314a8ef926518b95394d23d7967ac4
132
178
  - spec/features/navigation_spec.rb
133
179
  - spec/helpers/nav_link_helper_spec.rb
134
180
  - spec/spec_helper.rb
@@ -146,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
192
  version: '0'
147
193
  segments:
148
194
  - 0
149
- hash: -3753548243184339803
195
+ hash: 3905832851249229231
150
196
  required_rubygems_version: !ruby/object:Gem::Requirement
151
197
  none: false
152
198
  requirements:
@@ -155,10 +201,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
201
  version: '0'
156
202
  segments:
157
203
  - 0
158
- hash: -3753548243184339803
204
+ hash: 3905832851249229231
159
205
  requirements: []
160
206
  rubyforge_project:
161
- rubygems_version: 1.8.21
207
+ rubygems_version: 1.8.25
162
208
  signing_key:
163
209
  specification_version: 3
164
210
  summary: Rails helper to generate navigation links with a selected class.
@@ -199,6 +245,20 @@ test_files:
199
245
  - spec/dummy/public/500.html
200
246
  - spec/dummy/public/favicon.ico
201
247
  - spec/dummy/script/rails
248
+ - spec/dummy/tmp/cache/assets/test/sprockets/061366614f53b2e629f4ce5af7376503
249
+ - spec/dummy/tmp/cache/assets/test/sprockets/12e93292435b9fd9a8ead1d08efcc40b
250
+ - spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
251
+ - spec/dummy/tmp/cache/assets/test/sprockets/16813814f2e3c416d514746de8977f71
252
+ - spec/dummy/tmp/cache/assets/test/sprockets/20bdd97a4de949dfc1ccc5b4881d5de6
253
+ - spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
254
+ - spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
255
+ - spec/dummy/tmp/cache/assets/test/sprockets/52ef98542a240e988c164c670087be82
256
+ - spec/dummy/tmp/cache/assets/test/sprockets/8528046f7875341a083dca3a0349725a
257
+ - spec/dummy/tmp/cache/assets/test/sprockets/a45664b91391c11181b20e5903d4aa8f
258
+ - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
259
+ - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
260
+ - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
261
+ - spec/dummy/tmp/cache/assets/test/sprockets/fe314a8ef926518b95394d23d7967ac4
202
262
  - spec/features/navigation_spec.rb
203
263
  - spec/helpers/nav_link_helper_spec.rb
204
264
  - spec/spec_helper.rb