Rails 2.3.3.1
Update to latest Rails. A little bit of jiggery-pokery is involved, since they neglected to re-include vendored Rack in this release.
This commit is contained in:
parent
329fafafce
commit
664552ac02
257 changed files with 4346 additions and 1682 deletions
|
@ -11,6 +11,9 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
|
||||
# a standard template
|
||||
def hello_xml_world() render :template => "test/hello_xml_world"; end
|
||||
|
||||
# a standard partial
|
||||
def partial() render :partial => 'test/partial'; end
|
||||
|
||||
# a redirect to an internal location
|
||||
def redirect_internal() redirect_to "/nothing"; end
|
||||
|
@ -332,6 +335,30 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
|
|||
assert @response.rendered[:template]
|
||||
assert 'hello_world', @response.rendered[:template].to_s
|
||||
end
|
||||
|
||||
def test_assert_template_with_partial
|
||||
get :partial
|
||||
assert_template :partial => '_partial'
|
||||
end
|
||||
|
||||
def test_assert_template_with_nil
|
||||
get :nothing
|
||||
assert_template nil
|
||||
end
|
||||
|
||||
def test_assert_template_with_string
|
||||
get :hello_world
|
||||
assert_template 'hello_world'
|
||||
end
|
||||
|
||||
def test_assert_template_with_symbol
|
||||
get :hello_world
|
||||
assert_template :hello_world
|
||||
end
|
||||
|
||||
def test_assert_template_with_bad_argument
|
||||
assert_raise(ArgumentError) { assert_template 1 }
|
||||
end
|
||||
|
||||
# check the redirection location
|
||||
def test_redirection_location
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'fileutils'
|
||||
require 'abstract_unit'
|
||||
require 'active_record_unit'
|
||||
|
||||
CACHE_DIR = 'test_cache'
|
||||
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
|
||||
|
@ -7,6 +8,10 @@ FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
|
|||
ActionController::Base.page_cache_directory = FILE_STORE_PATH
|
||||
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
|
||||
|
||||
# Force sweeper classes to load
|
||||
ActionController::Caching::Sweeper
|
||||
ActionController::Caching::Sweeping
|
||||
|
||||
class PageCachingTestController < ActionController::Base
|
||||
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
|
||||
caches_page :found, :not_found
|
||||
|
@ -152,6 +157,7 @@ class ActionCachingTestController < ActionController::Base
|
|||
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
|
||||
caches_action :with_layout
|
||||
caches_action :layout_false, :layout => false
|
||||
caches_action :record_not_found, :four_oh_four, :simple_runtime_error
|
||||
|
||||
layout 'talk_from_action.erb'
|
||||
|
||||
|
@ -174,6 +180,18 @@ class ActionCachingTestController < ActionController::Base
|
|||
render :text => @cache_this, :layout => true
|
||||
end
|
||||
|
||||
def record_not_found
|
||||
raise ActiveRecord::RecordNotFound, "oops!"
|
||||
end
|
||||
|
||||
def four_oh_four
|
||||
render :text => "404'd!", :status => 404
|
||||
end
|
||||
|
||||
def simple_runtime_error
|
||||
raise "oops!"
|
||||
end
|
||||
|
||||
alias_method :show, :index
|
||||
alias_method :edit, :index
|
||||
alias_method :destroy, :index
|
||||
|
@ -456,6 +474,27 @@ class ActionCacheTest < ActionController::TestCase
|
|||
assert_response :success
|
||||
end
|
||||
|
||||
def test_record_not_found_returns_404_for_multiple_requests
|
||||
get :record_not_found
|
||||
assert_response 404
|
||||
get :record_not_found
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_four_oh_four_returns_404_for_multiple_requests
|
||||
get :four_oh_four
|
||||
assert_response 404
|
||||
get :four_oh_four
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_simple_runtime_error_returns_500_for_multiple_requests
|
||||
get :simple_runtime_error
|
||||
assert_response 500
|
||||
get :simple_runtime_error
|
||||
assert_response 500
|
||||
end
|
||||
|
||||
private
|
||||
def content_to_cache
|
||||
assigns(:cache_this)
|
||||
|
|
|
@ -6,6 +6,10 @@ class CookieTest < ActionController::TestCase
|
|||
cookies["user_name"] = "david"
|
||||
end
|
||||
|
||||
def set_with_with_escapable_characters
|
||||
cookies["that & guy"] = "foo & bar => baz"
|
||||
end
|
||||
|
||||
def authenticate_for_fourteen_days
|
||||
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
|
||||
end
|
||||
|
@ -53,6 +57,12 @@ class CookieTest < ActionController::TestCase
|
|||
assert_equal({"user_name" => "david"}, @response.cookies)
|
||||
end
|
||||
|
||||
def test_setting_with_escapable_characters
|
||||
get :set_with_with_escapable_characters
|
||||
assert_equal ["that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"], @response.headers["Set-Cookie"]
|
||||
assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
|
||||
end
|
||||
|
||||
def test_setting_cookie_for_fourteen_days
|
||||
get :authenticate_for_fourteen_days
|
||||
assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
|
||||
|
|
|
@ -25,7 +25,8 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
|
||||
def test_clears_dependencies_after_dispatch_if_in_loading_mode
|
||||
ActiveSupport::Dependencies.expects(:clear).once
|
||||
dispatch(false)
|
||||
# Close the response so dependencies kicks in
|
||||
dispatch(false).last.close
|
||||
end
|
||||
|
||||
def test_reloads_routes_before_dispatch_if_in_loading_mode
|
||||
|
@ -49,13 +50,14 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
Dispatcher.any_instance.expects(:dispatch).raises('b00m')
|
||||
ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
|
||||
|
||||
response = nil
|
||||
assert_nothing_raised do
|
||||
assert_equal [
|
||||
500,
|
||||
{"Content-Type" => "text/html"},
|
||||
"<html><body><h1>500 Internal Server Error</h1></body></html>"
|
||||
], dispatch
|
||||
response = dispatch
|
||||
end
|
||||
assert_equal 3, response.size
|
||||
assert_equal 500, response[0]
|
||||
assert_equal({"Content-Type" => "text/html"}, response[1])
|
||||
assert_match /500 Internal Server Error/, response[2].join
|
||||
end
|
||||
|
||||
def test_prepare_callbacks
|
||||
|
@ -94,7 +96,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
def dispatch(cache_classes = true)
|
||||
ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
|
||||
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
||||
Dispatcher.new.call({})
|
||||
Dispatcher.new.call({'rack.input' => StringIO.new('')})
|
||||
end
|
||||
|
||||
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
||||
|
|
60
vendor/rails/actionpack/test/controller/failsafe_test.rb
vendored
Normal file
60
vendor/rails/actionpack/test/controller/failsafe_test.rb
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
require 'abstract_unit'
|
||||
require 'stringio'
|
||||
require 'logger'
|
||||
|
||||
class FailsafeTest < ActionController::TestCase
|
||||
FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures/failsafe".freeze
|
||||
|
||||
def setup
|
||||
@old_error_file_path = ActionController::Failsafe.error_file_path
|
||||
ActionController::Failsafe.error_file_path = FIXTURE_PUBLIC
|
||||
@app = mock
|
||||
@log_io = StringIO.new
|
||||
@logger = Logger.new(@log_io)
|
||||
@failsafe = ActionController::Failsafe.new(@app)
|
||||
@failsafe.stubs(:failsafe_logger).returns(@logger)
|
||||
end
|
||||
|
||||
def teardown
|
||||
ActionController::Failsafe.error_file_path = @old_error_file_path
|
||||
end
|
||||
|
||||
def app_will_raise_error!
|
||||
@app.expects(:call).then.raises(RuntimeError.new("Printer on fire"))
|
||||
end
|
||||
|
||||
def test_calls_app_and_returns_its_return_value
|
||||
@app.expects(:call).returns([200, { "Content-Type" => "text/html" }, "ok"])
|
||||
assert_equal [200, { "Content-Type" => "text/html" }, "ok"], @failsafe.call({})
|
||||
end
|
||||
|
||||
def test_writes_to_log_file_on_exception
|
||||
app_will_raise_error!
|
||||
@failsafe.call({})
|
||||
assert_match /Printer on fire/, @log_io.string # Logs exception message.
|
||||
assert_match /failsafe_test\.rb/, @log_io.string # Logs backtrace.
|
||||
end
|
||||
|
||||
def test_returns_500_internal_server_error_on_exception
|
||||
app_will_raise_error!
|
||||
response = @failsafe.call({})
|
||||
assert_equal 3, response.size # It is a valid Rack response.
|
||||
assert_equal 500, response[0] # Status is 500.
|
||||
end
|
||||
|
||||
def test_renders_error_page_file_with_erb
|
||||
app_will_raise_error!
|
||||
response = @failsafe.call({})
|
||||
assert_equal 500, response[0]
|
||||
assert_equal "hello my world", response[2].join
|
||||
end
|
||||
|
||||
def test_returns_a_default_message_if_erb_rendering_failed
|
||||
app_will_raise_error!
|
||||
@failsafe.expects(:render_template).raises(RuntimeError.new("Harddisk is crashing"))
|
||||
response = @failsafe.call({})
|
||||
assert_equal 500, response[0]
|
||||
assert_match /500 Internal Server Error/, response[2].join
|
||||
assert_match %r(please read this web application's log file), response[2].join
|
||||
end
|
||||
end
|
|
@ -23,7 +23,8 @@ class FilterParamTest < Test::Unit::TestCase
|
|||
[{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
|
||||
[{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
|
||||
[{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
|
||||
[{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana']]
|
||||
[{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'],
|
||||
[{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]]
|
||||
|
||||
test_hashes.each do |before_filter, after_filter, filter_words|
|
||||
FilterParamController.filter_parameter_logging(*filter_words)
|
||||
|
|
|
@ -121,7 +121,7 @@ class FlashTest < ActionController::TestCase
|
|||
assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
|
||||
assert_equal "hello again", @response.template.assigns["flash_copy"]["this"], "On second flash"
|
||||
end
|
||||
|
||||
|
||||
def test_flash_after_reset_session
|
||||
get :use_flash_after_reset_session
|
||||
assert_equal "hello", @response.template.assigns["flashy_that"]
|
||||
|
@ -139,4 +139,9 @@ class FlashTest < ActionController::TestCase
|
|||
get :std_action
|
||||
assert_nil @response.template.assigns["flash_copy"]["foo"]
|
||||
end
|
||||
|
||||
def test_does_not_set_the_session_if_the_flash_is_empty
|
||||
get :std_action
|
||||
assert_nil session["flash"]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,6 +67,15 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
|
|||
assert_equal 'SuperSecret', credentials[:realm]
|
||||
end
|
||||
|
||||
test "authentication request with nil credentials" do
|
||||
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => nil, :password => nil)
|
||||
get :index
|
||||
|
||||
assert_response :unauthorized
|
||||
assert_equal "HTTP Digest: Access denied.\n", @response.body, "Authentication didn't fail for request"
|
||||
assert_not_equal 'Hello Secret', @response.body, "Authentication didn't fail for request"
|
||||
end
|
||||
|
||||
test "authentication request with invalid password" do
|
||||
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo')
|
||||
get :display
|
||||
|
@ -151,6 +160,21 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
|
|||
assert_equal 'Definitely Maybe', @response.body
|
||||
end
|
||||
|
||||
test "authentication request with _method" do
|
||||
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :method => :post)
|
||||
@request.env['rack.methodoverride.original_method'] = 'POST'
|
||||
put :display
|
||||
|
||||
assert_response :success
|
||||
assert assigns(:logged_in)
|
||||
assert_equal 'Definitely Maybe', @response.body
|
||||
end
|
||||
|
||||
test "validate_digest_response should fail with nil returning password_procedure" do
|
||||
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => nil, :password => nil)
|
||||
assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret"){nil}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def encode_credentials(options)
|
||||
|
@ -161,15 +185,22 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
|
|||
# to prevent tampering of timestamp
|
||||
ActionController::Base.session_options[:secret] = "session_options_secret"
|
||||
|
||||
# Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
|
||||
get :index
|
||||
# Perform unauthenticated request to retrieve digest parameters to use on subsequent request
|
||||
method = options.delete(:method) || 'GET'
|
||||
|
||||
case method.to_s.upcase
|
||||
when 'GET'
|
||||
get :index
|
||||
when 'POST'
|
||||
post :index
|
||||
end
|
||||
|
||||
assert_response :unauthorized
|
||||
|
||||
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
|
||||
credentials.merge!(options)
|
||||
credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
|
||||
ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
|
||||
ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1])
|
||||
end
|
||||
|
||||
def decode_credentials(header)
|
||||
|
|
|
@ -240,6 +240,14 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
render :text => "foo: #{params[:foo]}", :status => 200
|
||||
end
|
||||
|
||||
def post_with_multiparameter_params
|
||||
render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}", :status => 200
|
||||
end
|
||||
|
||||
def multipart_post_with_multiparameter_params
|
||||
render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}, filesize: #{params[:file].size}", :status => 200
|
||||
end
|
||||
|
||||
def post
|
||||
render :text => "Created", :status => 201
|
||||
end
|
||||
|
@ -255,6 +263,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
|
||||
|
||||
def test_get
|
||||
with_test_route_set do
|
||||
get '/get'
|
||||
|
@ -360,6 +370,24 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_post_with_multiparameter_attribute_parameters
|
||||
with_test_route_set do
|
||||
post '/post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz"
|
||||
|
||||
assert_equal 200, status
|
||||
assert_equal "foo(1i): bar, foo(2i): baz", response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_multipart_post_with_multiparameter_attribute_parameters
|
||||
with_test_route_set do
|
||||
post '/multipart_post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz", :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
|
||||
|
||||
assert_equal 200, status
|
||||
assert_equal "foo(1i): bar, foo(2i): baz, filesize: 159528", response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_head
|
||||
with_test_route_set do
|
||||
head '/get'
|
||||
|
|
|
@ -235,7 +235,10 @@ class RedirectTest < ActionController::TestCase
|
|||
|
||||
def test_redirect_with_partial_params
|
||||
get :module_redirect
|
||||
assert_redirected_to :action => 'hello_world'
|
||||
|
||||
assert_deprecated do
|
||||
assert_redirected_to :action => 'hello_world'
|
||||
end
|
||||
end
|
||||
|
||||
def test_redirect_to_nil
|
||||
|
|
97
vendor/rails/actionpack/test/controller/reloader_test.rb
vendored
Normal file
97
vendor/rails/actionpack/test/controller/reloader_test.rb
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
class ReloaderTests < ActiveSupport::TestCase
|
||||
Reloader = ActionController::Reloader
|
||||
Dispatcher = ActionController::Dispatcher
|
||||
|
||||
class MyBody < Array
|
||||
def initialize(&block)
|
||||
@on_close = block
|
||||
end
|
||||
|
||||
def foo
|
||||
"foo"
|
||||
end
|
||||
|
||||
def bar
|
||||
"bar"
|
||||
end
|
||||
|
||||
def close
|
||||
@on_close.call if @on_close
|
||||
end
|
||||
end
|
||||
|
||||
def setup_and_return_body(app = lambda { })
|
||||
Dispatcher.expects(:reload_application)
|
||||
reloader = Reloader.new(app)
|
||||
headers, status, body = reloader.call({ })
|
||||
body
|
||||
end
|
||||
|
||||
def test_it_reloads_the_application_before_the_request
|
||||
Dispatcher.expects(:reload_application)
|
||||
reloader = Reloader.new(lambda {
|
||||
[200, { "Content-Type" => "text/html" }, [""]]
|
||||
})
|
||||
reloader.call({ })
|
||||
end
|
||||
|
||||
def test_returned_body_object_always_responds_to_close
|
||||
body = setup_and_return_body(lambda {
|
||||
[200, { "Content-Type" => "text/html" }, [""]]
|
||||
})
|
||||
assert body.respond_to?(:close)
|
||||
end
|
||||
|
||||
def test_returned_body_object_behaves_like_underlying_object
|
||||
body = setup_and_return_body(lambda {
|
||||
b = MyBody.new
|
||||
b << "hello"
|
||||
b << "world"
|
||||
[200, { "Content-Type" => "text/html" }, b]
|
||||
})
|
||||
assert_equal 2, body.size
|
||||
assert_equal "hello", body[0]
|
||||
assert_equal "world", body[1]
|
||||
assert_equal "foo", body.foo
|
||||
assert_equal "bar", body.bar
|
||||
end
|
||||
|
||||
def test_it_calls_close_on_underlying_object_when_close_is_called_on_body
|
||||
close_called = false
|
||||
body = setup_and_return_body(lambda {
|
||||
b = MyBody.new do
|
||||
close_called = true
|
||||
end
|
||||
[200, { "Content-Type" => "text/html" }, b]
|
||||
})
|
||||
body.close
|
||||
assert close_called
|
||||
end
|
||||
|
||||
def test_returned_body_object_responds_to_all_methods_supported_by_underlying_object
|
||||
body = setup_and_return_body(lambda {
|
||||
[200, { "Content-Type" => "text/html" }, MyBody.new]
|
||||
})
|
||||
assert body.respond_to?(:size)
|
||||
assert body.respond_to?(:each)
|
||||
assert body.respond_to?(:foo)
|
||||
assert body.respond_to?(:bar)
|
||||
end
|
||||
|
||||
def test_it_doesnt_clean_up_the_application_after_call
|
||||
Dispatcher.expects(:cleanup_application).never
|
||||
body = setup_and_return_body(lambda {
|
||||
[200, { "Content-Type" => "text/html" }, MyBody.new]
|
||||
})
|
||||
end
|
||||
|
||||
def test_it_cleans_up_the_application_when_close_is_called_on_body
|
||||
Dispatcher.expects(:cleanup_application)
|
||||
body = setup_and_return_body(lambda {
|
||||
[200, { "Content-Type" => "text/html" }, MyBody.new]
|
||||
})
|
||||
body.close
|
||||
end
|
||||
end
|
|
@ -193,20 +193,24 @@ class TestController < ActionController::Base
|
|||
render :inline => "<%= controller_name %>"
|
||||
end
|
||||
|
||||
def render_json_nil
|
||||
render :json => nil
|
||||
end
|
||||
|
||||
def render_json_hello_world
|
||||
render :json => {:hello => 'world'}.to_json
|
||||
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
||||
end
|
||||
|
||||
def render_json_hello_world_with_callback
|
||||
render :json => {:hello => 'world'}.to_json, :callback => 'alert'
|
||||
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
|
||||
end
|
||||
|
||||
def render_json_with_custom_content_type
|
||||
render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript'
|
||||
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
|
||||
end
|
||||
|
||||
def render_symbol_json
|
||||
render :json => {:hello => 'world'}.to_json
|
||||
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
||||
end
|
||||
|
||||
def render_json_with_render_to_string
|
||||
|
@ -886,33 +890,39 @@ class RenderTest < ActionController::TestCase
|
|||
assert_equal "The secret is in the sauce\n", @response.body
|
||||
end
|
||||
|
||||
def test_render_json_nil
|
||||
get :render_json_nil
|
||||
assert_equal 'null', @response.body
|
||||
assert_equal 'application/json', @response.content_type
|
||||
end
|
||||
|
||||
def test_render_json
|
||||
get :render_json_hello_world
|
||||
assert_equal '{"hello": "world"}', @response.body
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
assert_equal 'application/json', @response.content_type
|
||||
end
|
||||
|
||||
def test_render_json_with_callback
|
||||
get :render_json_hello_world_with_callback
|
||||
assert_equal 'alert({"hello": "world"})', @response.body
|
||||
assert_equal 'alert({"hello":"world"})', @response.body
|
||||
assert_equal 'application/json', @response.content_type
|
||||
end
|
||||
|
||||
def test_render_json_with_custom_content_type
|
||||
get :render_json_with_custom_content_type
|
||||
assert_equal '{"hello": "world"}', @response.body
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
assert_equal 'text/javascript', @response.content_type
|
||||
end
|
||||
|
||||
def test_render_symbol_json
|
||||
get :render_symbol_json
|
||||
assert_equal '{"hello": "world"}', @response.body
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
assert_equal 'application/json', @response.content_type
|
||||
end
|
||||
|
||||
def test_render_json_with_render_to_string
|
||||
get :render_json_with_render_to_string
|
||||
assert_equal '{"hello": "partial html"}', @response.body
|
||||
assert_equal '{"hello":"partial html"}', @response.body
|
||||
assert_equal 'application/json', @response.content_type
|
||||
end
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
|
|||
|
||||
# Ruby CGI doesn't handle multipart/mixed for us.
|
||||
files = params['files']
|
||||
assert_kind_of String, files
|
||||
assert_kind_of Tempfile, files
|
||||
files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding)
|
||||
assert_equal 19756, files.size
|
||||
end
|
||||
|
@ -133,46 +133,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
# The lint wrapper is used in integration tests
|
||||
# instead of a normal StringIO class
|
||||
InputWrapper = Rack::Lint::InputWrapper
|
||||
|
||||
test "parses unwindable stream" do
|
||||
InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
|
||||
params = parse_multipart('large_text_file')
|
||||
assert_equal %w(file foo), params.keys.sort
|
||||
assert_equal 'bar', params['foo']
|
||||
end
|
||||
|
||||
test "uploads and reads file with unwindable input" do
|
||||
InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
|
||||
|
||||
with_test_routing do
|
||||
post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
|
||||
assert_equal "File: Hello", response.body
|
||||
end
|
||||
end
|
||||
|
||||
test "passes through rack middleware and uploads file" do
|
||||
with_muck_middleware do
|
||||
with_test_routing do
|
||||
post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
|
||||
assert_equal "File: Hello", response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "passes through rack middleware and uploads file with unwindable input" do
|
||||
InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
|
||||
|
||||
with_muck_middleware do
|
||||
with_test_routing do
|
||||
post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
|
||||
assert_equal "File: Hello", response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def fixture(name)
|
||||
File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
|
||||
|
@ -199,25 +159,4 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
|
|||
yield
|
||||
end
|
||||
end
|
||||
|
||||
class MuckMiddleware
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
req = Rack::Request.new(env)
|
||||
req.params # Parse params
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
def with_muck_middleware
|
||||
original_middleware = ActionController::Dispatcher.middleware
|
||||
middleware = original_middleware.dup
|
||||
middleware.insert_after ActionController::RewindableInput, MuckMiddleware
|
||||
ActionController::Dispatcher.middleware = middleware
|
||||
yield
|
||||
ActionController::Dispatcher.middleware = original_middleware
|
||||
end
|
||||
end
|
||||
|
|
35
vendor/rails/actionpack/test/controller/request/test_request_test.rb
vendored
Normal file
35
vendor/rails/actionpack/test/controller/request/test_request_test.rb
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'abstract_unit'
|
||||
require 'stringio'
|
||||
|
||||
class ActionController::TestRequestTest < ActiveSupport::TestCase
|
||||
|
||||
def setup
|
||||
@request = ActionController::TestRequest.new
|
||||
end
|
||||
|
||||
def test_test_request_has_session_options_initialized
|
||||
assert @request.session_options
|
||||
end
|
||||
|
||||
Rack::Session::Abstract::ID::DEFAULT_OPTIONS.each_key do |option|
|
||||
test "test_rack_default_session_options_#{option}_exists_in_session_options_and_is_default" do
|
||||
assert_equal(Rack::Session::Abstract::ID::DEFAULT_OPTIONS[option],
|
||||
@request.session_options[option],
|
||||
"Missing rack session default option #{option} in request.session_options")
|
||||
end
|
||||
test "test_rack_default_session_options_#{option}_exists_in_session_options" do
|
||||
assert(@request.session_options.has_key?(option),
|
||||
"Missing rack session option #{option} in request.session_options")
|
||||
end
|
||||
end
|
||||
|
||||
def test_session_id_exists_by_default
|
||||
assert_not_nil(@request.session_options[:id])
|
||||
end
|
||||
|
||||
def test_session_id_different_on_each_call
|
||||
prev_id =
|
||||
assert_not_equal(@request.session_options[:id], ActionController::TestRequest.new.session_options[:id])
|
||||
end
|
||||
|
||||
end
|
|
@ -126,45 +126,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
|
|||
assert_parses expected, query
|
||||
end
|
||||
|
||||
test "passes through rack middleware and parses params" do
|
||||
with_muck_middleware do
|
||||
assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
|
||||
end
|
||||
end
|
||||
|
||||
# The lint wrapper is used in integration tests
|
||||
# instead of a normal StringIO class
|
||||
InputWrapper = Rack::Lint::InputWrapper
|
||||
|
||||
test "passes through rack middleware and parses params with unwindable input" do
|
||||
InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
|
||||
with_muck_middleware do
|
||||
assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
class MuckMiddleware
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
req = Rack::Request.new(env)
|
||||
req.params # Parse params
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
def with_muck_middleware
|
||||
original_middleware = ActionController::Dispatcher.middleware
|
||||
middleware = original_middleware.dup
|
||||
middleware.insert_after ActionController::RewindableInput, MuckMiddleware
|
||||
ActionController::Dispatcher.middleware = middleware
|
||||
yield
|
||||
ActionController::Dispatcher.middleware = original_middleware
|
||||
end
|
||||
|
||||
def with_test_routing
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
|
|
|
@ -3,7 +3,6 @@ require 'abstract_unit'
|
|||
class RequestTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
ActionController::Base.relative_url_root = nil
|
||||
@request = ActionController::TestRequest.new
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -11,60 +10,52 @@ class RequestTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_remote_ip
|
||||
assert_equal '0.0.0.0', @request.remote_ip
|
||||
request = stub_request 'REMOTE_ADDR' => '1.2.3.4'
|
||||
assert_equal '1.2.3.4', request.remote_ip
|
||||
|
||||
@request.remote_addr = '1.2.3.4'
|
||||
assert_equal '1.2.3.4', @request.remote_ip
|
||||
request = stub_request 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6'
|
||||
assert_equal '1.2.3.4', request.remote_ip
|
||||
|
||||
@request.remote_addr = '1.2.3.4,3.4.5.6'
|
||||
assert_equal '1.2.3.4', @request.remote_ip
|
||||
request = stub_request 'REMOTE_ADDR' => '1.2.3.4',
|
||||
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
|
||||
assert_equal '1.2.3.4', request.remote_ip
|
||||
|
||||
@request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
|
||||
assert_equal '1.2.3.4', @request.remote_ip
|
||||
request = stub_request 'REMOTE_ADDR' => '127.0.0.1',
|
||||
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.remote_addr = '192.168.0.1'
|
||||
assert_equal '2.3.4.5', @request.remote_ip
|
||||
@request.env.delete 'HTTP_CLIENT_IP'
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.remote_addr = '1.2.3.4'
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
|
||||
assert_equal '1.2.3.4', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '172.16.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.remote_addr = '127.0.0.1'
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '192.168.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '172.16.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1, 10.0.0.1, 3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '192.168.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '127.0.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,192.168.0.1'
|
||||
assert_equal 'unknown', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.1, 3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
|
||||
assert_equal '3.4.5.6', request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,3.4.5.6'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
|
||||
assert_equal 'unknown', @request.remote_ip
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
|
||||
assert_equal '3.4.5.6', @request.remote_ip
|
||||
|
||||
@request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
|
||||
'HTTP_CLIENT_IP' => '2.2.2.2'
|
||||
e = assert_raise(ActionController::ActionControllerError) {
|
||||
@request.remote_ip
|
||||
request.remote_ip
|
||||
}
|
||||
assert_match /IP spoofing attack/, e.message
|
||||
assert_match /HTTP_X_FORWARDED_FOR="9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4"/, e.message
|
||||
assert_match /HTTP_CLIENT_IP="8.8.8.8"/, e.message
|
||||
assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message
|
||||
assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message
|
||||
|
||||
# turn IP Spoofing detection off.
|
||||
# This is useful for sites that are aimed at non-IP clients. The typical
|
||||
|
@ -72,336 +63,333 @@ class RequestTest < ActiveSupport::TestCase
|
|||
# leap of faith to assume that their proxies are ever going to set the
|
||||
# HTTP_CLIENT_IP/HTTP_X_FORWARDED_FOR headers properly.
|
||||
ActionController::Base.ip_spoofing_check = false
|
||||
assert_equal('8.8.8.8', @request.remote_ip)
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
|
||||
'HTTP_CLIENT_IP' => '2.2.2.2'
|
||||
assert_equal '2.2.2.2', request.remote_ip
|
||||
ActionController::Base.ip_spoofing_check = true
|
||||
|
||||
@request.env['HTTP_X_FORWARDED_FOR'] = '8.8.8.8, 9.9.9.9'
|
||||
assert_equal '8.8.8.8', @request.remote_ip
|
||||
|
||||
@request.env.delete 'HTTP_CLIENT_IP'
|
||||
@request.env.delete 'HTTP_X_FORWARDED_FOR'
|
||||
request = stub_request 'HTTP_X_FORWARDED_FOR' => '8.8.8.8, 9.9.9.9'
|
||||
assert_equal '9.9.9.9', request.remote_ip
|
||||
end
|
||||
|
||||
def test_domains
|
||||
@request.host = "www.rubyonrails.org"
|
||||
assert_equal "rubyonrails.org", @request.domain
|
||||
request = stub_request 'HTTP_HOST' => 'www.rubyonrails.org'
|
||||
assert_equal "rubyonrails.org", request.domain
|
||||
|
||||
@request.host = "www.rubyonrails.co.uk"
|
||||
assert_equal "rubyonrails.co.uk", @request.domain(2)
|
||||
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
|
||||
assert_equal "rubyonrails.co.uk", request.domain(2)
|
||||
|
||||
@request.host = "192.168.1.200"
|
||||
assert_nil @request.domain
|
||||
request = stub_request 'HTTP_HOST' => "192.168.1.200"
|
||||
assert_nil request.domain
|
||||
|
||||
@request.host = "foo.192.168.1.200"
|
||||
assert_nil @request.domain
|
||||
request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
|
||||
assert_nil request.domain
|
||||
|
||||
@request.host = "192.168.1.200.com"
|
||||
assert_equal "200.com", @request.domain
|
||||
|
||||
@request.host = nil
|
||||
assert_nil @request.domain
|
||||
request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
|
||||
assert_equal "200.com", request.domain
|
||||
end
|
||||
|
||||
def test_subdomains
|
||||
@request.host = "www.rubyonrails.org"
|
||||
assert_equal %w( www ), @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => "www.rubyonrails.org"
|
||||
assert_equal %w( www ), request.subdomains
|
||||
|
||||
@request.host = "www.rubyonrails.co.uk"
|
||||
assert_equal %w( www ), @request.subdomains(2)
|
||||
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
|
||||
assert_equal %w( www ), request.subdomains(2)
|
||||
|
||||
@request.host = "dev.www.rubyonrails.co.uk"
|
||||
assert_equal %w( dev www ), @request.subdomains(2)
|
||||
request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk"
|
||||
assert_equal %w( dev www ), request.subdomains(2)
|
||||
|
||||
@request.host = "foobar.foobar.com"
|
||||
assert_equal %w( foobar ), @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => "foobar.foobar.com"
|
||||
assert_equal %w( foobar ), request.subdomains
|
||||
|
||||
@request.host = "192.168.1.200"
|
||||
assert_equal [], @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => "192.168.1.200"
|
||||
assert_equal [], request.subdomains
|
||||
|
||||
@request.host = "foo.192.168.1.200"
|
||||
assert_equal [], @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
|
||||
assert_equal [], request.subdomains
|
||||
|
||||
@request.host = "192.168.1.200.com"
|
||||
assert_equal %w( 192 168 1 ), @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
|
||||
assert_equal %w( 192 168 1 ), request.subdomains
|
||||
|
||||
@request.host = nil
|
||||
assert_equal [], @request.subdomains
|
||||
request = stub_request 'HTTP_HOST' => nil
|
||||
assert_equal [], request.subdomains
|
||||
end
|
||||
|
||||
def test_port_string
|
||||
@request.port = 80
|
||||
assert_equal "", @request.port_string
|
||||
request = stub_request 'HTTP_HOST' => 'www.example.org:80'
|
||||
assert_equal "", request.port_string
|
||||
|
||||
@request.port = 8080
|
||||
assert_equal ":8080", @request.port_string
|
||||
request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
|
||||
assert_equal ":8080", request.port_string
|
||||
end
|
||||
|
||||
def test_request_uri
|
||||
@request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432'
|
||||
request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
|
||||
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
||||
assert_equal "/path/of/some/uri", request.path
|
||||
|
||||
@request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
|
||||
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
||||
assert_equal "/path/of/some/uri", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri"
|
||||
assert_equal "/path/of/some/uri", request.request_uri
|
||||
assert_equal "/path/of/some/uri", request.path
|
||||
|
||||
@request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri"
|
||||
assert_equal "/path/of/some/uri", @request.request_uri
|
||||
assert_equal "/path/of/some/uri", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/path/of/some/uri"
|
||||
assert_equal "/path/of/some/uri", request.request_uri
|
||||
assert_equal "/path/of/some/uri", request.path
|
||||
|
||||
@request.set_REQUEST_URI "/path/of/some/uri"
|
||||
assert_equal "/path/of/some/uri", @request.request_uri
|
||||
assert_equal "/path/of/some/uri", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/"
|
||||
assert_equal "/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
@request.set_REQUEST_URI "/"
|
||||
assert_equal "/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/?m=b"
|
||||
assert_equal "/?m=b", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
@request.set_REQUEST_URI "/?m=b"
|
||||
assert_equal "/?m=b", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
|
||||
@request.set_REQUEST_URI "/"
|
||||
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
||||
assert_equal "/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/", 'SCRIPT_NAME' => '/dispatch.cgi'
|
||||
assert_equal "/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
ActionController::Base.relative_url_root = "/hieraki"
|
||||
@request.set_REQUEST_URI "/hieraki/"
|
||||
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
|
||||
assert_equal "/hieraki/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/hieraki/", 'SCRIPT_NAME' => "/hieraki/dispatch.cgi"
|
||||
assert_equal "/hieraki/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
ActionController::Base.relative_url_root = "/collaboration/hieraki"
|
||||
@request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
|
||||
@request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
|
||||
assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
|
||||
assert_equal "/books/edit/2", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/collaboration/hieraki/books/edit/2",
|
||||
'SCRIPT_NAME' => "/collaboration/hieraki/dispatch.cgi"
|
||||
assert_equal "/collaboration/hieraki/books/edit/2", request.request_uri
|
||||
assert_equal "/books/edit/2", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
# The following tests are for when REQUEST_URI is not supplied (as in IIS)
|
||||
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
|
||||
@request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
||||
assert_equal "/path/of/some/uri", @request.path
|
||||
request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
|
||||
'SCRIPT_NAME' => nil,
|
||||
'REQUEST_URI' => nil
|
||||
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
||||
assert_equal "/path/of/some/uri", request.path
|
||||
|
||||
ActionController::Base.relative_url_root = '/path'
|
||||
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
|
||||
@request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
||||
assert_equal "/of/some/uri", @request.path
|
||||
request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
|
||||
'SCRIPT_NAME' => "/path/dispatch.rb",
|
||||
'REQUEST_URI' => nil
|
||||
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
||||
assert_equal "/of/some/uri", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
@request.env['PATH_INFO'] = "/path/of/some/uri"
|
||||
@request.env['SCRIPT_NAME'] = nil
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/path/of/some/uri", @request.request_uri
|
||||
assert_equal "/path/of/some/uri", @request.path
|
||||
request = stub_request 'PATH_INFO' => "/path/of/some/uri",
|
||||
'SCRIPT_NAME' => nil,
|
||||
'REQUEST_URI' => nil
|
||||
assert_equal "/path/of/some/uri", request.request_uri
|
||||
assert_equal "/path/of/some/uri", request.path
|
||||
|
||||
@request.env['PATH_INFO'] = "/"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'PATH_INFO' => '/', 'REQUEST_URI' => nil
|
||||
assert_equal "/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
@request.env['PATH_INFO'] = "/?m=b"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/?m=b", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'PATH_INFO' => '/?m=b', 'REQUEST_URI' => nil
|
||||
assert_equal "/?m=b", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
@request.env['PATH_INFO'] = "/"
|
||||
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'PATH_INFO' => "/",
|
||||
'SCRIPT_NAME' => "/dispatch.cgi",
|
||||
'REQUEST_URI' => nil
|
||||
assert_equal "/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
|
||||
ActionController::Base.relative_url_root = '/hieraki'
|
||||
@request.env['PATH_INFO'] = "/hieraki/"
|
||||
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
|
||||
@request.set_REQUEST_URI nil
|
||||
assert_equal "/hieraki/", @request.request_uri
|
||||
assert_equal "/", @request.path
|
||||
request = stub_request 'PATH_INFO' => "/hieraki/",
|
||||
'SCRIPT_NAME' => "/hieraki/dispatch.cgi",
|
||||
'REQUEST_URI' => nil
|
||||
assert_equal "/hieraki/", request.request_uri
|
||||
assert_equal "/", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
||||
request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
|
||||
ActionController::Base.relative_url_root = '/hieraki'
|
||||
assert_equal "/dispatch.cgi", @request.path
|
||||
assert_equal "/dispatch.cgi", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
||||
request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
|
||||
ActionController::Base.relative_url_root = '/foo'
|
||||
assert_equal "/hieraki/dispatch.cgi", @request.path
|
||||
assert_equal "/hieraki/dispatch.cgi", request.path
|
||||
ActionController::Base.relative_url_root = nil
|
||||
|
||||
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
|
||||
ActionController::Base.relative_url_root = nil
|
||||
@request.env['REQUEST_URI'] = "/some/path"
|
||||
@request.env['PATH_INFO'] = "/another/path"
|
||||
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
||||
assert_equal "/some/path", @request.request_uri
|
||||
assert_equal "/some/path", @request.path
|
||||
request = stub_request 'REQUEST_URI' => "/some/path",
|
||||
'PATH_INFO' => "/another/path",
|
||||
'SCRIPT_NAME' => "/dispatch.cgi"
|
||||
assert_equal "/some/path", request.request_uri
|
||||
assert_equal "/some/path", request.path
|
||||
end
|
||||
|
||||
def test_host_with_default_port
|
||||
@request.host = "rubyonrails.org"
|
||||
@request.port = 80
|
||||
assert_equal "rubyonrails.org", @request.host_with_port
|
||||
request = stub_request 'HTTP_HOST' => 'rubyonrails.org:80'
|
||||
assert_equal "rubyonrails.org", request.host_with_port
|
||||
end
|
||||
|
||||
def test_host_with_non_default_port
|
||||
@request.host = "rubyonrails.org"
|
||||
@request.port = 81
|
||||
assert_equal "rubyonrails.org:81", @request.host_with_port
|
||||
request = stub_request 'HTTP_HOST' => 'rubyonrails.org:81'
|
||||
assert_equal "rubyonrails.org:81", request.host_with_port
|
||||
end
|
||||
|
||||
def test_server_software
|
||||
assert_equal nil, @request.server_software
|
||||
request = stub_request
|
||||
assert_equal nil, request.server_software
|
||||
|
||||
@request.env['SERVER_SOFTWARE'] = 'Apache3.422'
|
||||
assert_equal 'apache', @request.server_software
|
||||
request = stub_request 'SERVER_SOFTWARE' => 'Apache3.422'
|
||||
assert_equal 'apache', request.server_software
|
||||
|
||||
@request.env['SERVER_SOFTWARE'] = 'lighttpd(1.1.4)'
|
||||
assert_equal 'lighttpd', @request.server_software
|
||||
request = stub_request 'SERVER_SOFTWARE' => 'lighttpd(1.1.4)'
|
||||
assert_equal 'lighttpd', request.server_software
|
||||
end
|
||||
|
||||
def test_xml_http_request
|
||||
assert !@request.xml_http_request?
|
||||
assert !@request.xhr?
|
||||
request = stub_request
|
||||
|
||||
@request.env['HTTP_X_REQUESTED_WITH'] = "DefinitelyNotAjax1.0"
|
||||
assert !@request.xml_http_request?
|
||||
assert !@request.xhr?
|
||||
assert !request.xml_http_request?
|
||||
assert !request.xhr?
|
||||
|
||||
@request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"
|
||||
assert @request.xml_http_request?
|
||||
assert @request.xhr?
|
||||
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'DefinitelyNotAjax1.0'
|
||||
assert !request.xml_http_request?
|
||||
assert !request.xhr?
|
||||
|
||||
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
||||
assert request.xml_http_request?
|
||||
assert request.xhr?
|
||||
end
|
||||
|
||||
def test_reports_ssl
|
||||
assert !@request.ssl?
|
||||
@request.env['HTTPS'] = 'on'
|
||||
assert @request.ssl?
|
||||
request = stub_request
|
||||
assert !request.ssl?
|
||||
|
||||
request = stub_request 'HTTPS' => 'on'
|
||||
assert request.ssl?
|
||||
end
|
||||
|
||||
def test_reports_ssl_when_proxied_via_lighttpd
|
||||
assert !@request.ssl?
|
||||
@request.env['HTTP_X_FORWARDED_PROTO'] = 'https'
|
||||
assert @request.ssl?
|
||||
request = stub_request
|
||||
assert !request.ssl?
|
||||
|
||||
request = stub_request 'HTTP_X_FORWARDED_PROTO' => 'https'
|
||||
assert request.ssl?
|
||||
end
|
||||
|
||||
def test_symbolized_request_methods
|
||||
[:get, :post, :put, :delete].each do |method|
|
||||
self.request_method = method
|
||||
assert_equal method, @request.method
|
||||
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
|
||||
assert_equal method, request.method
|
||||
end
|
||||
end
|
||||
|
||||
def test_invalid_http_method_raises_exception
|
||||
assert_raise(ActionController::UnknownHttpMethod) do
|
||||
self.request_method = :random_method
|
||||
@request.request_method
|
||||
request = stub_request 'REQUEST_METHOD' => 'RANDOM_METHOD'
|
||||
request.request_method
|
||||
end
|
||||
end
|
||||
|
||||
def test_allow_method_hacking_on_post
|
||||
[:get, :head, :options, :put, :post, :delete].each do |method|
|
||||
self.request_method = method
|
||||
assert_equal(method == :head ? :get : method, @request.method)
|
||||
end
|
||||
end
|
||||
|
||||
def test_invalid_method_hacking_on_post_raises_exception
|
||||
assert_raise(ActionController::UnknownHttpMethod) do
|
||||
self.request_method = :_random_method
|
||||
@request.request_method
|
||||
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
|
||||
assert_equal(method == :head ? :get : method, request.method)
|
||||
end
|
||||
end
|
||||
|
||||
def test_restrict_method_hacking
|
||||
@request.instance_eval { @parameters = { :_method => 'put' } }
|
||||
[:get, :put, :delete].each do |method|
|
||||
self.request_method = method
|
||||
assert_equal method, @request.method
|
||||
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase,
|
||||
'action_controller.request.request_parameters' => { :_method => 'put' }
|
||||
assert_equal method, request.method
|
||||
end
|
||||
end
|
||||
|
||||
def test_head_masquerading_as_get
|
||||
self.request_method = :head
|
||||
assert_equal :get, @request.method
|
||||
assert @request.get?
|
||||
assert @request.head?
|
||||
request = stub_request 'REQUEST_METHOD' => 'HEAD'
|
||||
assert_equal :get, request.method
|
||||
assert request.get?
|
||||
assert request.head?
|
||||
end
|
||||
|
||||
def test_xml_format
|
||||
@request.instance_eval { @parameters = { :format => 'xml' } }
|
||||
assert_equal Mime::XML, @request.format
|
||||
request = stub_request
|
||||
request.expects(:parameters).at_least_once.returns({ :format => 'xml' })
|
||||
assert_equal Mime::XML, request.format
|
||||
end
|
||||
|
||||
def test_xhtml_format
|
||||
@request.instance_eval { @parameters = { :format => 'xhtml' } }
|
||||
assert_equal Mime::HTML, @request.format
|
||||
request = stub_request
|
||||
request.expects(:parameters).at_least_once.returns({ :format => 'xhtml' })
|
||||
assert_equal Mime::HTML, request.format
|
||||
end
|
||||
|
||||
def test_txt_format
|
||||
@request.instance_eval { @parameters = { :format => 'txt' } }
|
||||
assert_equal Mime::TEXT, @request.format
|
||||
request = stub_request
|
||||
request.expects(:parameters).at_least_once.returns({ :format => 'txt' })
|
||||
assert_equal Mime::TEXT, request.format
|
||||
end
|
||||
|
||||
def test_nil_format
|
||||
def test_xml_http_request
|
||||
ActionController::Base.use_accept_header, old =
|
||||
false, ActionController::Base.use_accept_header
|
||||
|
||||
@request.instance_eval { @parameters = {} }
|
||||
@request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
|
||||
assert @request.xhr?
|
||||
assert_equal Mime::JS, @request.format
|
||||
|
||||
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
||||
request.expects(:parameters).at_least_once.returns({})
|
||||
assert request.xhr?
|
||||
assert_equal Mime::JS, request.format
|
||||
ensure
|
||||
ActionController::Base.use_accept_header = old
|
||||
end
|
||||
|
||||
def test_content_type
|
||||
@request.env["CONTENT_TYPE"] = "text/html"
|
||||
assert_equal Mime::HTML, @request.content_type
|
||||
request = stub_request 'CONTENT_TYPE' => 'text/html'
|
||||
assert_equal Mime::HTML, request.content_type
|
||||
end
|
||||
|
||||
def test_format_assignment_should_set_format
|
||||
@request.instance_eval { self.format = :txt }
|
||||
assert !@request.format.xml?
|
||||
@request.instance_eval { self.format = :xml }
|
||||
assert @request.format.xml?
|
||||
def test_can_override_format_with_parameter
|
||||
request = stub_request
|
||||
request.expects(:parameters).at_least_once.returns({ :format => :txt })
|
||||
assert !request.format.xml?
|
||||
|
||||
request = stub_request
|
||||
request.expects(:parameters).at_least_once.returns({ :format => :xml })
|
||||
assert request.format.xml?
|
||||
end
|
||||
|
||||
def test_content_no_type
|
||||
assert_equal nil, @request.content_type
|
||||
request = stub_request
|
||||
assert_equal nil, request.content_type
|
||||
end
|
||||
|
||||
def test_content_type_xml
|
||||
@request.env["CONTENT_TYPE"] = "application/xml"
|
||||
assert_equal Mime::XML, @request.content_type
|
||||
request = stub_request 'CONTENT_TYPE' => 'application/xml'
|
||||
assert_equal Mime::XML, request.content_type
|
||||
end
|
||||
|
||||
def test_content_type_with_charset
|
||||
@request.env["CONTENT_TYPE"] = "application/xml; charset=UTF-8"
|
||||
assert_equal Mime::XML, @request.content_type
|
||||
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
|
||||
assert_equal Mime::XML, request.content_type
|
||||
end
|
||||
|
||||
def test_user_agent
|
||||
assert_not_nil @request.user_agent
|
||||
request = stub_request 'HTTP_USER_AGENT' => 'TestAgent'
|
||||
assert_equal 'TestAgent', request.user_agent
|
||||
end
|
||||
|
||||
def test_parameters
|
||||
@request.stubs(:request_parameters).returns({ "foo" => 1 })
|
||||
@request.stubs(:query_parameters).returns({ "bar" => 2 })
|
||||
request = stub_request
|
||||
request.stubs(:request_parameters).returns({ "foo" => 1 })
|
||||
request.stubs(:query_parameters).returns({ "bar" => 2 })
|
||||
|
||||
assert_equal({"foo" => 1, "bar" => 2}, @request.parameters)
|
||||
assert_equal({"foo" => 1}, @request.request_parameters)
|
||||
assert_equal({"bar" => 2}, @request.query_parameters)
|
||||
assert_equal({"foo" => 1, "bar" => 2}, request.parameters)
|
||||
assert_equal({"foo" => 1}, request.request_parameters)
|
||||
assert_equal({"bar" => 2}, request.query_parameters)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def stub_request(env={})
|
||||
ActionController::Request.new(env)
|
||||
end
|
||||
|
||||
protected
|
||||
def request_method=(method)
|
||||
@request.env['REQUEST_METHOD'] = method.to_s.upcase
|
||||
@request.request_method = nil # Reset the ivar cache
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,6 +120,14 @@ class ResourcesTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_irregular_id_requirements_should_get_passed_to_member_actions
|
||||
expected_options = {:controller => 'messages', :action => 'custom', :id => '1.1.1'}
|
||||
|
||||
with_restful_routing(:messages, :member => {:custom => :get}, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do
|
||||
assert_recognizes(expected_options, :path => 'messages/1.1.1/custom', :method => :get)
|
||||
end
|
||||
end
|
||||
|
||||
def test_with_path_prefix
|
||||
with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do
|
||||
assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
|
||||
|
|
|
@ -1662,6 +1662,17 @@ class RouteSetTest < Test::Unit::TestCase
|
|||
assert_equal 1, set.routes.size
|
||||
end
|
||||
|
||||
def test_draw_symbol_controller_name
|
||||
assert_equal 0, set.routes.size
|
||||
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) }
|
||||
assert_equal 1, set.routes.size
|
||||
end
|
||||
|
||||
def test_named_draw
|
||||
assert_equal 0, set.routes.size
|
||||
set.draw do |map|
|
||||
|
@ -2476,6 +2487,16 @@ class RouteSetTest < Test::Unit::TestCase
|
|||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => 'JAMIS'}, set.recognize_path('/page/JAMIS'))
|
||||
end
|
||||
|
||||
def test_routes_with_symbols
|
||||
set.draw do |map|
|
||||
map.connect 'unnamed', :controller => :pages, :action => :show, :name => :as_symbol
|
||||
map.named 'named', :controller => :pages, :action => :show, :name => :as_symbol
|
||||
end
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/unnamed'))
|
||||
assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/named'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class RouteLoadingTest < Test::Unit::TestCase
|
||||
|
|
|
@ -108,7 +108,7 @@ class SendFileTest < ActionController::TestCase
|
|||
@controller.send(:send_file_headers!, options)
|
||||
|
||||
h = @controller.headers
|
||||
assert_equal 1, h['Content-Length']
|
||||
assert_equal '1', h['Content-Length']
|
||||
assert_equal 'image/png', h['Content-Type']
|
||||
assert_equal 'disposition; filename="filename"', h['Content-Disposition']
|
||||
assert_equal 'binary', h['Content-Transfer-Encoding']
|
||||
|
|
|
@ -193,27 +193,6 @@ class CookieStoreTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_session_store_with_expire_after
|
||||
app = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
|
||||
@integration_session = open_session(app)
|
||||
|
||||
with_test_route_set do
|
||||
# First request accesses the session
|
||||
cookies[SessionKey] = SignedBar
|
||||
|
||||
get '/set_session_value'
|
||||
assert_response :success
|
||||
cookie = headers['Set-Cookie']
|
||||
|
||||
# Second request does not access the session so the
|
||||
# expires header should not be changed
|
||||
get '/no_session_access'
|
||||
assert_response :success
|
||||
assert_equal cookie, headers['Set-Cookie'],
|
||||
"#{unmarshal_session(cookie).inspect} expected but was #{unmarshal_session(headers['Set-Cookie']).inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
|
|
|
@ -515,6 +515,14 @@ XML
|
|||
assert_nil @request.instance_variable_get("@request_method")
|
||||
end
|
||||
|
||||
def test_params_reset_after_post_request
|
||||
post :no_op, :foo => "bar"
|
||||
assert_equal "bar", @request.params[:foo]
|
||||
@request.recycle!
|
||||
post :no_op
|
||||
assert @request.params[:foo].blank?
|
||||
end
|
||||
|
||||
%w(controller response request).each do |variable|
|
||||
%w(get post put delete head process).each do |method|
|
||||
define_method("test_#{variable}_missing_for_#{method}_raises_error") do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue