Permalink
Browse files

Start rewriting some internal tests to use the new routing dsl

  • Loading branch information...
1 parent 207d048 commit a5c82a9dfb6d63bf90a3378da0b71d6ea592d7e3 @josh josh committed Oct 20, 2009
@@ -109,6 +109,10 @@ def self.middleware
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 @@ class ContainedNonEmptyController < ActionController::Base
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 @@ def setup
@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 @@ def use_controller(controller_class)
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 @@ def test_generate_url_with_controller
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 @@ def show_errors(exception)
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 @@ def test_relative_url_root_is_respected
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 @@ def test_relative_url_root_is_respected_for_named_routes
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 @@ def test_named_routes_with_nil_keys
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 @@ def test_no_deprecation_warning_for_named_route
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 @@ def assert_parses(expected, actual, headers = {})
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 @@ def teardown
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 @@ def teardown
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 @@ def teardown
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 @@ def test_session_store_with_expire_after
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 @@ def test_prevents_session_fixation
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 @@ def test_link_to_person
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

0 comments on commit a5c82a9

Please sign in to comment.