padrino-routing 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/padrino-routing/helpers.rb +22 -0
- data/lib/padrino-routing/named_route.rb +27 -0
- data/lib/padrino-routing.rb +48 -0
- data/padrino-routing.gemspec +76 -0
- data/test/active_support_helpers.rb +7 -0
- data/test/fixtures/routing_app/app.rb +47 -0
- data/test/fixtures/routing_app/views/index.haml +7 -0
- data/test/helper.rb +74 -0
- data/test/test_padrino_routing.rb +94 -0
- metadata +135 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Padrino
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "padrino-routing"
|
8
|
+
gem.summary = "Named route mapping system"
|
9
|
+
gem.description = "Enhances padrino with a named route mapping system allowing for advanced routes"
|
10
|
+
gem.email = "nesquena@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/padrino/padrino-routing"
|
12
|
+
gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
13
|
+
gem.add_runtime_dependency "sinatra", ">= 0.9.2"
|
14
|
+
gem.add_development_dependency "haml", ">= 2.2.1"
|
15
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
16
|
+
gem.add_development_dependency "mocha", ">= 0.9.7"
|
17
|
+
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
18
|
+
gem.add_development_dependency "webrat", ">= 0.5.1"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/test_*.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :test => :check_dependencies
|
47
|
+
|
48
|
+
task :default => :test
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "padrino-routing #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Routing
|
3
|
+
module Helpers
|
4
|
+
# Used to retrieve the full url for a given named route alias from the named_paths data
|
5
|
+
# Accepts parameters which will be substituted into the url if necessary
|
6
|
+
# url_for(:accounts) => '/accounts'
|
7
|
+
# url_for(:account, :id => 5) => '/account/5'
|
8
|
+
# url_for(:admin, show, :id => 5, :name => "demo") => '/admin/path/5/demo'
|
9
|
+
def url_for(*route_name)
|
10
|
+
values = route_name.extract_options!
|
11
|
+
mapped_url = self.class.named_paths[route_name] || self.class.named_paths[route_name.dup.unshift(self.class.app_name)]
|
12
|
+
raise Padrino::RouteNotFound.new("Route alias #{route_name.inspect} is not mapped to a url") unless mapped_url
|
13
|
+
result_url = String.new(File.join(self.class.uri_root, mapped_url))
|
14
|
+
result_url.scan(%r{/?(:\S+?)(?:/|$)}).each do |placeholder|
|
15
|
+
value_key = placeholder[0][1..-1].to_sym
|
16
|
+
result_url.gsub!(Regexp.new(placeholder[0]), values[value_key].to_s)
|
17
|
+
end
|
18
|
+
result_url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Routing
|
3
|
+
class NamedRoute
|
4
|
+
# Constructs the NamedRoute which accepts the application and
|
5
|
+
# the route alias names to register (i.e [:account] or [:admin, :show])
|
6
|
+
# NamedRoute.new(@app, :admin, :show)
|
7
|
+
def initialize(app, *names)
|
8
|
+
@app = app
|
9
|
+
@names = names.flatten
|
10
|
+
end
|
11
|
+
|
12
|
+
# Used to define the url mapping to the supplied alias
|
13
|
+
# NamedRoute.new(@app, :account).to('/account/path')
|
14
|
+
def to(path)
|
15
|
+
@app.named_paths[@names.unshift(@app.app_name)] = path
|
16
|
+
end
|
17
|
+
|
18
|
+
# Used to define the url mappings for child aliases within a namespace
|
19
|
+
# Invokes map on the application itself, appending the namespace to the route
|
20
|
+
# NamedRoute.new(@app, :admin).map(:show).to('/admin/show')
|
21
|
+
# is equivalent to NamedRoute.new(@app, :admin, :show).to('/admin/show')
|
22
|
+
def map(*args, &block)
|
23
|
+
@app.map(*args.unshift(@names), &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# require 'padrino-core/support_lite'
|
2
|
+
Dir[File.dirname(__FILE__) + '/padrino-routing/**/*.rb'].each {|file| require file }
|
3
|
+
|
4
|
+
module Padrino
|
5
|
+
class RouteNotFound < RuntimeError; end
|
6
|
+
|
7
|
+
module Routing
|
8
|
+
def self.registered(app)
|
9
|
+
# Named paths stores the named route aliases mapping to the url
|
10
|
+
# i.e { [:account] => '/account/path', [:admin, :show] => '/admin/show/:id' }
|
11
|
+
app.set :named_paths, {}
|
12
|
+
app.set :app_name, app.name.underscore.to_sym unless app.respond_to?(:app_name)
|
13
|
+
app.set :uri_root, '/' unless app.respond_to?(:uri_root)
|
14
|
+
app.helpers Padrino::Routing::Helpers
|
15
|
+
|
16
|
+
# map constructs a mapping between a named route and a specified alias
|
17
|
+
# the mapping url can contain url query parameters
|
18
|
+
# map(:accounts).to('/accounts/url')
|
19
|
+
# map(:admin, :show).to('/admin/show/:id')
|
20
|
+
# map(:admin) { |namespace| namespace.map(:show).to('/admin/show/:id') }
|
21
|
+
def map(*args, &block)
|
22
|
+
named_router = Padrino::Routing::NamedRoute.new(self, *args)
|
23
|
+
block_given? ? block.call(named_router) : named_router
|
24
|
+
end
|
25
|
+
|
26
|
+
# Used to define namespaced route configurations in order to group similar routes
|
27
|
+
# Class evals the routes but with the namespace assigned which will append to each route
|
28
|
+
# namespace(:admin) { get(:show) { "..." } }
|
29
|
+
def namespace(name, &block)
|
30
|
+
original, @_namespace = @_namespace, name
|
31
|
+
self.class_eval(&block)
|
32
|
+
@_namespace = original
|
33
|
+
end
|
34
|
+
|
35
|
+
# Hijacking route method in sinatra to replace a route alias (i.e :account) with the full url string mapping
|
36
|
+
# Supports namespaces by accessing the instance variable and appending this to the route alias name
|
37
|
+
# If the path is not a symbol, nothing is changed and the original route method is invoked
|
38
|
+
def route(verb, path, options={}, &block)
|
39
|
+
if path.kind_of? Symbol
|
40
|
+
route_name = [self.app_name, @_namespace, path].flatten.compact
|
41
|
+
path = named_paths[route_name]
|
42
|
+
raise RouteNotFound.new("Route alias #{route_name.inspect} is not mapped to a url") unless path
|
43
|
+
end
|
44
|
+
super verb, path, options, &block
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{padrino-routing}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
+
s.date = %q{2009-11-16}
|
13
|
+
s.description = %q{Enhances padrino with a named route mapping system allowing for advanced routes}
|
14
|
+
s.email = %q{nesquena@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/padrino-routing.rb",
|
27
|
+
"lib/padrino-routing/helpers.rb",
|
28
|
+
"lib/padrino-routing/named_route.rb",
|
29
|
+
"padrino-routing.gemspec",
|
30
|
+
"test/active_support_helpers.rb",
|
31
|
+
"test/fixtures/routing_app/app.rb",
|
32
|
+
"test/fixtures/routing_app/views/index.haml",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_padrino_routing.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/padrino/padrino-routing}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Named route mapping system}
|
41
|
+
s.test_files = [
|
42
|
+
"test/active_support_helpers.rb",
|
43
|
+
"test/fixtures/routing_app/app.rb",
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/test_padrino_routing.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
54
|
+
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
57
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
58
|
+
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
61
|
+
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
64
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
65
|
+
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
69
|
+
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
70
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
|
+
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
72
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
73
|
+
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'haml'
|
3
|
+
|
4
|
+
class RoutingDemo < Sinatra::Base
|
5
|
+
register Padrino::Routing
|
6
|
+
|
7
|
+
configure do
|
8
|
+
set :root, File.dirname(__FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
map(:admin, :show).to("/admin/:id/show")
|
12
|
+
map :admin do |namespace|
|
13
|
+
namespace.map(:update).to("/admin/:id/update/:name")
|
14
|
+
namespace.map(:destroy).to("/admin/:id/destroy")
|
15
|
+
end
|
16
|
+
map(:account).to("/the/accounts/:name/path/:id/end")
|
17
|
+
map(:accounts).to("/the/accounts/index/?")
|
18
|
+
|
19
|
+
namespace :admin do
|
20
|
+
get :show do
|
21
|
+
"<p>admin show for id #{params[:id]}</p>"
|
22
|
+
end
|
23
|
+
|
24
|
+
get :update do
|
25
|
+
"<p>updated admin with id #{params[:id]} and name #{params[:name]}</p>"
|
26
|
+
end
|
27
|
+
|
28
|
+
get :destroy do
|
29
|
+
"<p>destroy admin with id #{params[:id]}</p>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
get :account do
|
33
|
+
"<h1>the account url for #{params[:name]} and id #{params[:id]}</h1>"
|
34
|
+
end
|
35
|
+
|
36
|
+
get :accounts do
|
37
|
+
"<h1>the accounts index</h1>"
|
38
|
+
end
|
39
|
+
|
40
|
+
get '/links' do
|
41
|
+
haml :index
|
42
|
+
end
|
43
|
+
|
44
|
+
get '/failed_route' do
|
45
|
+
url_for(:some, :not_real, :id => 5)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
%p.admin_url= url_for(:admin, :show, :id => 25)
|
2
|
+
%p.app_admin_url= url_for(:routing_demo, :admin, :show, :id => 25)
|
3
|
+
%p.admin_url2= url_for(:admin, :update, :id => 10, :name => "test")
|
4
|
+
%p.admin_url3= url_for(:admin, :destroy, :id => 12)
|
5
|
+
%p.account_url= url_for(:account, :name => 'foobar', :id => 10)
|
6
|
+
%p.accounts_index=url_for(:accounts)
|
7
|
+
%p.app_accounts_index=url_for(:routing_demo, :accounts)
|
data/test/helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'webrat'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'active_support_helpers'
|
11
|
+
require File.dirname(__FILE__) + '/../../padrino-helpers/lib/padrino-helpers.rb'
|
12
|
+
require File.dirname(__FILE__) + '/../lib/padrino-routing.rb'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
include Padrino::Helpers::OutputHelpers
|
16
|
+
include Padrino::Helpers::TagHelpers
|
17
|
+
include Padrino::Helpers::AssetTagHelpers
|
18
|
+
include Rack::Test::Methods
|
19
|
+
include Webrat::Methods
|
20
|
+
include Webrat::Matchers
|
21
|
+
|
22
|
+
Webrat.configure do |config|
|
23
|
+
config.mode = :rack
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop_time_for_test
|
27
|
+
time = Time.now
|
28
|
+
Time.stubs(:now).returns(time)
|
29
|
+
return time
|
30
|
+
end
|
31
|
+
|
32
|
+
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
33
|
+
# In this case, block is the html to evaluate
|
34
|
+
def assert_has_tag(name, attributes = {}, &block)
|
35
|
+
html = block && block.call
|
36
|
+
matcher = HaveSelector.new(name, attributes)
|
37
|
+
raise "Please specify a block!" if html.blank?
|
38
|
+
assert matcher.matches?(html), matcher.failure_message
|
39
|
+
end
|
40
|
+
|
41
|
+
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
42
|
+
# In this case, block is the html to evaluate
|
43
|
+
def assert_has_no_tag(name, attributes = {}, &block)
|
44
|
+
html = block && block.call
|
45
|
+
attributes.merge!(:count => 0)
|
46
|
+
matcher = HaveSelector.new(name, attributes)
|
47
|
+
raise "Please specify a block!" if html.blank?
|
48
|
+
assert matcher.matches?(html), matcher.failure_message
|
49
|
+
end
|
50
|
+
|
51
|
+
# Silences the output by redirecting to stringIO
|
52
|
+
# silence_logger { ...commands... } => "...output..."
|
53
|
+
def silence_logger(&block)
|
54
|
+
orig_stdout = $stdout
|
55
|
+
$stdout = log_buffer = StringIO.new
|
56
|
+
block.call
|
57
|
+
$stdout = orig_stdout
|
58
|
+
log_buffer.rewind && log_buffer.read
|
59
|
+
end
|
60
|
+
|
61
|
+
# Asserts that a file matches the pattern
|
62
|
+
def assert_match_in_file(pattern, file)
|
63
|
+
assert File.exist?(file), "File '#{file}' does not exist!"
|
64
|
+
assert_match pattern, File.read(file)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module Webrat
|
69
|
+
module Logging
|
70
|
+
def logger # :nodoc:
|
71
|
+
@logger = nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require File.dirname(__FILE__) + '/fixtures/routing_app/app'
|
3
|
+
|
4
|
+
class TestPadrinoRouting < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
RoutingDemo.tap { |app| app.set :environment, :test }.tap { |app| app.set :uri_root, '/blog' }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for links list displaying routes' do
|
10
|
+
setup { visit '/links' }
|
11
|
+
should 'display account route links' do
|
12
|
+
assert_have_selector :p, :class => 'account_url', :content => '/the/accounts/foobar/path/10/end'
|
13
|
+
assert_have_selector :p, :class => 'accounts_index', :content => '/the/accounts/index'
|
14
|
+
end
|
15
|
+
should "display admin route links" do
|
16
|
+
assert_have_selector :p, :class => 'admin_url', :content => '/admin/25/show'
|
17
|
+
assert_have_selector :p, :class => 'admin_url2', :content => '/admin/10/update/test'
|
18
|
+
assert_have_selector :p, :class => 'admin_url3', :content => '/admin/12/destroy'
|
19
|
+
end
|
20
|
+
should "support app namespaces" do
|
21
|
+
assert_have_selector :p, :class => 'app_accounts_index', :content => '/the/accounts/index'
|
22
|
+
assert_have_selector :p, :class => 'app_admin_url', :content => '/admin/25/show'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'for mounted application' do
|
27
|
+
should "support changing uri root no mount" do
|
28
|
+
demo = app.new
|
29
|
+
demo.class.stubs(:uri_root).returns("/")
|
30
|
+
demo.class.map(:demo).to('/demo')
|
31
|
+
assert_equal "/demo", demo.class.named_paths[[:routing_demo, :demo]]
|
32
|
+
assert_equal "/demo", demo.url_for(:demo)
|
33
|
+
end
|
34
|
+
should "support changing uri root with mount" do
|
35
|
+
demo = app.new
|
36
|
+
demo.class.stubs(:uri_root).returns("/blog")
|
37
|
+
demo.class.map(:demo).to('/demo')
|
38
|
+
assert_equal "/demo", demo.class.named_paths[[:routing_demo, :demo]]
|
39
|
+
assert_equal "/blog/demo", demo.url_for(:demo)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'for failed or missing routes' do
|
44
|
+
should "properly not raise when found" do
|
45
|
+
assert_nothing_raised { app.new.url_for(:accounts) }
|
46
|
+
assert_nothing_raised { app.new.url_for(:routing_demo, :admin, :show, :id => 5) }
|
47
|
+
end
|
48
|
+
should "properly raise not found exception" do
|
49
|
+
assert_raises(Padrino::RouteNotFound) { visit '/failed_route' }
|
50
|
+
assert_raises(Padrino::RouteNotFound) { app.new.url_for(:admin, :fake) }
|
51
|
+
end
|
52
|
+
should "properly raise about an invalid alias for route definition" do
|
53
|
+
assert_raises(Padrino::RouteNotFound) { app.get(:fake) }
|
54
|
+
end
|
55
|
+
should "properly work when alias is used in proper route definition" do
|
56
|
+
assert_nothing_raised { app.get(:accounts) do; end }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'for no namespaced account route' do
|
61
|
+
setup { visit '/the/accounts/demo/path/5/end'}
|
62
|
+
should "return proper account text" do
|
63
|
+
assert_have_selector :h1, :content => "the account url for demo and id 5"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'for no namespaced accounts index route' do
|
68
|
+
setup { visit '/the/accounts/index/'}
|
69
|
+
should "return proper account text" do
|
70
|
+
assert_have_selector :h1, :content => "the accounts index"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'for admin show url' do
|
75
|
+
setup { visit '/admin/50/show' }
|
76
|
+
should "return proper admin test" do
|
77
|
+
assert_have_selector :p, :content => "admin show for id 50"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'for admin update url' do
|
82
|
+
setup { visit '/admin/15/update/demo' }
|
83
|
+
should "return proper update text" do
|
84
|
+
assert_have_selector :p, :content => "updated admin with id 15 and name demo"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'for admin destroy url' do
|
89
|
+
setup { visit '/admin/60/destroy' }
|
90
|
+
should "return proper destroy text" do
|
91
|
+
assert_have_selector :p, :content => "destroy admin with id 60"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-routing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Padrino Team
|
8
|
+
- Nathan Esquenazi
|
9
|
+
- Davide D'Agostino
|
10
|
+
- Arthur Chiu
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-11-16 00:00:00 -08:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: sinatra
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
version:
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: haml
|
30
|
+
type: :development
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.2.1
|
37
|
+
version:
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: shoulda
|
40
|
+
type: :development
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
type: :development
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.9.7
|
57
|
+
version:
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
type: :development
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.5.0
|
67
|
+
version:
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: webrat
|
70
|
+
type: :development
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.5.1
|
77
|
+
version:
|
78
|
+
description: Enhances padrino with a named route mapping system allowing for advanced routes
|
79
|
+
email: nesquena@gmail.com
|
80
|
+
executables: []
|
81
|
+
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .gitignore
|
90
|
+
- LICENSE
|
91
|
+
- README.rdoc
|
92
|
+
- Rakefile
|
93
|
+
- VERSION
|
94
|
+
- lib/padrino-routing.rb
|
95
|
+
- lib/padrino-routing/helpers.rb
|
96
|
+
- lib/padrino-routing/named_route.rb
|
97
|
+
- padrino-routing.gemspec
|
98
|
+
- test/active_support_helpers.rb
|
99
|
+
- test/fixtures/routing_app/app.rb
|
100
|
+
- test/fixtures/routing_app/views/index.haml
|
101
|
+
- test/helper.rb
|
102
|
+
- test/test_padrino_routing.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://github.com/padrino/padrino-routing
|
105
|
+
licenses: []
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- --charset=UTF-8
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
version:
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
version:
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.3.5
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Named route mapping system
|
131
|
+
test_files:
|
132
|
+
- test/active_support_helpers.rb
|
133
|
+
- test/fixtures/routing_app/app.rb
|
134
|
+
- test/helper.rb
|
135
|
+
- test/test_padrino_routing.rb
|