mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Start rewriting some internal tests to use the new routing dsl
This commit is contained in:
parent
207d0483e5
commit
a5c82a9dfb
13 changed files with 32 additions and 31 deletions
|
@ -109,6 +109,10 @@ module ActionController
|
|||
middleware_stack
|
||||
end
|
||||
|
||||
def self.call(env)
|
||||
action(env['action_dispatch.request.path_parameters'][:action]).call(env)
|
||||
end
|
||||
|
||||
# Return a rack endpoint for the given action. Memoize the endpoint, so
|
||||
# multiple calls into MyController.action will return the same object
|
||||
# for the same action.
|
||||
|
|
|
@ -10,12 +10,12 @@ module Submodule
|
|||
def public_action
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
hide_action :hidden_action
|
||||
def hidden_action
|
||||
raise "Noooo!"
|
||||
end
|
||||
|
||||
|
||||
def another_hidden_action
|
||||
end
|
||||
hide_action :another_hidden_action
|
||||
|
@ -30,25 +30,25 @@ class NonEmptyController < ActionController::Base
|
|||
def public_action
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
hide_action :hidden_action
|
||||
def hidden_action
|
||||
end
|
||||
end
|
||||
|
||||
class MethodMissingController < ActionController::Base
|
||||
|
||||
|
||||
hide_action :shouldnt_be_called
|
||||
def shouldnt_be_called
|
||||
raise "NO WAY!"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def method_missing(selector)
|
||||
render :text => selector.to_s
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
class DefaultUrlOptionsController < ActionController::Base
|
||||
|
@ -79,7 +79,7 @@ class ControllerInstanceTests < Test::Unit::TestCase
|
|||
@empty = EmptyController.new
|
||||
@contained = Submodule::ContainedEmptyController.new
|
||||
@empty_controllers = [@empty, @contained, Submodule::SubclassedController.new]
|
||||
|
||||
|
||||
@non_empty_controllers = [NonEmptyController.new,
|
||||
Submodule::ContainedNonEmptyController.new]
|
||||
end
|
||||
|
@ -135,24 +135,24 @@ class PerformActionTest < ActionController::TestCase
|
|||
|
||||
rescue_action_in_public!
|
||||
end
|
||||
|
||||
|
||||
def test_get_on_priv_should_show_selector
|
||||
use_controller MethodMissingController
|
||||
get :shouldnt_be_called
|
||||
assert_response :success
|
||||
assert_equal 'shouldnt_be_called', @response.body
|
||||
end
|
||||
|
||||
|
||||
def test_method_missing_is_not_an_action_name
|
||||
use_controller MethodMissingController
|
||||
|
||||
assert ! @controller.__send__(:action_method?, 'method_missing')
|
||||
|
||||
|
||||
get :method_missing
|
||||
assert_response :success
|
||||
assert_equal 'method_missing', @response.body
|
||||
end
|
||||
|
||||
|
||||
def test_get_on_hidden_should_fail
|
||||
use_controller NonEmptyController
|
||||
assert_raise(ActionController::UnknownAction) { get :hidden_action }
|
||||
|
|
|
@ -390,7 +390,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect "/:action", :controller => "integration_process_test/integration"
|
||||
match ':action', :to => IntegrationController
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -343,9 +343,9 @@ class RescueTest < ActionController::IntegrationTest
|
|||
def with_test_routing
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect 'foo', :controller => "rescue_test/test", :action => 'foo'
|
||||
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
|
||||
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
|
||||
match 'foo', :to => TestController.action(:foo)
|
||||
match 'invalid', :to => TestController.action(:invalid)
|
||||
match 'b00m', :to => TestController.action(:b00m)
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -224,9 +224,8 @@ class UrlWriterTests < ActionController::TestCase
|
|||
def test_named_routes
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.no_args '/this/is/verbose', :controller => 'home', :action => 'index'
|
||||
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
||||
map.connect ':controller/:action/:id'
|
||||
match 'this/is/verbose', :to => 'home#index', :as => :no_args
|
||||
match 'home/sweet/home/:user', :to => 'home#index', :as => :home
|
||||
end
|
||||
|
||||
# We need to create a new class in order to install the new named route.
|
||||
|
@ -264,7 +263,7 @@ class UrlWriterTests < ActionController::TestCase
|
|||
def test_only_path
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
||||
match 'home/sweet/home/:user', :to => 'home#index', :as => :home
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
||||
|
||||
|
@ -334,7 +333,6 @@ class UrlWriterTests < ActionController::TestCase
|
|||
set.draw do |map|
|
||||
map.main '', :controller => 'posts', :format => nil
|
||||
map.resources :posts
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
||||
|
||||
# We need to create a new class in order to install the new named route.
|
||||
|
|
|
@ -125,8 +125,8 @@ class VerificationTest < ActionController::TestCase
|
|||
assert_not_deprecated do
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.foo '/foo', :controller => 'test', :action => 'foo'
|
||||
map.connect ":controller/:action/:id"
|
||||
match 'foo', :to => 'test#foo', :as => :foo
|
||||
match 'verification_test/:action', :to => TestController
|
||||
end
|
||||
get :guarded_one_for_named_route_test, :two => "not one"
|
||||
assert_redirected_to '/foo'
|
||||
|
|
|
@ -57,7 +57,7 @@ class JsonParamsParsingTest < ActionController::IntegrationTest
|
|||
def with_test_routing
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect ':action', :controller => "json_params_parsing_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -109,7 +109,7 @@ class QueryStringParsingTest < ActionController::IntegrationTest
|
|||
def assert_parses(expected, actual)
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect ':action', :controller => "query_string_parsing_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
|
||||
get "/parse", actual
|
||||
|
|
|
@ -130,7 +130,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
|
|||
def with_test_routing
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -84,7 +84,7 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
|
|||
def with_test_routing
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect ':action', :controller => "xml_params_parsing_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -219,7 +219,7 @@ class CookieStoreTest < ActionController::IntegrationTest
|
|||
def with_test_route_set(options = {})
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect "/:action", :controller => "cookie_store_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
|
||||
@app = ActionDispatch::Session::CookieStore.new(set, options)
|
||||
|
|
|
@ -112,7 +112,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
|
|||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.connect "/:action", :controller => "mem_cache_store_test/test"
|
||||
match ':action', :to => TestController
|
||||
end
|
||||
@app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
|
||||
yield
|
||||
|
|
|
@ -48,8 +48,7 @@ class PeopleHelperTest < ActionView::TestCase
|
|||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.people 'people', :controller => 'people', :action => 'index'
|
||||
map.connect ':controller/:action/:id'
|
||||
match 'people', :to => 'people#index', :as => :people
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue