nav_links 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +67 -0
- data/Rakefile +3 -0
- data/lib/nav_links/link_generator.rb +117 -0
- data/lib/nav_links/version.rb +3 -0
- data/lib/nav_links/view_helpers.rb +35 -0
- data/lib/nav_links.rb +6 -0
- data/nav_links.gemspec +26 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +3 -0
- data/spec/dummy/app/controllers/projects_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/dashboard/show.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +27 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/nav_link_to_spec.rb +37 -0
- data/spec/helpers/nav_links_spec.rb +42 -0
- data/spec/nav_links/link_generator_spec.rb +97 -0
- data/spec/spec_helper.rb +34 -0
- data/tasks/bundler_gem.rake +1 -0
- data/tasks/rspec.rake +3 -0
- metadata +220 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym 'RESTful'
|
16
|
+
# end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure your secret_key_base is kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
Dummy::Application.config.secret_key_base = '029c4930027e877d48c1b8849e95d80edaba7b8880cfd25adc4bd2f5c3fdd592fe1b0790451dd1c737caf64fde4a2321e589b1a9161cbf338b11f98a178779b3'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
resources :projects
|
3
|
+
root :to => 'dashboard#show'
|
4
|
+
|
5
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
6
|
+
# See how all your routes lay out with "rake routes".
|
7
|
+
|
8
|
+
# You can have the root of your site routed with "root"
|
9
|
+
# root 'welcome#index'
|
10
|
+
|
11
|
+
# Example of regular route:
|
12
|
+
# get 'products/:id' => 'catalog#view'
|
13
|
+
|
14
|
+
# Example of named route that can be invoked with purchase_url(id: product.id)
|
15
|
+
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
16
|
+
|
17
|
+
# Example resource route (maps HTTP verbs to controller actions automatically):
|
18
|
+
# resources :products
|
19
|
+
|
20
|
+
# Example resource route with options:
|
21
|
+
# resources :products do
|
22
|
+
# member do
|
23
|
+
# get 'short'
|
24
|
+
# post 'toggle'
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# collection do
|
28
|
+
# get 'sold'
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Example resource route with sub-resources:
|
33
|
+
# resources :products do
|
34
|
+
# resources :comments, :sales
|
35
|
+
# resource :seller
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Example resource route with more complex sub-resources:
|
39
|
+
# resources :products do
|
40
|
+
# resources :comments
|
41
|
+
# resources :sales do
|
42
|
+
# get 'recent', on: :collection
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# Example resource route with concerns:
|
47
|
+
# concern :toggleable do
|
48
|
+
# post 'toggle'
|
49
|
+
# end
|
50
|
+
# resources :posts, concerns: :toggleable
|
51
|
+
# resources :photos, concerns: :toggleable
|
52
|
+
|
53
|
+
# Example resource route within a namespace:
|
54
|
+
# namespace :admin do
|
55
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
56
|
+
# # (app/controllers/admin/products_controller.rb)
|
57
|
+
# resources :products
|
58
|
+
# end
|
59
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NavLinks::ViewHelpers do
|
4
|
+
describe '#nav_link_to' do
|
5
|
+
let(:link_generator) do
|
6
|
+
lg = double("LinkGenerator")
|
7
|
+
lg.stub(:to_html => true)
|
8
|
+
lg
|
9
|
+
end
|
10
|
+
|
11
|
+
before { helper.stub(:request => :request) }
|
12
|
+
|
13
|
+
it 'accepts only a title and a path' do
|
14
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
|
15
|
+
.and_return(link_generator)
|
16
|
+
|
17
|
+
helper.nav_link_to("My Title", "/path")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts a block that returns the title' do
|
21
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
|
22
|
+
.and_return(link_generator)
|
23
|
+
|
24
|
+
helper.nav_link_to("/path") do
|
25
|
+
"My Title"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "accepts options and html_options parameters" do
|
30
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", :html_options, :options)
|
31
|
+
.and_return(link_generator)
|
32
|
+
|
33
|
+
helper.nav_link_to("My Title", "/path", :html_options, :options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NavLinks::ViewHelpers do
|
4
|
+
describe '#nav_links' do
|
5
|
+
let(:link_generator) do
|
6
|
+
lg = double("LinkGenerator")
|
7
|
+
lg.stub(:to_html => true)
|
8
|
+
lg
|
9
|
+
end
|
10
|
+
|
11
|
+
before { helper.stub(:request => :request) }
|
12
|
+
|
13
|
+
it 'does nothing when called without options' do
|
14
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
|
15
|
+
.and_return(link_generator)
|
16
|
+
|
17
|
+
helper.nav_links do |n|
|
18
|
+
n.nav_link_to("My Title", "/path")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'applies the options to links created inside' do
|
23
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {foo: :bar})
|
24
|
+
.and_return(link_generator)
|
25
|
+
|
26
|
+
helper.nav_links foo: :bar do |n|
|
27
|
+
n.nav_link_to("My Title", "/path")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'lets the options be overridden by individual calls' do
|
32
|
+
NavLinks::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {foo: :baz})
|
33
|
+
.and_return(link_generator)
|
34
|
+
|
35
|
+
helper.nav_links foo: :bar do |n|
|
36
|
+
n.nav_link_to("My Title", "/path", {}, {foo: :baz})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NavLinks::LinkGenerator do
|
4
|
+
describe '#to_html' do
|
5
|
+
subject { NavLinks::LinkGenerator }
|
6
|
+
let(:request){ double("Request") }
|
7
|
+
|
8
|
+
it "outputs a simple link when appropriate" do
|
9
|
+
request.stub(:fullpath).and_return('/not-projects')
|
10
|
+
subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "knows when to flag the link as current" do
|
14
|
+
request.stub(:fullpath).and_return('/projects')
|
15
|
+
subject.new(request, 'Hi', '/projects').to_html.should == '<a class="selected" href="/projects">Hi</a>'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does not flag the link as current if there are parameters in the path" do
|
19
|
+
request.stub(:fullpath).and_return('/projects?all=true')
|
20
|
+
subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "flags the link as selected if there are parameters in the path but we are ignoring parameters" do
|
24
|
+
request.stub(:fullpath).and_return('/projects?all=true')
|
25
|
+
subject.new(request, 'Hi', '/projects', {}, :ignore_params => true).to_html
|
26
|
+
.should == '<a class="selected" href="/projects">Hi</a>'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "allows the specification of an alternate selected class" do
|
30
|
+
request.stub(:fullpath).and_return('/projects')
|
31
|
+
subject.new(request, 'Hi', '/projects', {}, :selected_class => 'current').to_html
|
32
|
+
.should == '<a class="current" href="/projects">Hi</a>'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "generates a wrapper for the link when specified" do
|
36
|
+
request.stub(:fullpath).and_return('/not-projects')
|
37
|
+
subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li').to_html
|
38
|
+
.should == '<li><a href="/projects">Hi</a></li>'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "provides a class for the wrapper when specified" do
|
42
|
+
request.stub(:fullpath).and_return('/not-projects')
|
43
|
+
subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
|
44
|
+
.should == '<li class="container"><a href="/projects">Hi</a></li>'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "provides a class for the wrapper when specified along with a selected class if neeeded" do
|
48
|
+
request.stub(:fullpath).and_return('/projects')
|
49
|
+
subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
|
50
|
+
.should == '<li class="selected container"><a href="/projects">Hi</a></li>'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "allows specification of the link classes" do
|
54
|
+
request.stub(:fullpath).and_return('/not-projects')
|
55
|
+
subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
|
56
|
+
.should == '<a class="one two" href="/projects">Hi</a>'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "combines custom link classes when the link is selected" do
|
60
|
+
request.stub(:fullpath).and_return('/projects')
|
61
|
+
subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
|
62
|
+
.should == '<a class="one two selected" href="/projects">Hi</a>'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "ignores the ID in the path when provided with a segment" do
|
66
|
+
request.stub(:fullpath).and_return('/projects/2')
|
67
|
+
request.stub(:path).and_return('/projects/2')
|
68
|
+
subject.new(request, 'Hi', '/projects', {}, :url_segment => 1).to_html
|
69
|
+
.should == '<a class="selected" href="/projects">Hi</a>'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "handles deep URL segments" do
|
73
|
+
request.stub(:fullpath).and_return('/projects/2/edit')
|
74
|
+
request.stub(:path).and_return('/projects/2/edit')
|
75
|
+
subject.new(request, 'Hi', '/projects/2', {}, :url_segment => 2).to_html
|
76
|
+
.should == '<a class="selected" href="/projects/2">Hi</a>'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "knows to not match on the first segment when requested" do
|
80
|
+
request.stub(:fullpath).and_return('/projects/2/edit')
|
81
|
+
request.stub(:path).and_return('/projects/2/edit')
|
82
|
+
subject.new(request, 'Hi', '/projects/1', {}, :url_segment => 2).to_html
|
83
|
+
.should == '<a href="/projects/1">Hi</a>'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "handles matching on the controller segment" do
|
87
|
+
Rails.application.routes.stub(:recognize_path).with('/members/1').and_return(:controller => 'members')
|
88
|
+
Rails.application.routes.stub(:recognize_path).with('/members/pages/1').and_return(:controller => 'members')
|
89
|
+
|
90
|
+
request.stub(:fullpath).and_return('/members/pages/1')
|
91
|
+
request.stub(:path).and_return('/members/pages/1')
|
92
|
+
|
93
|
+
subject.new(request, 'Hi', '/members/1', {}, :controller_segment => 1).to_html
|
94
|
+
.should == '<a class="selected" href="/members/1">Hi</a>'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
10
|
+
|
11
|
+
# Checks for pending migrations before tests are run.
|
12
|
+
# If you are not using ActiveRecord, you can remove this line.
|
13
|
+
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# ## Mock Framework
|
17
|
+
#
|
18
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
19
|
+
#
|
20
|
+
# config.mock_with :mocha
|
21
|
+
# config.mock_with :flexmock
|
22
|
+
# config.mock_with :rr
|
23
|
+
|
24
|
+
# If true, the base class of anonymous controllers will be inferred
|
25
|
+
# automatically. This will be the default behavior in future versions of
|
26
|
+
# rspec-rails.
|
27
|
+
config.infer_base_class_for_anonymous_controllers = false
|
28
|
+
|
29
|
+
# Run specs in random order to surface order dependencies. If you find an
|
30
|
+
# order dependency and want to debug it, you can fix the order by providing
|
31
|
+
# the seed, which is printed after each run.
|
32
|
+
# --seed 1234
|
33
|
+
config.order = "random"
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/tasks/rspec.rake
ADDED