aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-10-27 19:48:35 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-27 21:02:20 -0500
commit43e0bc1c9f39ebf5b253b498b38101a4aba04a45 (patch)
tree0ff738bb4028d5b0e83bb4be428a4cab3c905781 /actionpack
parente296ea056e87027933c7d37e1e8c1f6ef73bc447 (diff)
downloadrails-43e0bc1c9f39ebf5b253b498b38101a4aba04a45.tar.gz
rails-43e0bc1c9f39ebf5b253b498b38101a4aba04a45.tar.bz2
rails-43e0bc1c9f39ebf5b253b498b38101a4aba04a45.zip
Extract routing controller stub helper into abstract unit
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/abstract_unit.rb20
-rw-r--r--actionpack/test/dispatch/routing_test.rb145
2 files changed, 86 insertions, 79 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 86c8a95a43..214d79cd87 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -105,6 +105,26 @@ class ActionController::IntegrationTest < ActiveSupport::TestCase
self.app = build_app
+ class StubDispatcher
+ def self.new(*args)
+ lambda { |env|
+ params = env['action_dispatch.request.path_parameters']
+ controller, action = params[:controller], params[:action]
+ [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]]
+ }
+ end
+ end
+
+ def self.stub_controllers
+ old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher
+ ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
+ ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, StubDispatcher }
+ yield ActionDispatch::Routing::RouteSet.new
+ ensure
+ ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
+ ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher }
+ end
+
def with_routing(&block)
real_routes = ActionController::Routing::Routes
ActionController::Routing.module_eval { remove_const :Routes }
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 972bf73602..5558cf0154 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -12,112 +12,99 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- class Dispatcher
- def self.new(*args)
- lambda { |env|
- params = env['action_dispatch.request.path_parameters']
- controller, action = params[:controller], params[:action]
- [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]]
- }
- end
- end
-
- old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, Dispatcher }
- Routes = ActionDispatch::Routing::RouteSet.new
- Routes.draw do |map|
- controller :sessions do
- get 'login', :to => :new, :as => :login
- post 'login', :to => :create
-
- delete 'logout', :to => :destroy, :as => :logout
- end
-
- match 'account/login', :to => redirect("/login")
-
- match 'openid/login', :via => [:get, :post], :to => "openid#login"
-
- controller(:global) do
- match 'global/:action'
- match 'global/export', :to => :export, :as => :export_request
- match 'global/hide_notice', :to => :hide_notice, :as => :hide_notice
- match '/export/:id/:file', :to => :export, :as => :export_download, :constraints => { :file => /.*/ }
- end
-
- constraints(:ip => /192\.168\.1\.\d\d\d/) do
- get 'admin', :to => "queenbee#index"
- end
+ stub_controllers do |routes|
+ Routes = routes
+ Routes.draw do |map|
+ controller :sessions do
+ get 'login', :to => :new, :as => :login
+ post 'login', :to => :create
+
+ delete 'logout', :to => :destroy, :as => :logout
+ end
- constraints IpRestrictor do
- get 'admin/accounts', :to => "queenbee#accounts"
- end
+ match 'account/login', :to => redirect("/login")
- resources :projects, :controller => :project do
- resources :involvements, :attachments
+ match 'openid/login', :via => [:get, :post], :to => "openid#login"
- resources :participants do
- put :update_all, :on => :collection
+ controller(:global) do
+ match 'global/:action'
+ match 'global/export', :to => :export, :as => :export_request
+ match 'global/hide_notice', :to => :hide_notice, :as => :hide_notice
+ match '/export/:id/:file', :to => :export, :as => :export_download, :constraints => { :file => /.*/ }
end
- resources :companies do
- resources :people
- resource :avatar
+ constraints(:ip => /192\.168\.1\.\d\d\d/) do
+ get 'admin', :to => "queenbee#index"
end
- resources :images do
- post :revise, :on => :member
+ constraints IpRestrictor do
+ get 'admin/accounts', :to => "queenbee#accounts"
end
- resources :people do
- namespace ":access_token" do
- resource :avatar
+ resources :projects, :controller => :project do
+ resources :involvements, :attachments
+
+ resources :participants do
+ put :update_all, :on => :collection
end
- member do
- put :accessible_projects
- post :resend, :generate_new_password
+ resources :companies do
+ resources :people
+ resource :avatar
+ end
+
+ resources :images do
+ post :revise, :on => :member
+ end
+
+ resources :people do
+ namespace ":access_token" do
+ resource :avatar
+ end
+
+ member do
+ put :accessible_projects
+ post :resend, :generate_new_password
+ end
end
- end
- resources :posts do
- get :archive, :toggle_view, :on => :collection
- post :preview, :on => :member
+ resources :posts do
+ get :archive, :toggle_view, :on => :collection
+ post :preview, :on => :member
- resource :subscription
+ resource :subscription
- resources :comments do
- post :preview, :on => :collection
+ resources :comments do
+ post :preview, :on => :collection
+ end
end
end
- end
- match 'sprockets.js', :to => SprocketsApp
+ match 'sprockets.js', :to => SprocketsApp
- match 'people/:id/update', :to => 'people#update', :as => :update_person
- match '/projects/:project_id/people/:id/update', :to => 'people#update', :as => :update_project_person
+ match 'people/:id/update', :to => 'people#update', :as => :update_person
+ match '/projects/:project_id/people/:id/update', :to => 'people#update', :as => :update_project_person
- # misc
- match 'articles/:year/:month/:day/:title', :to => "articles#show", :as => :article
+ # misc
+ match 'articles/:year/:month/:day/:title', :to => "articles#show", :as => :article
- namespace :account do
- resource :subscription, :credit, :credit_card
- end
+ namespace :account do
+ resource :subscription, :credit, :credit_card
+ end
- controller :articles do
- scope 'articles' do
- scope ':title', :title => /[a-z]+/, :as => :with_title do
- match ':id', :to => :with_id
+ controller :articles do
+ scope 'articles' do
+ scope ':title', :title => /[a-z]+/, :as => :with_title do
+ match ':id', :to => :with_id
+ end
end
end
- end
- scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do
- resources :rooms
+ scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do
+ resources :rooms
+ end
end
end
- ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher }
- ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher }
def app
Routes