Rails 2.1 RC1
Updated Instiki to Rails 2.1 RC1 (aka 2.0.991).
This commit is contained in:
parent
14afed5893
commit
5292899c9a
971 changed files with 46318 additions and 17450 deletions
|
@ -1,5 +1,5 @@
|
|||
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
||||
require "#{File.dirname(__FILE__)}/fake_controllers"
|
||||
require 'abstract_unit'
|
||||
require 'controller/fake_controllers'
|
||||
require 'action_controller/routing'
|
||||
|
||||
class MilestonesController < ActionController::Base
|
||||
|
@ -25,28 +25,30 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
|
|||
ActionController::Routing.use_controllers! ['controller']
|
||||
@set = ActionController::Routing::RouteSet.new
|
||||
@set.draw do |map|
|
||||
map.connect ':controller/:action/:variable'
|
||||
map.connect ':controller/:action/:variable/*additional'
|
||||
end
|
||||
|
||||
safe, unsafe = %w(: @ & = + $ , ;), %w(^ / ? # [ ])
|
||||
hex = unsafe.map { |char| '%' + char.unpack('H2').first.upcase }
|
||||
|
||||
@segment = "#{safe}#{unsafe}".freeze
|
||||
@escaped = "#{safe}#{hex}".freeze
|
||||
@segment = "#{safe.join}#{unsafe.join}".freeze
|
||||
@escaped = "#{safe.join}#{hex.join}".freeze
|
||||
end
|
||||
|
||||
def test_route_generation_escapes_unsafe_path_characters
|
||||
assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable",
|
||||
assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2",
|
||||
@set.generate(:controller => "contr#{@segment}oller",
|
||||
:action => "act#{@segment}ion",
|
||||
:variable => "var#{@segment}iable")
|
||||
:variable => "var#{@segment}iable",
|
||||
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"])
|
||||
end
|
||||
|
||||
def test_route_recognition_unescapes_path_components
|
||||
options = { :controller => "controller",
|
||||
:action => "act#{@segment}ion",
|
||||
:variable => "var#{@segment}iable" }
|
||||
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable")
|
||||
:variable => "var#{@segment}iable",
|
||||
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
|
||||
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -84,20 +86,47 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_time_recognition
|
||||
n = 10000
|
||||
# We create many routes to make situation more realistic
|
||||
@rs = ::ActionController::Routing::RouteSet.new
|
||||
@rs.draw { |map|
|
||||
map.frontpage '', :controller => 'search', :action => 'new'
|
||||
map.resources :videos do |video|
|
||||
video.resources :comments
|
||||
video.resource :file, :controller => 'video_file'
|
||||
video.resource :share, :controller => 'video_shares'
|
||||
video.resource :abuse, :controller => 'video_abuses'
|
||||
end
|
||||
map.resources :abuses, :controller => 'video_abuses'
|
||||
map.resources :video_uploads
|
||||
map.resources :video_visits
|
||||
|
||||
map.resources :users do |user|
|
||||
user.resource :settings
|
||||
user.resources :videos
|
||||
end
|
||||
map.resources :channels do |channel|
|
||||
channel.resources :videos, :controller => 'channel_videos'
|
||||
end
|
||||
map.resource :session
|
||||
map.resource :lost_password
|
||||
map.search 'search', :controller => 'search'
|
||||
map.resources :pages
|
||||
map.connect ':controller/:action/:id'
|
||||
}
|
||||
n = 1000
|
||||
if RunTimeTests
|
||||
GC.start
|
||||
rectime = Benchmark.realtime do
|
||||
n.times do
|
||||
rs.recognize_path("content")
|
||||
rs.recognize_path("content/list")
|
||||
rs.recognize_path("content/show/10")
|
||||
rs.recognize_path("admin/user")
|
||||
rs.recognize_path("admin/user/list")
|
||||
rs.recognize_path("admin/user/show/10")
|
||||
rs.recognize_path("/videos/1234567", {:method => :get})
|
||||
rs.recognize_path("/videos/1234567/abuse", {:method => :get})
|
||||
rs.recognize_path("/users/1234567/settings", {:method => :get})
|
||||
rs.recognize_path("/channels/1234567", {:method => :get})
|
||||
rs.recognize_path("/session/new", {:method => :get})
|
||||
rs.recognize_path("/admin/user/show/10", {:method => :get})
|
||||
end
|
||||
end
|
||||
puts "\n\nRecognition (RouteSet):"
|
||||
puts "\n\nRecognition (#{rs.routes.size} routes):"
|
||||
per_url = rectime / (n * 6)
|
||||
puts "#{per_url * 1000} ms/url"
|
||||
puts "#{1 / per_url} url/s\n\n"
|
||||
|
@ -909,6 +938,16 @@ class DynamicSegmentTest < Test::Unit::TestCase
|
|||
a_segment.key = :action
|
||||
assert a_segment.optionality_implied?
|
||||
end
|
||||
|
||||
def test_modifiers_must_be_handled_sensibly
|
||||
a_segment = ROUTING::DynamicSegment.new
|
||||
a_segment.regexp = /david|jamis/i
|
||||
assert_equal "((?i-mx:david|jamis))stuff", a_segment.build_pattern('stuff')
|
||||
a_segment.regexp = /david|jamis/x
|
||||
assert_equal "((?x-mi:david|jamis))stuff", a_segment.build_pattern('stuff')
|
||||
a_segment.regexp = /david|jamis/
|
||||
assert_equal "(david|jamis)stuff", a_segment.build_pattern('stuff')
|
||||
end
|
||||
end
|
||||
|
||||
class ControllerSegmentTest < Test::Unit::TestCase
|
||||
|
@ -1696,7 +1735,7 @@ class RouteSetTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_non_path_route_requirements_match_all
|
||||
set.draw do |map|
|
||||
map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/
|
||||
|
@ -1781,6 +1820,30 @@ class RouteSetTest < Test::Unit::TestCase
|
|||
Object.send(:remove_const, :PeopleController)
|
||||
end
|
||||
|
||||
def test_recognize_with_alias_in_conditions
|
||||
Object.const_set(:PeopleController, Class.new)
|
||||
|
||||
set.draw do |map|
|
||||
map.people "/people", :controller => 'people', :action => "index",
|
||||
:conditions => { :method => :get }
|
||||
map.root :people
|
||||
end
|
||||
|
||||
request.path = "/people"
|
||||
request.method = :get
|
||||
assert_nothing_raised { set.recognize(request) }
|
||||
assert_equal("people", request.path_parameters[:controller])
|
||||
assert_equal("index", request.path_parameters[:action])
|
||||
|
||||
request.path = "/"
|
||||
request.method = :get
|
||||
assert_nothing_raised { set.recognize(request) }
|
||||
assert_equal("people", request.path_parameters[:controller])
|
||||
assert_equal("index", request.path_parameters[:action])
|
||||
ensure
|
||||
Object.send(:remove_const, :PeopleController)
|
||||
end
|
||||
|
||||
def test_typo_recognition
|
||||
Object.const_set(:ArticlesController, Class.new)
|
||||
|
||||
|
@ -2059,6 +2122,138 @@ class RouteSetTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_requirements_with_unsupported_regexp_options_must_error
|
||||
assert_raises ArgumentError do
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => /(david|jamis)/m}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_requirements_with_supported_options_must_not_error
|
||||
assert_nothing_raised do
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => /(david|jamis)/i}
|
||||
end
|
||||
end
|
||||
assert_nothing_raised do
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => / # Desperately overcommented regexp
|
||||
( #Either
|
||||
david #The Creator
|
||||
| #Or
|
||||
jamis #The Deployer
|
||||
)/x}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_requirement_recognize_with_ignore_case
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => /(david|jamis)/i}
|
||||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
|
||||
assert_raises ActionController::RoutingError do
|
||||
set.recognize_path('/page/davidjamis')
|
||||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'DAVID'}, set.recognize_path('/page/DAVID'))
|
||||
end
|
||||
|
||||
def test_route_requirement_generate_with_ignore_case
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => /(david|jamis)/i}
|
||||
end
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
|
||||
assert_equal "/page/david", url
|
||||
assert_raises ActionController::RoutingError do
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
|
||||
end
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
||||
assert_equal "/page/JAMIS", url
|
||||
end
|
||||
|
||||
def test_route_requirement_recognize_with_extended_syntax
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => / # Desperately overcommented regexp
|
||||
( #Either
|
||||
david #The Creator
|
||||
| #Or
|
||||
jamis #The Deployer
|
||||
)/x}
|
||||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'david'}, set.recognize_path('/page/david'))
|
||||
assert_raises ActionController::RoutingError do
|
||||
set.recognize_path('/page/david #The Creator')
|
||||
end
|
||||
assert_raises ActionController::RoutingError do
|
||||
set.recognize_path('/page/David')
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_requirement_generate_with_extended_syntax
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => / # Desperately overcommented regexp
|
||||
( #Either
|
||||
david #The Creator
|
||||
| #Or
|
||||
jamis #The Deployer
|
||||
)/x}
|
||||
end
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
|
||||
assert_equal "/page/david", url
|
||||
assert_raises ActionController::RoutingError do
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
|
||||
end
|
||||
assert_raises ActionController::RoutingError do
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_requirement_generate_with_xi_modifiers
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => / # Desperately overcommented regexp
|
||||
( #Either
|
||||
david #The Creator
|
||||
| #Or
|
||||
jamis #The Deployer
|
||||
)/xi}
|
||||
end
|
||||
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
||||
assert_equal "/page/JAMIS", url
|
||||
end
|
||||
|
||||
def test_route_requirement_recognize_with_xi_modifiers
|
||||
set.draw do |map|
|
||||
map.connect 'page/:name', :controller => 'pages',
|
||||
:action => 'show',
|
||||
:requirements => {:name => / # Desperately overcommented regexp
|
||||
( #Either
|
||||
david #The Creator
|
||||
| #Or
|
||||
jamis #The Deployer
|
||||
)/xi}
|
||||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'JAMIS'}, set.recognize_path('/page/JAMIS'))
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
@ -2119,15 +2314,15 @@ class RoutingTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_normalize_unix_paths
|
||||
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models)
|
||||
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config)
|
||||
paths = ActionController::Routing.normalize_paths(load_paths)
|
||||
assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models lib .), paths
|
||||
assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models config .bar lib .), paths
|
||||
end
|
||||
|
||||
def test_normalize_windows_paths
|
||||
load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models)
|
||||
load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models .foo\\..\\.bar foo.bar\\..\\config)
|
||||
paths = ActionController::Routing.normalize_paths(load_paths)
|
||||
assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models lib .), paths
|
||||
assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models config .bar lib .), paths
|
||||
end
|
||||
|
||||
def test_routing_helper_module
|
||||
|
@ -2139,7 +2334,7 @@ class RoutingTest < Test::Unit::TestCase
|
|||
ActionController::Routing::Routes.install_helpers c
|
||||
assert c.ancestors.include?(h)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
uses_mocha 'route loading' do
|
||||
|
@ -2148,11 +2343,13 @@ uses_mocha 'route loading' do
|
|||
def setup
|
||||
routes.instance_variable_set '@routes_last_modified', nil
|
||||
silence_warnings { Object.const_set :RAILS_ROOT, '.' }
|
||||
ActionController::Routing::Routes.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
|
||||
|
||||
@stat = stub_everything
|
||||
end
|
||||
|
||||
def teardown
|
||||
ActionController::Routing::Routes.configuration_file = nil
|
||||
Object.send :remove_const, :RAILS_ROOT
|
||||
end
|
||||
|
||||
|
@ -2193,6 +2390,14 @@ uses_mocha 'route loading' do
|
|||
|
||||
Inflector.inflections { |inflect| inflect.uncountable('equipment') }
|
||||
end
|
||||
|
||||
def test_load_with_configuration
|
||||
routes.configuration_file = "foobarbaz"
|
||||
File.expects(:stat).returns(@stat)
|
||||
routes.expects(:load).with("foobarbaz")
|
||||
|
||||
routes.reload
|
||||
end
|
||||
|
||||
private
|
||||
def routes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue