New Version
Sync with Latest Instiki Trunk. Migrate to Rails 1.2.5. Bump version number.
This commit is contained in:
parent
de125367b0
commit
207fb1f7f2
120 changed files with 2592 additions and 662 deletions
|
@ -19,6 +19,8 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
|
||||
def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end
|
||||
|
||||
def redirect_to_controller_with_symbol() redirect_to :controller => :elsewhere, :action => :flash_me; end
|
||||
|
||||
def redirect_to_path() redirect_to '/some/path' end
|
||||
|
||||
def redirect_to_named_route() redirect_to route_one_url end
|
||||
|
@ -555,6 +557,17 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|||
assert_redirected_to 'http://test.host/some/path'
|
||||
end
|
||||
|
||||
def test_assert_redirection_with_symbol
|
||||
process :redirect_to_controller_with_symbol
|
||||
assert_nothing_raised {
|
||||
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
|
||||
}
|
||||
process :redirect_to_controller_with_symbol
|
||||
assert_nothing_raised {
|
||||
assert_redirected_to :controller => :elsewhere, :action => :flash_me
|
||||
}
|
||||
end
|
||||
|
||||
def test_redirected_to_with_nested_controller
|
||||
@controller = Admin::InnerModuleController.new
|
||||
get :redirect_to_absolute_controller
|
||||
|
|
|
@ -39,7 +39,10 @@ class AddressesTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_list
|
||||
get :list
|
||||
# because pagination is deprecated
|
||||
ActiveSupport::Deprecation.silence do
|
||||
get :list
|
||||
end
|
||||
assert_equal "We only need to get this far!", @response.body.chomp
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,7 +88,7 @@ class ControllerInstanceTests < Test::Unit::TestCase
|
|||
# Mocha adds methods to Object which are then included in the public_instance_methods
|
||||
# This method hides those from the controller so the above tests won't know the difference
|
||||
def hide_mocha_methods_from_controller(controller)
|
||||
mocha_methods = [:expects, :metaclass, :mocha, :mocha_inspect, :reset_mocha, :stubba_object, :stubba_method, :stubs, :verify]
|
||||
mocha_methods = [:expects, :metaclass, :mocha, :mocha_inspect, :reset_mocha, :stubba_object, :stubba_method, :stubs, :verify, :__is_a__, :__metaclass__]
|
||||
controller.class.send(:hide_action, *mocha_methods)
|
||||
end
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ class ActionCachingTestController < ActionController::Base
|
|||
caches_action :index
|
||||
|
||||
def index
|
||||
sleep 0.01
|
||||
@cache_this = Time.now.to_f.to_s
|
||||
render :text => @cache_this
|
||||
end
|
||||
|
@ -195,7 +196,7 @@ class ActionCacheTest < Test::Unit::TestCase
|
|||
def test_xml_version_of_resource_is_treated_as_different_cache
|
||||
@mock_controller.mock_url_for = 'http://example.org/posts/'
|
||||
@mock_controller.mock_path = '/posts/index.xml'
|
||||
path_object = @path_class.new(@mock_controller)
|
||||
path_object = @path_class.new(@mock_controller, {})
|
||||
assert_equal 'xml', path_object.extension
|
||||
assert_equal 'example.org/posts/index.xml', path_object.path
|
||||
end
|
||||
|
@ -204,7 +205,7 @@ class ActionCacheTest < Test::Unit::TestCase
|
|||
@mock_controller.mock_url_for = 'http://example.org/'
|
||||
@mock_controller.mock_path = '/'
|
||||
|
||||
assert_equal 'example.org/index', @path_class.path_for(@mock_controller)
|
||||
assert_equal 'example.org/index', @path_class.path_for(@mock_controller, {})
|
||||
end
|
||||
|
||||
def test_file_extensions
|
||||
|
|
|
@ -31,6 +31,11 @@ class CookieTest < Test::Unit::TestCase
|
|||
cookies.delete("user_name")
|
||||
end
|
||||
|
||||
def delete_cookie_with_path
|
||||
cookies.delete("user_name", :path => '/beaten')
|
||||
render_text "hello world"
|
||||
end
|
||||
|
||||
def rescue_action(e)
|
||||
raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
|
||||
end
|
||||
|
@ -85,4 +90,10 @@ class CookieTest < Test::Unit::TestCase
|
|||
assert_equal "david", jar["user_name"]
|
||||
assert_equal nil, jar["something_else"]
|
||||
end
|
||||
|
||||
def test_delete_cookie_with_path
|
||||
get :delete_cookie_with_path
|
||||
assert_equal "/beaten", @response.headers["cookie"].first.path
|
||||
assert_not_equal "/", @response.headers["cookie"].first.path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require File.dirname(__FILE__) + '/../../abstract_unit'
|
||||
|
||||
class DeprecatedBaseMethodsTest < Test::Unit::TestCase
|
||||
# ActiveRecord model mock to test pagination deprecation
|
||||
class DummyModel
|
||||
def self.find(*args) [] end
|
||||
def self.count(*args) 0 end
|
||||
end
|
||||
|
||||
class Target < ActionController::Base
|
||||
def deprecated_symbol_parameter_to_url_for
|
||||
redirect_to(url_for(:home_url, "superstars"))
|
||||
|
@ -18,6 +24,11 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
|
|||
this_method_doesnt_exist
|
||||
end
|
||||
|
||||
def pagination
|
||||
paginate :dummy_models, :class_name => 'DeprecatedBaseMethodsTest::DummyModel'
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def rescue_action(e) raise e end
|
||||
end
|
||||
|
||||
|
@ -27,6 +38,7 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
|
|||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@controller = Target.new
|
||||
@controller.logger = Logger.new(nil) unless @controller.logger
|
||||
end
|
||||
|
||||
def test_deprecated_symbol_parameter_to_url_for
|
||||
|
@ -57,4 +69,10 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
|
|||
error = Test::Unit::Error.new('testing ur doodz', e)
|
||||
assert_not_deprecated { error.message }
|
||||
end
|
||||
|
||||
def test_pagination_deprecation
|
||||
assert_deprecated('svn://errtheblog.com/svn/plugins/classic_pagination') do
|
||||
get :pagination
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ class FilterParamTest < Test::Unit::TestCase
|
|||
assert @controller.respond_to?(:filter_parameters)
|
||||
|
||||
test_hashes = [[{},{},[]],
|
||||
[{'foo'=>nil},{'foo'=>nil},[]],
|
||||
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
|
||||
[{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
|
||||
[{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
|
||||
|
|
|
@ -14,7 +14,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
@ran_filter ||= []
|
||||
@ran_filter << "ensure_login"
|
||||
end
|
||||
|
||||
|
||||
def clean_up
|
||||
@ran_after_filter ||= []
|
||||
@ran_after_filter << "clean_up"
|
||||
|
@ -62,7 +62,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
render :inline => "something else"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class ConditionalFilterController < ActionController::Base
|
||||
def show
|
||||
render :inline => "ran action"
|
||||
|
@ -86,7 +86,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
@ran_filter ||= []
|
||||
@ran_filter << "clean_up_tmp"
|
||||
end
|
||||
|
||||
|
||||
def rescue_action(e) raise(e) end
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
before_filter :ensure_login, :except => [ :show_without_filter, :another_action ]
|
||||
end
|
||||
|
||||
class OnlyConditionSymController < ConditionalFilterController
|
||||
class OnlyConditionSymController < ConditionalFilterController
|
||||
before_filter :ensure_login, :only => :show
|
||||
end
|
||||
|
||||
|
@ -104,10 +104,10 @@ class FilterTest < Test::Unit::TestCase
|
|||
|
||||
class BeforeAndAfterConditionController < ConditionalFilterController
|
||||
before_filter :ensure_login, :only => :show
|
||||
after_filter :clean_up_tmp, :only => :show
|
||||
after_filter :clean_up_tmp, :only => :show
|
||||
end
|
||||
|
||||
class OnlyConditionProcController < ConditionalFilterController
|
||||
|
||||
class OnlyConditionProcController < ConditionalFilterController
|
||||
before_filter(:only => :show) {|c| c.assigns["ran_proc_filter"] = true }
|
||||
end
|
||||
|
||||
|
@ -131,6 +131,14 @@ class FilterTest < Test::Unit::TestCase
|
|||
before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.assigns["ran_proc_filter1"] = true }, :except => :show_without_filter) { |c| c.assigns["ran_proc_filter2"] = true}
|
||||
end
|
||||
|
||||
class EmptyFilterChainController < TestController
|
||||
self.filter_chain.clear
|
||||
def show
|
||||
@action_executed = true
|
||||
render :text => "yawp!"
|
||||
end
|
||||
end
|
||||
|
||||
class PrependingController < TestController
|
||||
prepend_before_filter :wonderful_life
|
||||
# skip_before_filter :fire_flash
|
||||
|
@ -145,7 +153,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
class ConditionalSkippingController < TestController
|
||||
skip_before_filter :ensure_login, :only => [ :login ]
|
||||
skip_after_filter :clean_up, :only => [ :login ]
|
||||
|
||||
|
||||
before_filter :find_user, :only => [ :change_password ]
|
||||
|
||||
def login
|
||||
|
@ -155,7 +163,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
def change_password
|
||||
render :inline => "ran action"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def find_user
|
||||
@ran_filter ||= []
|
||||
|
@ -166,15 +174,15 @@ class FilterTest < Test::Unit::TestCase
|
|||
class ConditionalParentOfConditionalSkippingController < ConditionalFilterController
|
||||
before_filter :conditional_in_parent, :only => [:show, :another_action]
|
||||
after_filter :conditional_in_parent, :only => [:show, :another_action]
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def conditional_in_parent
|
||||
@ran_filter ||= []
|
||||
@ran_filter << 'conditional_in_parent'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class ChildOfConditionalParentController < ConditionalParentOfConditionalSkippingController
|
||||
skip_before_filter :conditional_in_parent, :only => :another_action
|
||||
skip_after_filter :conditional_in_parent, :only => :another_action
|
||||
|
@ -197,7 +205,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
controller.assigns["was_audited"] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class AroundFilter
|
||||
def before(controller)
|
||||
@execution_log = "before"
|
||||
|
@ -209,7 +217,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
controller.assigns["execution_log"] = @execution_log + " and after"
|
||||
controller.assigns["after_ran"] = true
|
||||
controller.class.execution_log << " after aroundfilter " if controller.respond_to? :execution_log
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class AppendedAroundFilter
|
||||
|
@ -219,12 +227,12 @@ class FilterTest < Test::Unit::TestCase
|
|||
|
||||
def after(controller)
|
||||
controller.class.execution_log << " after appended aroundfilter "
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class AuditController < ActionController::Base
|
||||
before_filter(AuditFilter)
|
||||
|
||||
|
||||
def show
|
||||
render_text "hello"
|
||||
end
|
||||
|
@ -234,6 +242,14 @@ class FilterTest < Test::Unit::TestCase
|
|||
around_filter AroundFilter.new
|
||||
end
|
||||
|
||||
class BeforeAfterClassFilterController < PrependingController
|
||||
begin
|
||||
filter = AroundFilter.new
|
||||
before_filter filter
|
||||
after_filter filter
|
||||
end
|
||||
end
|
||||
|
||||
class MixedFilterController < PrependingController
|
||||
cattr_accessor :execution_log
|
||||
|
||||
|
@ -247,7 +263,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
after_filter { |c| c.class.execution_log << " after procfilter " }
|
||||
append_around_filter AppendedAroundFilter.new
|
||||
end
|
||||
|
||||
|
||||
class MixedSpecializationController < ActionController::Base
|
||||
class OutOfOrder < StandardError; end
|
||||
|
||||
|
@ -285,6 +301,101 @@ class FilterTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class PrependingBeforeAndAfterController < ActionController::Base
|
||||
prepend_before_filter :before_all
|
||||
prepend_after_filter :after_all
|
||||
before_filter :between_before_all_and_after_all
|
||||
|
||||
def before_all
|
||||
@ran_filter ||= []
|
||||
@ran_filter << 'before_all'
|
||||
end
|
||||
|
||||
def after_all
|
||||
@ran_filter ||= []
|
||||
@ran_filter << 'after_all'
|
||||
end
|
||||
|
||||
def between_before_all_and_after_all
|
||||
@ran_filter ||= []
|
||||
@ran_filter << 'between_before_all_and_after_all'
|
||||
end
|
||||
def show
|
||||
render :text => 'hello'
|
||||
end
|
||||
end
|
||||
|
||||
class NonYieldingAroundFilterController < ActionController::Base
|
||||
|
||||
before_filter :filter_one
|
||||
around_filter :non_yielding_filter
|
||||
before_filter :filter_two
|
||||
after_filter :filter_three
|
||||
|
||||
def index
|
||||
render :inline => "index"
|
||||
end
|
||||
|
||||
#make sure the controller complains
|
||||
def rescue_action(e); raise e; end
|
||||
|
||||
private
|
||||
|
||||
def filter_one
|
||||
@filters ||= []
|
||||
@filters << "filter_one"
|
||||
end
|
||||
|
||||
def filter_two
|
||||
@filters << "filter_two"
|
||||
end
|
||||
|
||||
def non_yielding_filter
|
||||
@filters << "zomg it didn't yield"
|
||||
@filter_return_value
|
||||
end
|
||||
|
||||
def filter_three
|
||||
@filters << "filter_three"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_non_yielding_around_filters_not_returning_false_do_not_raise
|
||||
controller = NonYieldingAroundFilterController.new
|
||||
controller.instance_variable_set "@filter_return_value", true
|
||||
assert_nothing_raised do
|
||||
test_process(controller, "index")
|
||||
end
|
||||
end
|
||||
|
||||
def test_non_yielding_around_filters_returning_false_do_not_raise
|
||||
controller = NonYieldingAroundFilterController.new
|
||||
controller.instance_variable_set "@filter_return_value", false
|
||||
assert_nothing_raised do
|
||||
test_process(controller, "index")
|
||||
end
|
||||
end
|
||||
|
||||
def test_after_filters_are_not_run_if_around_filter_returns_false
|
||||
controller = NonYieldingAroundFilterController.new
|
||||
controller.instance_variable_set "@filter_return_value", false
|
||||
test_process(controller, "index")
|
||||
assert_equal ["filter_one", "zomg it didn't yield"], controller.assigns['filters']
|
||||
end
|
||||
|
||||
def test_after_filters_are_not_run_if_around_filter_does_not_yield
|
||||
controller = NonYieldingAroundFilterController.new
|
||||
controller.instance_variable_set "@filter_return_value", true
|
||||
test_process(controller, "index")
|
||||
assert_equal ["filter_one", "zomg it didn't yield"], controller.assigns['filters']
|
||||
end
|
||||
|
||||
def test_empty_filter_chain
|
||||
assert_equal 0, EmptyFilterChainController.filter_chain.size
|
||||
assert test_process(EmptyFilterChainController).template.assigns['action_executed']
|
||||
end
|
||||
|
||||
def test_added_filter_to_inheritance_graph
|
||||
assert_equal [ :ensure_login ], TestController.before_filters
|
||||
end
|
||||
|
@ -292,11 +403,11 @@ class FilterTest < Test::Unit::TestCase
|
|||
def test_base_class_in_isolation
|
||||
assert_equal [ ], ActionController::Base.before_filters
|
||||
end
|
||||
|
||||
|
||||
def test_prepending_filter
|
||||
assert_equal [ :wonderful_life, :ensure_login ], PrependingController.before_filters
|
||||
end
|
||||
|
||||
|
||||
def test_running_filters
|
||||
assert_equal %w( wonderful_life ensure_login ), test_process(PrependingController).template.assigns["ran_filter"]
|
||||
end
|
||||
|
@ -304,11 +415,11 @@ class FilterTest < Test::Unit::TestCase
|
|||
def test_running_filters_with_proc
|
||||
assert test_process(ProcController).template.assigns["ran_proc_filter"]
|
||||
end
|
||||
|
||||
|
||||
def test_running_filters_with_implicit_proc
|
||||
assert test_process(ImplicitProcController).template.assigns["ran_proc_filter"]
|
||||
end
|
||||
|
||||
|
||||
def test_running_filters_with_class
|
||||
assert test_process(AuditController).template.assigns["was_audited"]
|
||||
end
|
||||
|
@ -319,7 +430,7 @@ class FilterTest < Test::Unit::TestCase
|
|||
assert response.template.assigns["ran_class_filter"]
|
||||
assert response.template.assigns["ran_proc_filter1"]
|
||||
assert response.template.assigns["ran_proc_filter2"]
|
||||
|
||||
|
||||
response = test_process(AnomolousYetValidConditionController, "show_without_filter")
|
||||
assert_equal nil, response.template.assigns["ran_filter"]
|
||||
assert !response.template.assigns["ran_class_filter"]
|
||||
|
@ -373,6 +484,12 @@ class FilterTest < Test::Unit::TestCase
|
|||
assert controller.template.assigns["after_ran"]
|
||||
end
|
||||
|
||||
def test_before_after_class_filter
|
||||
controller = test_process(BeforeAfterClassFilterController)
|
||||
assert controller.template.assigns["before_ran"]
|
||||
assert controller.template.assigns["after_ran"]
|
||||
end
|
||||
|
||||
def test_having_properties_in_around_filter
|
||||
controller = test_process(AroundFilterController)
|
||||
assert_equal "before and after", controller.template.assigns["execution_log"]
|
||||
|
@ -381,10 +498,10 @@ class FilterTest < Test::Unit::TestCase
|
|||
def test_prepending_and_appending_around_filter
|
||||
controller = test_process(MixedFilterController)
|
||||
assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
|
||||
" after appended aroundfilter after aroundfilter after procfilter ",
|
||||
" after appended aroundfilter after aroundfilter after procfilter ",
|
||||
MixedFilterController.execution_log
|
||||
end
|
||||
|
||||
|
||||
def test_rendering_breaks_filtering_chain
|
||||
response = test_process(RenderingController)
|
||||
assert_equal "something else", response.body
|
||||
|
@ -412,6 +529,12 @@ class FilterTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_running_prepended_before_and_after_filter
|
||||
assert_equal 3, PrependingBeforeAndAfterController.filter_chain.length
|
||||
response = test_process(PrependingBeforeAndAfterController)
|
||||
assert_equal %w( before_all between_before_all_and_after_all after_all ), response.template.assigns["ran_filter"]
|
||||
end
|
||||
|
||||
def test_conditional_skipping_of_filters
|
||||
assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"]
|
||||
assert_equal %w( ensure_login find_user ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"]
|
||||
|
|
|
@ -11,7 +11,7 @@ require 'stubba'
|
|||
module ActionController
|
||||
module Integration
|
||||
class Session
|
||||
def process
|
||||
def process(*args)
|
||||
end
|
||||
|
||||
def generic_url_rewriter
|
||||
|
@ -56,8 +56,7 @@ class SessionTest < Test::Unit::TestCase
|
|||
|
||||
@session.expects(:get).with(path,args)
|
||||
|
||||
redirects = [true, true, false]
|
||||
@session.stubs(:redirect?).returns(lambda { redirects.shift })
|
||||
@session.stubs(:redirect?).returns(true).then.returns(true).then.returns(false)
|
||||
@session.expects(:follow_redirect!).times(2)
|
||||
|
||||
@session.stubs(:status).returns(200)
|
||||
|
@ -69,8 +68,7 @@ class SessionTest < Test::Unit::TestCase
|
|||
|
||||
@session.expects(:post).with(path,args)
|
||||
|
||||
redirects = [true, true, false]
|
||||
@session.stubs(:redirect?).returns(lambda { redirects.shift })
|
||||
@session.stubs(:redirect?).returns(true).then.returns(true).then.returns(false)
|
||||
@session.expects(:follow_redirect!).times(2)
|
||||
|
||||
@session.stubs(:status).returns(200)
|
||||
|
@ -134,15 +132,102 @@ class SessionTest < Test::Unit::TestCase
|
|||
@session.head(path,params,headers)
|
||||
end
|
||||
|
||||
def test_xml_http_request
|
||||
def test_xml_http_request_deprecated_call
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:post).with(path,params,headers_after_xhr)
|
||||
@session.xml_http_request(path,params,headers)
|
||||
@session.expects(:process).with(:post,path,params,headers_after_xhr)
|
||||
assert_deprecated { @session.xml_http_request(path,params,headers) }
|
||||
end
|
||||
|
||||
def test_xml_http_request_get
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:process).with(:get,path,params,headers_after_xhr)
|
||||
@session.xml_http_request(:get,path,params,headers)
|
||||
end
|
||||
|
||||
def test_xml_http_request_post
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:process).with(:post,path,params,headers_after_xhr)
|
||||
@session.xml_http_request(:post,path,params,headers)
|
||||
end
|
||||
|
||||
def test_xml_http_request_put
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:process).with(:put,path,params,headers_after_xhr)
|
||||
@session.xml_http_request(:put,path,params,headers)
|
||||
end
|
||||
|
||||
def test_xml_http_request_delete
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:process).with(:delete,path,params,headers_after_xhr)
|
||||
@session.xml_http_request(:delete,path,params,headers)
|
||||
end
|
||||
|
||||
def test_xml_http_request_head
|
||||
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
||||
headers_after_xhr = headers.merge(
|
||||
"X-Requested-With" => "XMLHttpRequest",
|
||||
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
||||
)
|
||||
@session.expects(:process).with(:head,path,params,headers_after_xhr)
|
||||
@session.xml_http_request(:head,path,params,headers)
|
||||
end
|
||||
end
|
||||
|
||||
class IntegrationTestTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@test = ::ActionController::IntegrationTest.new(:default_test)
|
||||
@test.class.stubs(:fixture_table_names).returns([])
|
||||
@session = @test.open_session
|
||||
end
|
||||
|
||||
def test_opens_new_session
|
||||
@test.class.expects(:fixture_table_names).times(2).returns(['foo'])
|
||||
|
||||
session1 = @test.open_session { |sess| }
|
||||
session2 = @test.open_session # implicit session
|
||||
|
||||
assert_equal ::ActionController::Integration::Session, session1.class
|
||||
assert_equal ::ActionController::Integration::Session, session2.class
|
||||
assert_not_equal session1, session2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Tests that integration tests don't call Controller test methods for processing.
|
||||
# Integration tests have their own setup and teardown.
|
||||
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
||||
|
||||
def self.fixture_table_names
|
||||
[]
|
||||
end
|
||||
|
||||
def test_integration_methods_called
|
||||
%w( get post head put delete ).each do |verb|
|
||||
assert_nothing_raised("'#{verb}' should use integration test methods") { send(verb, '/') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# TODO
|
||||
|
|
|
@ -69,10 +69,6 @@ class TestController < ActionController::Base
|
|||
render "test/hello"
|
||||
end
|
||||
|
||||
def heading
|
||||
head :ok
|
||||
end
|
||||
|
||||
def greeting
|
||||
# let's just rely on the template
|
||||
end
|
||||
|
@ -290,50 +286,8 @@ class RenderTest < Test::Unit::TestCase
|
|||
assert_equal "Goodbye, Local David", @response.body
|
||||
end
|
||||
|
||||
def test_render_200_should_set_etag
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal etag_for("hello david"), @response.headers['Etag']
|
||||
end
|
||||
|
||||
def test_render_against_etag_request_should_304_when_match
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello david")
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "304 Not Modified", @response.headers['Status']
|
||||
assert @response.body.empty?
|
||||
end
|
||||
|
||||
def test_render_against_etag_request_should_200_when_no_match
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello somewhere else")
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "200 OK", @response.headers['Status']
|
||||
assert !@response.body.empty?
|
||||
end
|
||||
|
||||
def test_render_with_etag
|
||||
get :render_hello_world_from_variable
|
||||
expected_etag = "\"#{MD5.new("hello david").to_s}\""
|
||||
assert_equal expected_etag, @response.headers['Etag']
|
||||
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = expected_etag
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "304 Not Modified", @response.headers['Status']
|
||||
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\""
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "200 OK", @response.headers['Status']
|
||||
end
|
||||
|
||||
def render_with_404_shouldnt_have_etag
|
||||
get :render_custom_code
|
||||
assert_nil @response.headers['Etag']
|
||||
end
|
||||
|
||||
protected
|
||||
def assert_deprecated_render(&block)
|
||||
assert_deprecated(/render/, &block)
|
||||
end
|
||||
|
||||
def etag_for(text)
|
||||
"\"#{MD5.new(text).to_s}\""
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,8 +10,9 @@ class ThreadsController < ResourcesController; end
|
|||
class MessagesController < ResourcesController; end
|
||||
class CommentsController < ResourcesController; end
|
||||
|
||||
class AccountController < ResourcesController; end
|
||||
class AdminController < ResourcesController; end
|
||||
class AccountController < ResourcesController; end
|
||||
class AdminController < ResourcesController; end
|
||||
class ProductsController < ResourcesController; end
|
||||
|
||||
class ResourcesTest < Test::Unit::TestCase
|
||||
def test_should_arrange_actions
|
||||
|
@ -63,13 +64,13 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_multile_with_path_prefix
|
||||
def test_multiple_with_path_prefix
|
||||
with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do
|
||||
assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
|
||||
assert_simply_restful_for :comments, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_with_name_prefix
|
||||
with_restful_routing :messages, :name_prefix => 'post_' do
|
||||
assert_simply_restful_for :messages, :name_prefix => 'post_'
|
||||
|
@ -78,7 +79,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
|
||||
def test_with_collection_action
|
||||
rss_options = {:action => 'rss'}
|
||||
rss_path = "/messages;rss"
|
||||
rss_path = "/messages/rss"
|
||||
actions = { 'a' => :put, 'b' => :post, 'c' => :delete }
|
||||
|
||||
with_restful_routing :messages, :collection => { :rss => :get }.merge(actions) do
|
||||
|
@ -86,14 +87,14 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
assert_routing rss_path, options.merge(rss_options)
|
||||
|
||||
actions.each do |action, method|
|
||||
assert_recognizes(options.merge(:action => action), :path => "/messages;#{action}", :method => method)
|
||||
assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method)
|
||||
end
|
||||
end
|
||||
|
||||
assert_restful_named_routes_for :messages do |options|
|
||||
assert_named_route rss_path, :rss_messages_path, rss_options
|
||||
actions.keys.each do |action|
|
||||
assert_named_route "/messages;#{action}", "#{action}_messages_path", :action => action
|
||||
assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -103,7 +104,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
[:put, :post].each do |method|
|
||||
with_restful_routing :messages, :member => { :mark => method } do
|
||||
mark_options = {:action => 'mark', :id => '1'}
|
||||
mark_path = "/messages/1;mark"
|
||||
mark_path = "/messages/1/mark"
|
||||
assert_restful_routes_for :messages do |options|
|
||||
assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method)
|
||||
end
|
||||
|
@ -120,7 +121,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
with_restful_routing :messages, :member => { :mark => method, :unmark => method } do
|
||||
%w(mark unmark).each do |action|
|
||||
action_options = {:action => action, :id => '1'}
|
||||
action_path = "/messages/1;#{action}"
|
||||
action_path = "/messages/1/#{action}"
|
||||
assert_restful_routes_for :messages do |options|
|
||||
assert_recognizes(options.merge(action_options), :path => action_path, :method => method)
|
||||
end
|
||||
|
@ -136,7 +137,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
def test_with_new_action
|
||||
with_restful_routing :messages, :new => { :preview => :post } do
|
||||
preview_options = {:action => 'preview'}
|
||||
preview_path = "/messages/new;preview"
|
||||
preview_path = "/messages/new/preview"
|
||||
assert_restful_routes_for :messages do |options|
|
||||
assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post)
|
||||
end
|
||||
|
@ -178,9 +179,11 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
assert_simply_restful_for :threads
|
||||
assert_simply_restful_for :messages,
|
||||
:path_prefix => 'threads/1/',
|
||||
:name_prefix => 'thread_',
|
||||
:options => { :thread_id => '1' }
|
||||
assert_simply_restful_for :comments,
|
||||
:path_prefix => 'threads/1/messages/2/',
|
||||
:name_prefix => 'thread_message_',
|
||||
:options => { :thread_id => '1', :message_id => '2' }
|
||||
end
|
||||
end
|
||||
|
@ -217,9 +220,9 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
admin.resource :account
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
assert_singleton_restful_for :admin
|
||||
assert_singleton_restful_for :account, :path_prefix => 'admin/'
|
||||
assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -227,7 +230,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
[:put, :post].each do |method|
|
||||
with_singleton_resources :account, :member => { :reset => method } do
|
||||
reset_options = {:action => 'reset'}
|
||||
reset_path = "/account;reset"
|
||||
reset_path = "/account/reset"
|
||||
assert_singleton_routes_for :account do |options|
|
||||
assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method)
|
||||
end
|
||||
|
@ -244,7 +247,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
with_singleton_resources :account, :member => { :reset => method, :disable => method } do
|
||||
%w(reset disable).each do |action|
|
||||
action_options = {:action => action}
|
||||
action_path = "/account;#{action}"
|
||||
action_path = "/account/#{action}"
|
||||
assert_singleton_routes_for :account do |options|
|
||||
assert_recognizes(options.merge(action_options), :path => action_path, :method => method)
|
||||
end
|
||||
|
@ -264,9 +267,9 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
account.resources :messages
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
assert_singleton_restful_for :account
|
||||
assert_simply_restful_for :messages, :path_prefix => 'account/'
|
||||
assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -279,10 +282,10 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' }
|
||||
assert_simply_restful_for :messages, :path_prefix => '7/account/', :options => { :site_id => '7' }
|
||||
assert_simply_restful_for :messages, :path_prefix => '7/account/', :name_prefix => 'account_', :options => { :site_id => '7' }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_should_nest_singleton_resource_in_resources
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
|
@ -290,9 +293,9 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
thread.resource :admin
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
assert_simply_restful_for :threads
|
||||
assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :options => { :thread_id => '5' }
|
||||
assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -312,6 +315,181 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_resource_action_separator
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
|
||||
map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
|
||||
end
|
||||
|
||||
action_separator = ActionController::Base.resource_action_separator
|
||||
|
||||
assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
|
||||
assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {}
|
||||
assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}
|
||||
assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {}
|
||||
assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'
|
||||
assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {}
|
||||
assert_named_route "/admin/account/new", "new_admin_account_path", {}
|
||||
assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {}
|
||||
end
|
||||
end
|
||||
|
||||
def test_new_style_named_routes_for_resource
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
|
||||
end
|
||||
assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
|
||||
assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {}
|
||||
assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}
|
||||
assert_named_route "/threads/1/messages/new/preview", "preview_new_thread_message_path", {}
|
||||
end
|
||||
end
|
||||
|
||||
def test_new_style_named_routes_for_singleton_resource
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
|
||||
end
|
||||
assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'
|
||||
assert_named_route "/admin/account/login", "login_admin_account_path", {}
|
||||
assert_named_route "/admin/account/new", "new_admin_account_path", {}
|
||||
assert_named_route "/admin/account/new/preview", "preview_new_admin_account_path", {}
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_resource
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
|
||||
end
|
||||
assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
|
||||
assert_deprecated do
|
||||
assert_named_route "/threads/1/messages/search", "thread_search_messages_path", {}
|
||||
assert_named_route "/threads/1/messages/new", "thread_new_message_path", {}
|
||||
assert_named_route "/threads/1/messages/new/preview", "thread_preview_new_message_path", {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_singleton_resource
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
|
||||
end
|
||||
assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'
|
||||
assert_deprecated do
|
||||
assert_named_route "/admin/account/login", "admin_login_account_path", {}
|
||||
assert_named_route "/admin/account/new", "admin_new_account_path", {}
|
||||
assert_named_route "/admin/account/new/preview", "admin_preview_new_account_path", {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_nested_resources
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :threads do |map|
|
||||
map.resources :messages do |map|
|
||||
map.resources :comments
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert_simply_restful_for :threads
|
||||
assert_simply_restful_for :messages,
|
||||
:path_prefix => 'threads/1/',
|
||||
:name_prefix => 'thread_',
|
||||
:options => { :thread_id => '1' }
|
||||
assert_simply_restful_for :comments,
|
||||
:path_prefix => 'threads/1/messages/2/',
|
||||
:name_prefix => 'thread_message_',
|
||||
:options => { :thread_id => '1', :message_id => '2' }
|
||||
|
||||
assert_deprecated do
|
||||
assert_named_route "/threads/1/messages", "messages_path", {}
|
||||
assert_named_route "/threads/1/messages/1", "message_path", {:thread_id => '1', :id => '1'}
|
||||
assert_named_route "/threads/1/messages/new", "new_message_path", {:thread_id => '1'}
|
||||
assert_named_route "/threads/1/messages/1/edit", "edit_message_path", {:thread_id => '1', :id => '1'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_nested_singleton_resources
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resource :admin do |admin|
|
||||
admin.resource :account
|
||||
end
|
||||
end
|
||||
|
||||
assert_singleton_restful_for :admin
|
||||
assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_'
|
||||
|
||||
assert_deprecated do
|
||||
assert_named_route "/admin/account", "account_path", {}
|
||||
assert_named_route "/admin/account/new", "new_account_path", {}
|
||||
assert_named_route "/admin/account/edit", "edit_account_path", {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_nested_resources_in_singleton_resource
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resource :account do |account|
|
||||
account.resources :messages
|
||||
end
|
||||
end
|
||||
|
||||
assert_singleton_restful_for :account
|
||||
assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_'
|
||||
|
||||
assert_deprecated do
|
||||
assert_named_route "/account/messages", "messages_path", {}
|
||||
assert_named_route "/account/messages/1", "message_path", {:id => '1'}
|
||||
assert_named_route "/account/messages/new", "new_message_path", {}
|
||||
assert_named_route "/account/messages/1/edit", "edit_message_path", {:id => '1'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_named_routes_for_nested_singleton_resource_in_resources
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :threads do |thread|
|
||||
thread.resource :admin
|
||||
end
|
||||
end
|
||||
|
||||
assert_simply_restful_for :threads
|
||||
assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' }
|
||||
|
||||
assert_deprecated do
|
||||
assert_named_route "/threads/5/admin", "admin_path", {}
|
||||
assert_named_route "/threads/5/admin/new", "new_admin_path", {}
|
||||
assert_named_route "/threads/5/admin/edit", "edit_admin_path", {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_add_deprecated_formatted_routes
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources :products, :collection => { :specials => :get }, :member => { :thumbnail => :get }
|
||||
map.resource :account, :member => { :icon => :get }
|
||||
end
|
||||
assert_restful_routes_for :products do |options|
|
||||
assert_recognizes options.merge({ :action => 'specials', :format => 'xml' }), :path => '/products.xml;specials', :method => :get
|
||||
assert_recognizes options.merge({ :action => 'thumbnail', :format => 'jpg', :id => '1' }), :path => '/products/1.jpg;thumbnail', :method => :get
|
||||
end
|
||||
assert_singleton_restful_for :account do |options|
|
||||
assert_recognizes options.merge({ :action => 'icon', :format => 'jpg' }), :path => '/account.jpg;icon', :method => :get
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def with_restful_routing(*args)
|
||||
with_routing do |set|
|
||||
|
@ -319,7 +497,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
yield
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def with_singleton_resources(*args)
|
||||
with_routing do |set|
|
||||
set.draw { |map| map.resource(*args) }
|
||||
|
@ -344,8 +522,8 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
collection_path = "/#{options[:path_prefix]}#{controller_name}"
|
||||
member_path = "#{collection_path}/1"
|
||||
new_path = "#{collection_path}/new"
|
||||
edit_member_path = "#{member_path};edit"
|
||||
formatted_edit_member_path = "#{member_path}.xml;edit"
|
||||
edit_member_path = "#{member_path}/edit"
|
||||
formatted_edit_member_path = "#{member_path}/edit.xml"
|
||||
|
||||
with_options(options[:options]) do |controller|
|
||||
controller.assert_routing collection_path, :action => 'index'
|
||||
|
@ -395,13 +573,13 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
name_prefix = options[:name_prefix]
|
||||
|
||||
assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options]
|
||||
assert_named_route "#{full_prefix}/new", "#{name_prefix}new_#{singular_name}_path", options[:options]
|
||||
assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
|
||||
assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
||||
assert_named_route "#{full_prefix}/1;edit", "#{name_prefix}edit_#{singular_name}_path", options[:options].merge(:id => '1')
|
||||
assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
||||
assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml')
|
||||
assert_named_route "#{full_prefix}/new.xml", "formatted_#{name_prefix}new_#{singular_name}_path", options[:options].merge( :format => 'xml')
|
||||
assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
|
||||
assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
|
||||
assert_named_route "#{full_prefix}/1.xml;edit", "formatted_#{name_prefix}edit_#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
|
||||
assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
|
||||
yield options[:options] if block_given?
|
||||
end
|
||||
|
||||
|
@ -410,8 +588,8 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
|
||||
full_path = "/#{options[:path_prefix]}#{singleton_name}"
|
||||
new_path = "#{full_path}/new"
|
||||
edit_path = "#{full_path};edit"
|
||||
formatted_edit_path = "#{full_path}.xml;edit"
|
||||
edit_path = "#{full_path}/edit"
|
||||
formatted_edit_path = "#{full_path}/edit.xml"
|
||||
|
||||
with_options options[:options] do |controller|
|
||||
controller.assert_routing full_path, :action => 'show'
|
||||
|
@ -448,13 +626,14 @@ class ResourcesTest < Test::Unit::TestCase
|
|||
options[:options].delete :action
|
||||
|
||||
full_path = "/#{options[:path_prefix]}#{singleton_name}"
|
||||
full_name = "#{options[:name_prefix]}#{singleton_name}"
|
||||
|
||||
assert_named_route "#{full_path}", "#{singleton_name}_path", options[:options]
|
||||
assert_named_route "#{full_path}/new", "new_#{singleton_name}_path", options[:options]
|
||||
assert_named_route "#{full_path};edit", "edit_#{singleton_name}_path", options[:options]
|
||||
assert_named_route "#{full_path}.xml", "formatted_#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
||||
assert_named_route "#{full_path}/new.xml", "formatted_new_#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
||||
assert_named_route "#{full_path}.xml;edit", "formatted_edit_#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
||||
assert_named_route "#{full_path}", "#{full_name}_path", options[:options]
|
||||
assert_named_route "#{full_path}/new", "new_#{full_name}_path", options[:options]
|
||||
assert_named_route "#{full_path}/edit", "edit_#{full_name}_path", options[:options]
|
||||
assert_named_route "#{full_path}.xml", "formatted_#{full_name}_path", options[:options].merge(:format => 'xml')
|
||||
assert_named_route "#{full_path}/new.xml", "formatted_new_#{full_name}_path", options[:options].merge(:format => 'xml')
|
||||
assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml')
|
||||
end
|
||||
|
||||
def assert_named_route(expected, route, options)
|
||||
|
|
|
@ -265,7 +265,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
|||
map.content '/content/:query', :controller => 'content', :action => 'show'
|
||||
end
|
||||
exception = assert_raise(ActionController::RoutingError) { rs.generate(:controller => 'content', :action => 'show', :use_route => "content") }
|
||||
expected_message = %[content_url failed to generate from {:action=>"show", :controller=>"content"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["content", :query] - are they all satisifed?]
|
||||
expected_message = "content_url failed to generate from #{{:action=>"show", :controller=>"content"}.inspect} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: [\"content\", :query] - are they all satisifed?"
|
||||
assert_equal expected_message, exception.message
|
||||
end
|
||||
|
||||
|
@ -946,7 +946,7 @@ class RouteTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_expand_array_build_query_string
|
||||
assert_equal '?x[]=1&x[]=2', order_query_string(@route.build_query_string(:x => [1, 2]))
|
||||
assert_equal '?x%5B%5D=1&x%5B%5D=2', order_query_string(@route.build_query_string(:x => [1, 2]))
|
||||
end
|
||||
|
||||
def test_escape_spaces_build_query_string_selected_keys
|
||||
|
|
|
@ -482,6 +482,22 @@ HTML
|
|||
end
|
||||
end
|
||||
|
||||
def test_request_uri_updates
|
||||
get :test_params
|
||||
uri = @request.request_uri
|
||||
assert_equal @request.env['REQUEST_URI'], uri
|
||||
|
||||
get :test_uri
|
||||
assert_not_equal uri, @request.request_uri
|
||||
uri = @request.request_uri
|
||||
assert_equal @request.env['REQUEST_URI'], uri
|
||||
|
||||
get :test_uri, :testing => true
|
||||
assert_not_equal uri, @request.request_uri
|
||||
uri = @request.request_uri
|
||||
assert_equal @request.env['REQUEST_URI'], uri
|
||||
end
|
||||
|
||||
protected
|
||||
def with_foo_routing
|
||||
with_routing do |set|
|
||||
|
|
|
@ -17,15 +17,12 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|||
assert_match %r(/hi/hi/2$), u
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def split_query_string(str)
|
||||
[str[0].chr] + str[1..-1].split(/&/).sort
|
||||
end
|
||||
|
||||
def assert_query_equal(q1, q2)
|
||||
assert_equal(split_query_string(q1), split_query_string(q2))
|
||||
end
|
||||
def test_anchor
|
||||
assert_equal(
|
||||
'http://test.host/c/a/i#anchor',
|
||||
@rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class UrlWriterTests < Test::Unit::TestCase
|
||||
|
@ -75,6 +72,12 @@ class UrlWriterTests < Test::Unit::TestCase
|
|||
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
||||
)
|
||||
end
|
||||
|
||||
def test_anchor
|
||||
assert_equal('/c/a#anchor',
|
||||
W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor')
|
||||
)
|
||||
end
|
||||
|
||||
def test_named_route
|
||||
ActionController::Routing::Routes.draw do |map|
|
||||
|
@ -111,5 +114,58 @@ class UrlWriterTests < Test::Unit::TestCase
|
|||
ensure
|
||||
ActionController::Routing::Routes.load!
|
||||
end
|
||||
|
||||
|
||||
def test_one_parameter
|
||||
assert_equal('/c/a?param=val',
|
||||
W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :param => 'val')
|
||||
)
|
||||
end
|
||||
|
||||
def test_two_parameters
|
||||
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :p1 => 'X1', :p2 => 'Y2')
|
||||
params = extract_params(url)
|
||||
assert_equal params[0], { :p1 => 'X1' }.to_query
|
||||
assert_equal params[1], { :p2 => 'Y2' }.to_query
|
||||
end
|
||||
|
||||
def test_hash_parameter
|
||||
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:name => 'Bob', :category => 'prof'})
|
||||
params = extract_params(url)
|
||||
assert_equal params[0], { 'query[category]' => 'prof' }.to_query
|
||||
assert_equal params[1], { 'query[name]' => 'Bob' }.to_query
|
||||
end
|
||||
|
||||
def test_array_parameter
|
||||
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => ['Bob', 'prof'])
|
||||
params = extract_params(url)
|
||||
assert_equal params[0], { 'query[]' => 'Bob' }.to_query
|
||||
assert_equal params[1], { 'query[]' => 'prof' }.to_query
|
||||
end
|
||||
|
||||
def test_hash_recursive_parameters
|
||||
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:person => {:name => 'Bob', :position => 'prof'}, :hobby => 'piercing'})
|
||||
params = extract_params(url)
|
||||
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
|
||||
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
|
||||
assert_equal params[2], { 'query[person][position]' => 'prof' }.to_query
|
||||
end
|
||||
|
||||
def test_hash_recursive_and_array_parameters
|
||||
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
|
||||
assert_match %r(^/c/a/101), url
|
||||
params = extract_params(url)
|
||||
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
|
||||
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
|
||||
assert_equal params[2], { 'query[person][position][]' => 'art director' }.to_query
|
||||
assert_equal params[3], { 'query[person][position][]' => 'prof' }.to_query
|
||||
end
|
||||
|
||||
def test_path_generation_for_symbol_parameter_keys
|
||||
assert_generates("/image", :controller=> :image)
|
||||
end
|
||||
|
||||
private
|
||||
def extract_params(url)
|
||||
url.split('?', 2).last.split('&')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,9 +34,16 @@ class VerificationTest < Test::Unit::TestCase
|
|||
|
||||
verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
|
||||
|
||||
verify :only => :guarded_one_for_named_route_test, :params => "one",
|
||||
:redirect_to => :foo_url
|
||||
|
||||
def guarded_one
|
||||
render :text => "#{params[:one]}"
|
||||
end
|
||||
|
||||
def guarded_one_for_named_route_test
|
||||
render :text => "#{params[:one]}"
|
||||
end
|
||||
|
||||
def guarded_with_flash
|
||||
render :text => "#{params[:one]}"
|
||||
|
@ -94,6 +101,14 @@ class VerificationTest < Test::Unit::TestCase
|
|||
@controller = TestController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
ActionController::Routing::Routes.add_named_route :foo, '/foo', :controller => 'test', :action => 'foo'
|
||||
end
|
||||
|
||||
def test_no_deprecation_warning_for_named_route
|
||||
assert_not_deprecated do
|
||||
get :guarded_one_for_named_route_test, :two => "not one"
|
||||
assert_redirected_to '/foo'
|
||||
end
|
||||
end
|
||||
|
||||
def test_guarded_one_with_prereqs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue