aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb22
-rw-r--r--actionpack/test/controller/base_test.rb13
-rw-r--r--actionpack/test/controller/benchmark_test.rb33
-rw-r--r--actionpack/test/controller/caching_test.rb12
-rw-r--r--actionpack/test/controller/cookie_test.rb35
-rw-r--r--actionpack/test/controller/dispatcher_test.rb13
-rw-r--r--actionpack/test/controller/filter_params_test.rb2
-rw-r--r--actionpack/test/controller/flash_test.rb45
-rw-r--r--actionpack/test/controller/helper_test.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/controller/logging_test.rb66
-rw-r--r--actionpack/test/controller/mime_responds_test.rb67
-rw-r--r--actionpack/test/controller/redirect_test.rb4
-rw-r--r--actionpack/test/controller/render_other_test.rb14
-rw-r--r--actionpack/test/controller/render_test.rb68
-rw-r--r--actionpack/test/controller/render_xml_test.rb4
-rw-r--r--actionpack/test/controller/request_forgery_protection_test.rb20
-rw-r--r--actionpack/test/controller/resources_test.rb8
-rw-r--r--actionpack/test/controller/routing_test.rb317
-rw-r--r--actionpack/test/controller/test_test.rb25
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb10
-rw-r--r--actionpack/test/controller/webservice_test.rb4
22 files changed, 345 insertions, 441 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 901cb940ea..d54be9bdc0 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -221,8 +221,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_named_route
with_routing do |set|
set.draw do |map|
- map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
- map.connect ':controller/:action/:id'
+ match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one
+ match ':controller/:action'
end
set.install_helpers
@@ -235,9 +235,9 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_named_route_failure
with_routing do |set|
set.draw do |map|
- map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'one'
- map.route_two 'route_two', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
- map.connect ':controller/:action/:id'
+ match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one
+ match 'route_two', :to => 'action_pack_assertions#nothing', :id => 'two', :as => :route_two
+ match ':controller/:action'
end
process :redirect_to_named_route
assert_raise(ActiveSupport::TestCase::Assertion) do
@@ -255,8 +255,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_nested_named_route
with_routing do |set|
set.draw do |map|
- map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
- map.connect ':controller/:action/:id'
+ match 'admin/inner_module', :to => 'admin/inner_module#index', :as => :admin_inner_module
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_index
@@ -268,8 +268,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirected_to_top_level_named_route_from_nested_controller
with_routing do |set|
set.draw do |map|
- map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index'
- map.connect ':controller/:action/:id'
+ match '/action_pack_assertions/:id', :to => 'action_pack_assertions#index', :as => :top_level
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
@@ -282,8 +282,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
with_routing do |set|
set.draw do |map|
# this controller exists in the admin namespace as well which is the only difference from previous test
- map.top_level '/user/:id', :controller => 'user', :action => 'index'
- map.connect ':controller/:action/:id'
+ match '/user/:id', :to => 'user#index', :as => :top_level
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index b57550a69a..65118f9bc9 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -158,13 +158,6 @@ class PerformActionTest < ActionController::TestCase
assert_raise(ActionController::UnknownAction) { get :hidden_action }
assert_raise(ActionController::UnknownAction) { get :another_hidden_action }
end
-
- def test_namespaced_action_should_log_module_name
- use_controller Submodule::ContainedNonEmptyController
- @controller.logger = MockLogger.new
- get :public_action
- assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1]
- end
end
class DefaultUrlOptionsTest < ActionController::TestCase
@@ -179,8 +172,8 @@ class DefaultUrlOptionsTest < ActionController::TestCase
def test_default_url_options_are_used_if_set
with_routing do |set|
set.draw do |map|
- map.default_url_options 'default_url_options', :controller => 'default_url_options'
- map.connect ':controller/:action/:id'
+ match 'default_url_options', :to => 'default_url_options#default_url_options_action', :as => :default_url_options
+ match ':controller/:action'
end
get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
@@ -210,7 +203,7 @@ class EnsureNamedRoutesWorksTicket22BugTest < ActionController::TestCase
def test_named_routes_still_work
with_routing do |set|
set.draw do |map|
- map.resources :things
+ resources :things
end
EmptyController.send :include, ActionController::UrlWriter
diff --git a/actionpack/test/controller/benchmark_test.rb b/actionpack/test/controller/benchmark_test.rb
deleted file mode 100644
index 66ebfcf20a..0000000000
--- a/actionpack/test/controller/benchmark_test.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require 'abstract_unit'
-
-# Provide some static controllers.
-class BenchmarkedController < ActionController::Base
- def public_action
- render :nothing => true
- end
-
- def rescue_action(e)
- raise e
- end
-end
-
-class BenchmarkTest < ActionController::TestCase
- tests BenchmarkedController
-
- class MockLogger
- def method_missing(*args)
- end
- end
-
- def setup
- super
- # benchmark doesn't do anything unless a logger is set
- @controller.logger = MockLogger.new
- @request.host = "test.actioncontroller.i"
- end
-
- def test_with_http_1_0_request
- @request.host = nil
- assert_nothing_raised { get :public_action }
- end
-end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 3ce90b6ccf..679eaf7b38 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -70,8 +70,8 @@ class PageCachingTest < ActionController::TestCase
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
with_routing do |set|
set.draw do |map|
- map.main '', :controller => 'posts', :format => nil
- map.formatted_posts 'posts.:format', :controller => 'posts'
+ match 'posts.:format', :to => 'posts#index', :as => :formatted_posts
+ match '/', :to => 'posts#index', :as => :main
end
@params[:format] = 'rss'
assert_equal '/posts.rss', @rewriter.rewrite(@params)
@@ -422,8 +422,7 @@ class ActionCacheTest < ActionController::TestCase
def test_xml_version_of_resource_is_treated_as_different_cache
with_routing do |set|
set.draw do |map|
- map.connect ':controller/:action.:format'
- map.connect ':controller/:action'
+ match ':controller(/:action(.:format))'
end
get :index, :format => 'xml'
@@ -632,13 +631,16 @@ class FragmentCachingTest < ActionController::TestCase
def test_fragment_for_logging
fragment_computed = false
- ActiveSupport::Notifications.queue.expects(:publish).times(2)
+ events = []
+ ActiveSupport::Notifications.subscribe { |*args| events << args }
buffer = 'generated till now -> '
@controller.fragment_for(buffer, 'expensive') { fragment_computed = true }
assert fragment_computed
assert_equal 'generated till now -> ', buffer
+ ActiveSupport::Notifications.notifier.wait
+ assert_equal [:exist_fragment?, :write_fragment], events.map(&:first)
end
end
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 53d4364576..c8e8b3857e 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -1,5 +1,7 @@
require 'abstract_unit'
+ActionController::Base.cookie_verifier_secret = "thisISverySECRET123"
+
class CookieTest < ActionController::TestCase
class TestController < ActionController::Base
def authenticate
@@ -47,6 +49,21 @@ class CookieTest < ActionController::TestCase
cookies["user_name"] = { :value => "david", :httponly => true }
head :ok
end
+
+ def set_permanent_cookie
+ cookies.permanent[:user_name] = "Jamie"
+ head :ok
+ end
+
+ def set_signed_cookie
+ cookies.signed[:user_id] = 45
+ head :ok
+ end
+
+ def set_permanent_signed_cookie
+ cookies.permanent.signed[:remember_me] = 100
+ head :ok
+ end
end
tests TestController
@@ -134,6 +151,24 @@ class CookieTest < ActionController::TestCase
response = get :authenticate
assert response.headers["Set-Cookie"] =~ /user_name=david/
end
+
+ def test_permanent_cookie
+ get :set_permanent_cookie
+ assert_match /Jamie/, @response.headers["Set-Cookie"]
+ assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
+ end
+
+ def test_signed_cookie
+ get :set_signed_cookie
+ assert_equal 45, @controller.send(:cookies).signed[:user_id]
+ end
+
+ def test_permanent_signed_cookie
+ get :set_permanent_signed_cookie
+ assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
+ assert_equal 100, @controller.send(:cookies).signed[:remember_me]
+ end
+
private
def assert_cookie_header(expected)
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index 622d67287d..64f1ad7610 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -15,7 +15,6 @@ class DispatcherTest < Test::Unit::TestCase
ActionDispatch::Callbacks.reset_callbacks(:call)
ActionController::Routing::Routes.stubs(:call).returns([200, {}, 'response'])
- ActionController::Routing::Routes.stubs(:reload)
Dispatcher.stubs(:require_dependency)
end
@@ -28,18 +27,6 @@ class DispatcherTest < Test::Unit::TestCase
dispatch(false)
end
- def test_reloads_routes_before_dispatch_if_in_loading_mode
- ActionController::Routing::Routes.expects(:reload).once
- dispatch(false)
- end
-
- def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
- ActionController::Routing::Routes.expects(:reload).never
- ActiveSupport::Dependencies.expects(:clear).never
-
- dispatch
- end
-
def test_prepare_callbacks
a = b = c = nil
ActionDispatch::Callbacks.to_prepare { |*args| a = b = c = 1 }
diff --git a/actionpack/test/controller/filter_params_test.rb b/actionpack/test/controller/filter_params_test.rb
index 43bef34885..420ebeacf4 100644
--- a/actionpack/test/controller/filter_params_test.rb
+++ b/actionpack/test/controller/filter_params_test.rb
@@ -70,9 +70,9 @@ class FilterParamTest < ActionController::TestCase
FilterParamController.filter_parameter_logging(:lifo, :amount)
get :payment, :lifo => 'Pratik', :amount => '420', :step => '1'
+ ActiveSupport::Notifications.notifier.wait
filtered_params_logs = logs.detect {|l| l =~ /\AParameters/ }
-
assert filtered_params_logs.index('"amount"=>"[FILTERED]"')
assert filtered_params_logs.index('"lifo"=>"[FILTERED]"')
assert filtered_params_logs.index('"step"=>"1"')
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index c448f36cb3..a9b60386f1 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -34,7 +34,7 @@ class FlashTest < ActionController::TestCase
flash.keep
render :inline => "hello"
end
-
+
def use_flash_and_update_it
flash.update("this" => "hello again")
@flash_copy = {}.update flash
@@ -72,6 +72,18 @@ class FlashTest < ActionController::TestCase
redirect_to :action => "std_action"
@flash_copy = {}.update(flash)
end
+
+ def redirect_with_alert
+ redirect_to '/nowhere', :alert => "Beware the nowheres!"
+ end
+
+ def redirect_with_notice
+ redirect_to '/somewhere', :notice => "Good luck in the somewheres!"
+ end
+
+ def redirect_with_other_flashes
+ redirect_to '/wonderland', :flash => { :joyride => "Horses!" }
+ end
end
tests TestController
@@ -89,7 +101,7 @@ class FlashTest < ActionController::TestCase
def test_keep_flash
get :set_flash
-
+
get :use_flash_and_keep_it
assert_equal "hello", assigns["flash_copy"]["that"]
assert_equal "hello", assigns["flashy"]
@@ -100,7 +112,7 @@ class FlashTest < ActionController::TestCase
get :use_flash
assert_nil assigns["flash_copy"]["that"], "On third flash"
end
-
+
def test_flash_now
get :set_flash_now
assert_equal "hello", assigns["flash_copy"]["that"]
@@ -111,8 +123,8 @@ class FlashTest < ActionController::TestCase
assert_nil assigns["flash_copy"]["that"]
assert_nil assigns["flash_copy"]["foo"]
assert_nil assigns["flashy"]
- end
-
+ end
+
def test_update_flash
get :set_flash
get :use_flash_and_update_it
@@ -128,7 +140,7 @@ class FlashTest < ActionController::TestCase
assert_equal "hello", assigns["flashy_that"]
assert_equal "good-bye", assigns["flashy_this"]
assert_nil assigns["flashy_that_reset"]
- end
+ end
def test_does_not_set_the_session_if_the_flash_is_empty
get :std_action
@@ -153,11 +165,26 @@ class FlashTest < ActionController::TestCase
assert_equal(:foo_indeed, flash.discard(:foo)) # valid key passed
assert_nil flash.discard(:unknown) # non existant key passed
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard()) # nothing passed
- assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard(nil)) # nothing passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard(nil)) # nothing passed
assert_equal(:foo_indeed, flash.keep(:foo)) # valid key passed
assert_nil flash.keep(:unknown) # non existant key passed
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep()) # nothing passed
- assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep(nil)) # nothing passed
+ assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep(nil)) # nothing passed
+ end
+
+ def test_redirect_to_with_alert
+ get :redirect_with_alert
+ assert_equal "Beware the nowheres!", @controller.send(:flash)[:alert]
+ end
+
+ def test_redirect_to_with_notice
+ get :redirect_with_notice
+ assert_equal "Good luck in the somewheres!", @controller.send(:flash)[:notice]
+ end
+
+ def test_redirect_to_with_other_flashes
+ get :redirect_with_other_flashes
+ assert_equal "Horses!", @controller.send(:flash)[:joyride]
end
-end
+end \ No newline at end of file
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index b9be163904..9030e562bb 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -191,7 +191,7 @@ class IsolatedHelpersTest < Test::Unit::TestCase
end
def test_helper_in_a
- assert_raise(ActionView::TemplateError) { call_controller(A, "index") }
+ assert_raise(ActionView::Template::Error) { call_controller(A, "index") }
end
def test_helper_in_b
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index feb2f81cc1..f635253156 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -115,7 +115,7 @@ class RendersNoLayoutController < LayoutTest
end
class LayoutSetInResponseTest < ActionController::TestCase
- include ActionView::TemplateHandlers
+ include ActionView::Template::Handlers
def test_layout_set_when_using_default_layout
@controller = DefaultLayoutController.new
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 2b5e8d8bde..4206dffa7e 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -1,48 +1,74 @@
require 'abstract_unit'
-class LoggingController < ActionController::Base
- def show
- render :nothing => true
- end
-end
-
-class LoggingTest < ActionController::TestCase
- tests LoggingController
-
- class MockLogger
- attr_reader :logged
- attr_accessor :level
+module Another
+ class LoggingController < ActionController::Base
+ layout "layouts/standard"
- def initialize
- @level = Logger::DEBUG
+ def show
+ render :nothing => true
end
- def method_missing(method, *args, &blk)
- @logged ||= []
- @logged << args.first
- @logged << blk.call if block_given?
+ def with_layout
+ render :template => "test/hello_world", :layout => true
end
end
+end
+
+class LoggingTest < ActionController::TestCase
+ tests Another::LoggingController
def setup
super
set_logger
end
+ def get(*args)
+ super
+ wait
+ end
+
+ def wait
+ ActiveSupport::Notifications.notifier.wait
+ end
+
def test_logging_without_parameters
get :show
- assert_equal 3, logs.size
+ assert_equal 4, logs.size
assert_nil logs.detect {|l| l =~ /Parameters/ }
end
def test_logging_with_parameters
get :show, :id => '10'
- assert_equal 4, logs.size
+ assert_equal 5, logs.size
params = logs.detect {|l| l =~ /Parameters/ }
assert_equal 'Parameters: {"id"=>"10"}', params
end
+ def test_log_controller_with_namespace_and_action
+ get :show
+ assert_match /Processed\sAnother::LoggingController#show/, logs[1]
+ end
+
+ def test_log_view_runtime
+ get :show
+ assert_match /View runtime/, logs[2]
+ end
+
+ def test_log_completed_status_and_request_uri
+ get :show
+ last = logs.last
+ assert_match /Completed/, last
+ assert_match /200/, last
+ assert_match /another\/logging\/show/, last
+ end
+
+ def test_logger_prints_layout_and_template_rendering_info
+ get :with_layout
+ logged = logs.find {|l| l =~ /render/i }
+ assert_match /Rendered (.*)test\/hello_world.erb within (.*)layouts\/standard.html.erb/, logged
+ end
+
private
def set_logger
@controller.logger = MockLogger.new
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index fee9cf46f9..6b9cace9cd 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -507,6 +507,13 @@ class RespondWithController < ActionController::Base
end
end
+ def using_responder_with_respond
+ responder = Class.new(ActionController::Responder) do
+ def respond; @controller.render :text => "respond #{format}"; end
+ end
+ respond_with(Customer.new("david", 13), :responder => responder)
+ end
+
protected
def _render_js(js, options)
@@ -592,14 +599,18 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_post_with_html
+ def test_using_resource_for_post_with_html_redirects_on_success
with_test_route_set do
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
+ end
+ end
+ def test_using_resource_for_post_with_html_rerender_on_failure
+ with_test_route_set do
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
@@ -610,16 +621,20 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_post_with_xml
+ def test_using_resource_for_post_with_xml_yields_created_on_success
with_test_route_set do
@request.accept = "application/xml"
-
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/customers/13", @response.location
+ end
+ end
+ def test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure
+ with_test_route_set do
+ @request.accept = "application/xml"
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
@@ -630,14 +645,18 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_put_with_html
+ def test_using_resource_for_put_with_html_redirects_on_success
with_test_route_set do
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
+ end
+ end
+ def test_using_resource_for_put_with_html_rerender_on_failure
+ with_test_route_set do
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
@@ -648,14 +667,16 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_put_with_xml
+ def test_using_resource_for_put_with_xml_yields_ok_on_success
@request.accept = "application/xml"
-
put :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal " ", @response.body
+ end
+ def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
+ @request.accept = "application/xml"
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
@@ -665,7 +686,7 @@ class RespondWithControllerTest < ActionController::TestCase
assert_nil @response.location
end
- def test_using_resource_for_delete_with_html
+ def test_using_resource_for_delete_with_html_redirects_on_success
with_test_route_set do
Customer.any_instance.stubs(:destroyed?).returns(true)
delete :using_resource
@@ -675,7 +696,7 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_delete_with_xml
+ def test_using_resource_for_delete_with_xml_yields_ok_on_success
Customer.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/xml"
delete :using_resource
@@ -684,6 +705,18 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal " ", @response.body
end
+ def test_using_resource_for_delete_with_html_redirects_on_failure
+ with_test_route_set do
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ Customer.any_instance.stubs(:destroyed?).returns(false)
+ delete :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ end
+ end
+
def test_using_resource_with_parent_for_get
@request.accept = "application/xml"
get :using_resource_with_parent
@@ -735,6 +768,16 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal "foo - #{[:html].to_s}", @controller.response_body
end
+ def test_respond_as_responder_entry_point
+ @request.accept = "text/html"
+ get :using_responder_with_respond
+ assert_equal "respond html", @response.body
+
+ @request.accept = "application/xml"
+ get :using_responder_with_respond
+ assert_equal "respond xml", @response.body
+ end
+
def test_clear_respond_to
@controller = InheritedRespondWithController.new
@request.accept = "text/html"
@@ -810,9 +853,11 @@ class RespondWithControllerTest < ActionController::TestCase
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.resources :quiz_stores, :has_many => :customers
- map.connect ":controller/:action/:id"
+ resources :customers
+ resources :quiz_stores do
+ resources :customers
+ end
+ match ":controller/:action"
end
yield
end
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index ea278fd8f0..570ff4a41b 100644
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -233,8 +233,8 @@ class RedirectTest < ActionController::TestCase
def test_redirect_to_record
with_routing do |set|
set.draw do |map|
- map.resources :workshops
- map.connect ':controller/:action/:id'
+ resources :workshops
+ match ':controller/:action'
end
get :redirect_to_existing_record
diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb
index 51c3c55545..dfc4f2db8c 100644
--- a/actionpack/test/controller/render_other_test.rb
+++ b/actionpack/test/controller/render_other_test.rb
@@ -2,6 +2,11 @@ require 'abstract_unit'
require 'controller/fake_models'
require 'pathname'
+ActionController.add_renderer :simon do |says, options|
+ self.content_type = Mime::TEXT
+ self.response_body = "Simon says: #{says}"
+end
+
class RenderOtherTest < ActionController::TestCase
class TestController < ActionController::Base
protect_from_forgery
@@ -109,6 +114,10 @@ class RenderOtherTest < ActionController::TestCase
end
end
+ def render_simon_says
+ render :simon => "foo"
+ end
+
private
def default_render
if @alternate_default_render
@@ -240,4 +249,9 @@ class RenderOtherTest < ActionController::TestCase
xhr :get, :render_alternate_default
assert_equal %(Element.replace("foo", "partial html");), @response.body
end
+
+ def test_using_custom_render_option
+ get :render_simon_says
+ assert_equal "Simon says: foo", @response.body
+ end
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index b32325fa20..2c3dc2a72d 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -10,19 +10,6 @@ module Fun
end
end
-class MockLogger
- attr_reader :logged
-
- def initialize
- @logged = []
- end
-
- def method_missing(method, *args, &blk)
- @logged << args.first
- @logged << blk.call if block_given?
- end
-end
-
class TestController < ActionController::Base
protect_from_forgery
@@ -39,35 +26,35 @@ class TestController < ActionController::Base
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_public_header
if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_public_header_and_expires_at
expires_in 1.minute
if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_expires_in
- expires_in 1.minute
+ expires_in 60.1.seconds
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public
expires_in 1.minute, :public => true
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public_with_more_keys
expires_in 1.minute, :public => true, 'max-stale' => 5.hours
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours
render :action => 'hello_world'
@@ -272,7 +259,7 @@ class TestController < ActionController::Base
def builder_layout_test
render :action => "hello", :layout => "layouts/builder"
end
-
+
# :move: test this in ActionView
def builder_partial_test
render :action => "hello_world_container"
@@ -1093,8 +1080,8 @@ class RenderTest < ActionController::TestCase
def test_head_with_location_object
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.connect ':controller/:action/:id'
+ resources :customers
+ match ':controller/:action'
end
get :head_with_location_object
@@ -1125,7 +1112,7 @@ class RenderTest < ActionController::TestCase
assert !@response.headers.include?('Content-Length')
assert_response :no_content
- ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
+ Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |status, code|
get :head_with_symbolic_status, :status => status.to_s
assert_equal code, @response.response_code
assert_response status
@@ -1133,7 +1120,7 @@ class RenderTest < ActionController::TestCase
end
def test_head_with_integer_status
- ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message|
+ Rack::Utils::HTTP_STATUS_CODES.each do |code, message|
get :head_with_integer_status, :status => code.to_s
assert_equal message, @response.message
end
@@ -1306,22 +1293,22 @@ class ExpiresInRenderTest < ActionController::TestCase
def setup
@request.host = "www.nextangle.com"
end
-
+
def test_expires_in_header
get :conditional_hello_with_expires_in
assert_equal "max-age=60, private", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_header_with_public
get :conditional_hello_with_expires_in_with_public
assert_equal "max-age=60, public", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_header_with_additional_headers
get :conditional_hello_with_expires_in_with_public_with_more_keys
assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_old_syntax
get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
@@ -1425,12 +1412,12 @@ class EtagRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :not_modified
end
-
+
def test_etag_with_public_true_should_set_header
get :conditional_hello_with_public_header
assert_equal "public", @response.headers['Cache-Control']
end
-
+
def test_etag_with_public_true_should_set_header_and_retain_other_headers
get :conditional_hello_with_public_header_and_expires_at
assert_equal "max-age=60, public", @response.headers['Cache-Control']
@@ -1500,21 +1487,4 @@ class LastModifiedRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :success
end
-end
-
-class RenderingLoggingTest < ActionController::TestCase
- tests TestController
-
- def setup
- super
- @request.host = "www.nextangle.com"
- end
-
- def test_logger_prints_layout_and_template_rendering_info
- @controller.logger = MockLogger.new
- get :layout_test
- logged = @controller.logger.logged.find_all {|l| l =~ /render/i }
- assert logged[0] =~ %r{Rendering.*test/hello_world}
- assert logged[1] =~ %r{Rendering template within.*layouts/standard}
- end
-end
+end \ No newline at end of file
diff --git a/actionpack/test/controller/render_xml_test.rb b/actionpack/test/controller/render_xml_test.rb
index 68a52c3e8c..b5b0d0b9d5 100644
--- a/actionpack/test/controller/render_xml_test.rb
+++ b/actionpack/test/controller/render_xml_test.rb
@@ -61,8 +61,8 @@ class RenderXmlTest < ActionController::TestCase
def test_rendering_with_object_location_should_set_header_with_url_for
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.connect ':controller/:action/:id'
+ resources :customers
+ match ':controller/:action'
end
get :render_with_object_location
diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb
index 7111796f8d..09003adf73 100644
--- a/actionpack/test/controller/request_forgery_protection_test.rb
+++ b/actionpack/test/controller/request_forgery_protection_test.rb
@@ -18,7 +18,7 @@ module RequestForgeryProtectionActions
def unsafe
render :text => 'pwn'
end
-
+
def rescue_action(e) raise e end
end
@@ -40,6 +40,13 @@ class FreeCookieController < RequestForgeryProtectionController
end
end
+class CustomAuthenticityParamController < RequestForgeryProtectionController
+ def form_authenticity_param
+ 'foobar'
+ end
+end
+
+
# common test methods
module RequestForgeryProtectionTests
@@ -241,3 +248,14 @@ class FreeCookieControllerTest < ActionController::TestCase
end
end
end
+
+class CustomAuthenticityParamControllerTest < ActionController::TestCase
+ def setup
+ ActionController::Base.request_forgery_protection_token = :authenticity_token
+ end
+
+ def test_should_allow_custom_token
+ post :index, :authenticity_token => 'foobar'
+ assert_response :ok
+ end
+end
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index 04e9acf855..1a03396ae9 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -403,7 +403,7 @@ class ResourcesTest < ActionController::TestCase
with_restful_routing :messages do
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
end
end
@@ -689,11 +689,11 @@ class ResourcesTest < ActionController::TestCase
options = { :controller => controller_name.to_s }
collection_path = "/#{controller_name}"
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
assert_recognizes(options.merge(:action => 'update'), :path => collection_path, :method => :put)
end
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
assert_recognizes(options.merge(:action => 'destroy'), :path => collection_path, :method => :delete)
end
end
@@ -1378,7 +1378,7 @@ class ResourcesTest < ActionController::TestCase
end
def assert_not_recognizes(expected_options, path)
- assert_raise ActionController::RoutingError, ActionController::MethodNotAllowed, Assertion do
+ assert_raise ActionController::RoutingError, Assertion do
assert_recognizes(expected_options, path)
end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 3971aacadb..c15eaade58 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -51,30 +51,6 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
end
end
-class RoutingTest < Test::Unit::TestCase
- 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 .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 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 .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 config .bar lib .), paths
- end
-
- def test_routing_helper_module
- assert_kind_of Module, ActionController::Routing::Helpers
-
- h = ActionController::Routing::Helpers
- c = Class.new
- assert ! c.ancestors.include?(h)
- ActionController::Routing::Routes.install_helpers c
- assert c.ancestors.include?(h)
- end
-end
-
class MockController
attr_accessor :routes
@@ -578,10 +554,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase
end
def setup_request_method_routes_for(method)
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = method
- @request.request_uri = "/match"
-
rs.draw do |r|
r.connect '/match', :controller => 'books', :action => 'get', :conditions => { :method => :get }
r.connect '/match', :controller => 'books', :action => 'post', :conditions => { :method => :post }
@@ -593,8 +565,8 @@ class LegacyRouteSetTests < Test::Unit::TestCase
%w(GET POST PUT DELETE).each do |request_method|
define_method("test_request_method_recognized_with_#{request_method}") do
setup_request_method_routes_for(request_method)
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal request_method.downcase, @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => request_method)
+ assert_equal request_method.downcase, params[:action]
end
end
@@ -604,18 +576,11 @@ class LegacyRouteSetTests < Test::Unit::TestCase
r.connect '/match', :controller => 'books', :action => 'not_get_or_post'
end
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = 'POST'
- @request.request_uri = "/match"
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal 'get_or_post', @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => :post)
+ assert_equal 'get_or_post', params[:action]
- # have to recreate or else the RouteSet uses a cached version:
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = 'PUT'
- @request.request_uri = "/match"
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal 'not_get_or_post', @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => :put)
+ assert_equal 'not_get_or_post', params[:action]
end
def test_subpath_recognized
@@ -769,9 +734,7 @@ class RouteSetTest < ActiveSupport::TestCase
set.draw do |map|
map.connect '/users/index', :controller => :users, :action => :index
end
- @request = ActionController::TestRequest.new
- @request.request_uri = '/users/index'
- assert_nothing_raised { set.recognize(@request) }
+ params = set.recognize_path('/users/index', :method => :get)
assert_equal 1, set.routes.size
end
@@ -1004,55 +967,34 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.request_uri = "/people"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("index", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :get)
+ assert_equal("index", params[:action])
- request.env["REQUEST_METHOD"] = "POST"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("create", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :post)
+ assert_equal("create", params[:action])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :put)
+ assert_equal("update", params[:action])
- assert_raise(ActionController::UnknownHttpMethod) {
- request.env["REQUEST_METHOD"] = "BACON"
- set.recognize(request)
+ assert_raise(ActionController::RoutingError) {
+ set.recognize_path("/people", :method => :bacon)
}
- request.recycle!
- request.request_uri = "/people/5"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :put)
+ assert_equal("update", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "DELETE"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("destroy", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :delete)
+ assert_equal("destroy", params[:action])
+ assert_equal("5", params[:id])
- begin
- request.env["REQUEST_METHOD"] = "POST"
- set.recognize(request)
- flunk 'Should have raised MethodNotAllowed'
- rescue ActionController::MethodNotAllowed => e
- assert_equal [:get, :put, :delete], e.allowed_methods
- end
- request.recycle!
+ assert_raise(ActionController::RoutingError) {
+ set.recognize_path("/people/5", :method => :post)
+ }
end
def test_recognize_with_alias_in_conditions
@@ -1062,17 +1004,13 @@ class RouteSetTest < ActiveSupport::TestCase
map.root :people
end
- request.path = "/people"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/people", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
- request.path = "/"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
end
def test_typo_recognition
@@ -1082,14 +1020,12 @@ class RouteSetTest < ActiveSupport::TestCase
:year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/
end
- request.path = "/articles/2005/11/05/a-very-interesting-article"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("permalink", request.path_parameters[:action])
- assert_equal("2005", request.path_parameters[:year])
- assert_equal("11", request.path_parameters[:month])
- assert_equal("05", request.path_parameters[:day])
- assert_equal("a-very-interesting-article", request.path_parameters[:title])
+ params = set.recognize_path("/articles/2005/11/05/a-very-interesting-article", :method => :get)
+ assert_equal("permalink", params[:action])
+ assert_equal("2005", params[:year])
+ assert_equal("11", params[:month])
+ assert_equal("05", params[:day])
+ assert_equal("a-very-interesting-article", params[:title])
end
def test_routing_traversal_does_not_load_extra_classes
@@ -1098,9 +1034,7 @@ class RouteSetTest < ActiveSupport::TestCase
map.connect '/profile', :controller => 'profile'
end
- request.path = '/profile'
-
- set.recognize(request) rescue nil
+ params = set.recognize_path("/profile") rescue nil
assert !Object.const_defined?("Profiler__"), "Profiler should not be loaded"
end
@@ -1114,24 +1048,17 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.request_uri = "/people/5"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :put)
+ assert_equal("update", params[:action])
- request.request_uri = "/people/5.png"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- assert_equal("png", request.path_parameters[:_format])
+ params = set.recognize_path("/people/5.png", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
+ assert_equal("png", params[:_format])
end
def test_generate_with_default_action
@@ -1147,11 +1074,9 @@ class RouteSetTest < ActiveSupport::TestCase
def test_root_map
set.draw { |map| map.root :controller => "people" }
- request.path = ""
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
end
def test_namespace
@@ -1163,11 +1088,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
- request.path = "/api/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/api/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_namespaced_root_map
@@ -1179,11 +1102,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
- request.path = "/api"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/api", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("index", params[:action])
end
def test_namespace_with_path_prefix
@@ -1193,11 +1114,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/prefix/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/prefix/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_namespace_with_blank_path_prefix
@@ -1207,11 +1126,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_generate_changes_controller_module
@@ -1340,11 +1257,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/projects/1/milestones"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("milestones", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/projects/1/milestones", :method => :get)
+ assert_equal("milestones", params[:controller])
+ assert_equal("index", params[:action])
end
def test_setting_root_in_namespace_using_symbol
@@ -1418,6 +1333,7 @@ class RouteSetTest < ActiveSupport::TestCase
:action => 'show',
:requirements => {:name => /(david|jamis)/i}
end
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
assert_equal "/page/david", url
assert_raise ActionController::RoutingError do
@@ -1459,6 +1375,7 @@ class RouteSetTest < ActiveSupport::TestCase
jamis #The Deployer
)/x}
end
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
assert_equal "/page/david", url
assert_raise ActionController::RoutingError do
@@ -1480,6 +1397,7 @@ class RouteSetTest < ActiveSupport::TestCase
jamis #The Deployer
)/xi}
end
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
assert_equal "/page/JAMIS", url
end
@@ -1638,7 +1556,7 @@ class RouteSetTest < ActiveSupport::TestCase
end
def test_expand_array_build_query_string
- assert_uri_equal '/foo?x%5B%5D=1&x%5B%5D=2', default_route_set.generate({:controller => 'foo', :x => [1, 2]})
+ assert_uri_equal '/foo?x[]=1&x[]=2', default_route_set.generate({:controller => 'foo', :x => [1, 2]})
end
def test_escape_spaces_build_query_string_selected_keys
@@ -1656,9 +1574,7 @@ class RouteSetTest < ActiveSupport::TestCase
map.connect ':controller/:action/:id'
end
- pending do
- assert_equal '/ibocorp', set.generate({:controller => 'ibocorp', :page => 1})
- end
+ assert_equal '/ibocorp', set.generate({:controller => 'ibocorp', :page => 1})
end
def test_generate_with_optional_params_recalls_last_request
@@ -1691,9 +1607,7 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal("/blog/2006/07/25", set.generate({:day => 25}, last_request))
assert_equal("/blog/2005", set.generate({:year => 2005}, last_request))
assert_equal("/blog/show/123", set.generate({:action => "show" , :id => 123}, last_request))
- pending do
- assert_equal("/blog/2006/07/28", set.generate({:year => 2006}, last_request))
- end
+ assert_equal("/blog/2006", set.generate({:year => 2006}, last_request))
assert_equal("/blog/2006", set.generate({:year => 2006, :month => nil}, last_request))
end
@@ -1709,85 +1623,6 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
-class RouteLoadingTest < Test::Unit::TestCase
- def setup
- routes.instance_variable_set '@routes_last_modified', nil
- Object.remove_const(:RAILS_ROOT) if defined?(::RAILS_ROOT)
- Object.const_set :RAILS_ROOT, '.'
- routes.add_configuration_file(File.join(RAILS_ROOT, 'config', 'routes.rb'))
-
- @stat = stub_everything
- end
-
- def teardown
- ActionController::Routing::Routes.configuration_files.clear
- Object.send :remove_const, :RAILS_ROOT
- end
-
- def test_load
- File.expects(:stat).returns(@stat)
- routes.expects(:load).with(regexp_matches(/routes\.rb$/))
-
- routes.reload
- end
-
- def test_no_reload_when_not_modified
- @stat.expects(:mtime).times(2).returns(1)
- File.expects(:stat).times(2).returns(@stat)
- routes.expects(:load).with(regexp_matches(/routes\.rb$/)).at_most_once
-
- 2.times { routes.reload }
- end
-
- def test_reload_when_modified
- @stat.expects(:mtime).at_least(2).returns(1, 2)
- File.expects(:stat).at_least(2).returns(@stat)
- routes.expects(:load).with(regexp_matches(/routes\.rb$/)).times(2)
-
- 2.times { routes.reload }
- end
-
- def test_bang_forces_reload
- @stat.expects(:mtime).at_least(2).returns(1)
- File.expects(:stat).at_least(2).returns(@stat)
- routes.expects(:load).with(regexp_matches(/routes\.rb$/)).times(2)
-
- 2.times { routes.reload! }
- end
-
- def test_adding_inflections_forces_reload
- ActiveSupport::Inflector::Inflections.instance.expects(:uncountable).with('equipment')
- routes.expects(:reload!)
-
- ActiveSupport::Inflector.inflections { |inflect| inflect.uncountable('equipment') }
- end
-
- def test_load_with_configuration
- routes.configuration_files.clear
- routes.add_configuration_file("foobarbaz")
- File.expects(:stat).returns(@stat)
- routes.expects(:load).with("foobarbaz")
-
- routes.reload
- end
-
- def test_load_multiple_configurations
- routes.add_configuration_file("engines.rb")
-
- File.expects(:stat).at_least_once.returns(@stat)
-
- routes.expects(:load).with('./config/routes.rb')
- routes.expects(:load).with('engines.rb')
-
- routes.reload
- end
-
- private
- def routes
- ActionController::Routing::Routes
- end
-end
-
class RackMountIntegrationTests < ActiveSupport::TestCase
Model = Struct.new(:to_param)
@@ -1877,11 +1712,9 @@ class RackMountIntegrationTests < ActiveSupport::TestCase
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009'}, @routes.recognize_path('/blog/2009', :method => :get))
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009', :month => '01'}, @routes.recognize_path('/blog/2009/01', :method => :get))
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009', :month => '01', :day => '01'}, @routes.recognize_path('/blog/2009/01/01', :method => :get))
- assert_raise(ActionController::ActionControllerError) { @routes.recognize_path('/blog/123456789', :method => :get) }
assert_equal({:controller => 'archive', :action => 'index', :year => '2010'}, @routes.recognize_path('/archive/2010'))
assert_equal({:controller => 'archive', :action => 'index'}, @routes.recognize_path('/archive'))
- assert_raise(ActionController::ActionControllerError) { @routes.recognize_path('/archive/january') }
assert_equal({:controller => 'people', :action => 'index'}, @routes.recognize_path('/people', :method => :get))
assert_equal({:controller => 'people', :action => 'index', :format => 'xml'}, @routes.recognize_path('/people.xml', :method => :get))
@@ -2040,9 +1873,9 @@ class RackMountIntegrationTests < ActiveSupport::TestCase
assert_equal '/posts', @routes.generate({:controller => 'posts'}, {:controller => 'posts', :action => 'index'})
assert_equal '/posts/create', @routes.generate({:action => 'create'}, {:controller => 'posts'})
assert_equal '/posts?foo=bar', @routes.generate(:controller => 'posts', :foo => 'bar')
- assert_equal '/posts?foo%5B%5D=bar&foo%5B%5D=baz', @routes.generate(:controller => 'posts', :foo => ['bar', 'baz'])
+ assert_equal '/posts?foo[]=bar&foo[]=baz', @routes.generate(:controller => 'posts', :foo => ['bar', 'baz'])
assert_equal '/posts?page=2', @routes.generate(:controller => 'posts', :page => 2)
- assert_equal '/posts?q%5Bfoo%5D%5Ba%5D=b', @routes.generate(:controller => 'posts', :q => { :foo => { :a => 'b'}})
+ assert_equal '/posts?q[foo][a]=b', @routes.generate(:controller => 'posts', :q => { :foo => { :a => 'b'}})
assert_equal '/', @routes.generate(:controller => 'news', :action => 'index')
assert_equal '/', @routes.generate(:controller => 'news', :action => 'index', :format => nil)
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 375878b755..0f074b32e6 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -456,8 +456,8 @@ XML
def test_array_path_parameter_handled_properly
with_routing do |set|
set.draw do |map|
- map.connect 'file/*path', :controller => 'test_test/test', :action => 'test_params'
- map.connect ':controller/:action/:id'
+ match 'file/*path', :to => 'test_test/test#test_params'
+ match ':controller/:action'
end
get :test_params, :path => ['hello', 'world']
@@ -563,7 +563,7 @@ XML
expected = File.read(path)
expected.force_encoding(Encoding::BINARY) if expected.respond_to?(:force_encoding)
- file = ActionController::TestUploadedFile.new(path, content_type)
+ file = Rack::Test::UploadedFile.new(path, content_type)
assert_equal filename, file.original_filename
assert_equal content_type, file.content_type
assert_equal file.path, file.local_path
@@ -580,10 +580,10 @@ XML
path = "#{FILES_DIR}/#{filename}"
content_type = 'image/png'
- binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary)
+ binary_uploaded_file = Rack::Test::UploadedFile.new(path, content_type, :binary)
assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
- plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type)
+ plain_uploaded_file = Rack::Test::UploadedFile.new(path, content_type)
assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
end
@@ -605,7 +605,7 @@ XML
end
def test_test_uploaded_file_exception_when_file_doesnt_exist
- assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') }
+ assert_raise(RuntimeError) { Rack::Test::UploadedFile.new('non_existent_file') }
end
def test_redirect_url_only_cares_about_location_header
@@ -628,17 +628,6 @@ XML
assert_nothing_raised(NoMethodError) { @response.binary_content }
end
end
-
- protected
- def with_foo_routing
- with_routing do |set|
- set.draw do |map|
- map.generate_url 'foo', :controller => 'test'
- map.connect ':controller/:action/:id'
- end
- yield set
- end
- end
end
class InferringClassNameTest < ActionController::TestCase
@@ -673,7 +662,7 @@ class NamedRoutesControllerTest < ActionController::TestCase
def test_should_be_able_to_use_named_routes_before_a_request_is_done
with_routing do |set|
- set.draw { |map| map.resources :contents }
+ set.draw { |map| resources :contents }
assert_equal 'http://test.host/contents/new', new_content_url
assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index 3b14cbb2d8..428f40b9f8 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -247,7 +247,7 @@ class UrlWriterTests < ActionController::TestCase
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
end
kls = Class.new { include ActionController::UrlWriter }
@@ -264,7 +264,7 @@ class UrlWriterTests < ActionController::TestCase
with_routing do |set|
set.draw do |map|
match 'home/sweet/home/:user', :to => 'home#index', :as => :home
- map.connect ':controller/:action/:id'
+ match ':controller/:action/:id'
end
# We need to create a new class in order to install the new named route.
@@ -331,8 +331,8 @@ class UrlWriterTests < ActionController::TestCase
def test_named_routes_with_nil_keys
with_routing do |set|
set.draw do |map|
- map.main '', :controller => 'posts', :format => nil
- map.resources :posts
+ match 'posts.:format', :to => 'posts#index', :as => :posts
+ match '/', :to => 'posts#index', :as => :main
end
# We need to create a new class in order to install the new named route.
@@ -350,7 +350,7 @@ class UrlWriterTests < ActionController::TestCase
def test_formatted_url_methods_are_deprecated
with_routing do |set|
set.draw do |map|
- map.resources :posts
+ resources :posts
end
# We need to create a new class in order to install the new named route.
kls = Class.new { include ActionController::UrlWriter }
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index 0514c098bf..5882a8cfa3 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -255,9 +255,7 @@ class WebServiceTest < ActionController::IntegrationTest
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.with_options :controller => "web_service_test/test" do |c|
- c.connect "/", :action => "assign_parameters"
- end
+ match '/', :to => 'web_service_test/test#assign_parameters'
end
yield
end