Instiki 0.16.3: Rails 2.3.0
Instiki now runs on the Rails 2.3.0 Candidate Release. Among other improvements, this means that it now automagically selects between WEBrick and Mongrel. Just run ./instiki --daemon
This commit is contained in:
parent
43aadecc99
commit
4e14ccc74d
893 changed files with 71965 additions and 28511 deletions
|
@ -1,9 +1,6 @@
|
|||
require 'active_support/test_case'
|
||||
require 'action_controller/dispatcher'
|
||||
require 'action_controller/test_process'
|
||||
|
||||
require 'stringio'
|
||||
require 'uri'
|
||||
require 'active_support/test_case'
|
||||
|
||||
module ActionController
|
||||
module Integration #:nodoc:
|
||||
|
@ -12,19 +9,26 @@ module ActionController
|
|||
# multiple sessions and run them side-by-side, you can also mimic (to some
|
||||
# limited extent) multiple simultaneous users interacting with your system.
|
||||
#
|
||||
# Typically, you will instantiate a new session using IntegrationTest#open_session,
|
||||
# rather than instantiating Integration::Session directly.
|
||||
# Typically, you will instantiate a new session using
|
||||
# IntegrationTest#open_session, rather than instantiating
|
||||
# Integration::Session directly.
|
||||
class Session
|
||||
include Test::Unit::Assertions
|
||||
include ActionController::Assertions
|
||||
include ActionController::TestCase::Assertions
|
||||
include ActionController::TestProcess
|
||||
|
||||
# Rack application to use
|
||||
attr_accessor :application
|
||||
|
||||
# The integer HTTP status code of the last request.
|
||||
attr_reader :status
|
||||
|
||||
# The status message that accompanied the status code of the last request.
|
||||
attr_reader :status_message
|
||||
|
||||
# The body of the last request.
|
||||
attr_reader :body
|
||||
|
||||
# The URI of the last request.
|
||||
attr_reader :path
|
||||
|
||||
|
@ -60,7 +64,8 @@ module ActionController
|
|||
end
|
||||
|
||||
# Create and initialize a new Session instance.
|
||||
def initialize
|
||||
def initialize(app = nil)
|
||||
@application = app || ActionController::Dispatcher.new
|
||||
reset!
|
||||
end
|
||||
|
||||
|
@ -79,11 +84,13 @@ module ActionController
|
|||
|
||||
self.host = "www.example.com"
|
||||
self.remote_addr = "127.0.0.1"
|
||||
self.accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
|
||||
self.accept = "text/xml,application/xml,application/xhtml+xml," +
|
||||
"text/html;q=0.9,text/plain;q=0.8,image/png," +
|
||||
"*/*;q=0.5"
|
||||
|
||||
unless defined? @named_routes_configured
|
||||
# install the named routes in this session instance.
|
||||
klass = class<<self; self; end
|
||||
klass = class << self; self; end
|
||||
Routing::Routes.install_helpers(klass)
|
||||
|
||||
# the helpers are made protected by default--we make them public for
|
||||
|
@ -97,7 +104,7 @@ module ActionController
|
|||
#
|
||||
# session.https!
|
||||
# session.https!(false)
|
||||
def https!(flag=true)
|
||||
def https!(flag = true)
|
||||
@https = flag
|
||||
end
|
||||
|
||||
|
@ -122,7 +129,7 @@ module ActionController
|
|||
# performed on the location header.
|
||||
def follow_redirect!
|
||||
raise "not a redirect! #{@status} #{@status_message}" unless redirect?
|
||||
get(interpret_uri(headers['location'].first))
|
||||
get(interpret_uri(headers['location']))
|
||||
status
|
||||
end
|
||||
|
||||
|
@ -167,17 +174,21 @@ module ActionController
|
|||
|
||||
# Performs a GET request with the given parameters.
|
||||
#
|
||||
# - +path+: The URI (as a String) on which you want to perform a GET request.
|
||||
# - +parameters+: The HTTP parameters that you want to pass. This may be +nil+,
|
||||
# - +path+: The URI (as a String) on which you want to perform a GET
|
||||
# request.
|
||||
# - +parameters+: The HTTP parameters that you want to pass. This may
|
||||
# be +nil+,
|
||||
# a Hash, or a String that is appropriately encoded
|
||||
# (<tt>application/x-www-form-urlencoded</tt> or <tt>multipart/form-data</tt>).
|
||||
# (<tt>application/x-www-form-urlencoded</tt> or
|
||||
# <tt>multipart/form-data</tt>).
|
||||
# - +headers+: Additional HTTP headers to pass, as a Hash. The keys will
|
||||
# automatically be upcased, with the prefix 'HTTP_' added if needed.
|
||||
#
|
||||
# This method returns an AbstractResponse object, which one can use to inspect
|
||||
# the details of the response. Furthermore, if this method was called from an
|
||||
# ActionController::IntegrationTest object, then that object's <tt>@response</tt>
|
||||
# instance variable will point to the same response object.
|
||||
# This method returns an Response object, which one can use to
|
||||
# inspect the details of the response. Furthermore, if this method was
|
||||
# called from an ActionController::IntegrationTest object, then that
|
||||
# object's <tt>@response</tt> instance variable will point to the same
|
||||
# response object.
|
||||
#
|
||||
# You can also perform POST, PUT, DELETE, and HEAD requests with +post+,
|
||||
# +put+, +delete+, and +head+.
|
||||
|
@ -185,22 +196,26 @@ module ActionController
|
|||
process :get, path, parameters, headers
|
||||
end
|
||||
|
||||
# Performs a POST request with the given parameters. See get() for more details.
|
||||
# Performs a POST request with the given parameters. See get() for more
|
||||
# details.
|
||||
def post(path, parameters = nil, headers = nil)
|
||||
process :post, path, parameters, headers
|
||||
end
|
||||
|
||||
# Performs a PUT request with the given parameters. See get() for more details.
|
||||
# Performs a PUT request with the given parameters. See get() for more
|
||||
# details.
|
||||
def put(path, parameters = nil, headers = nil)
|
||||
process :put, path, parameters, headers
|
||||
end
|
||||
|
||||
# Performs a DELETE request with the given parameters. See get() for more details.
|
||||
# Performs a DELETE request with the given parameters. See get() for
|
||||
# more details.
|
||||
def delete(path, parameters = nil, headers = nil)
|
||||
process :delete, path, parameters, headers
|
||||
end
|
||||
|
||||
# Performs a HEAD request with the given parameters. See get() for more details.
|
||||
# Performs a HEAD request with the given parameters. See get() for more
|
||||
# details.
|
||||
def head(path, parameters = nil, headers = nil)
|
||||
process :head, path, parameters, headers
|
||||
end
|
||||
|
@ -215,8 +230,7 @@ module ActionController
|
|||
def xml_http_request(request_method, path, parameters = nil, headers = nil)
|
||||
headers ||= {}
|
||||
headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
headers['Accept'] ||= 'text/javascript, text/html, application/xml, text/xml, */*'
|
||||
|
||||
headers['Accept'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
process(request_method, path, parameters, headers)
|
||||
end
|
||||
alias xhr :xml_http_request
|
||||
|
@ -224,7 +238,9 @@ module ActionController
|
|||
# Returns the URL for the given options, according to the rules specified
|
||||
# in the application's routes.
|
||||
def url_for(options)
|
||||
controller ? controller.url_for(options) : generic_url_rewriter.rewrite(options)
|
||||
controller ?
|
||||
controller.url_for(options) :
|
||||
generic_url_rewriter.rewrite(options)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -250,17 +266,35 @@ module ActionController
|
|||
data = nil
|
||||
end
|
||||
|
||||
env["QUERY_STRING"] ||= ""
|
||||
|
||||
data = data.is_a?(IO) ? data : StringIO.new(data || '')
|
||||
|
||||
env.update(
|
||||
"REQUEST_METHOD" => method.to_s.upcase,
|
||||
"REQUEST_METHOD" => method.to_s.upcase,
|
||||
"SERVER_NAME" => host,
|
||||
"SERVER_PORT" => (https? ? "443" : "80"),
|
||||
"HTTPS" => https? ? "on" : "off",
|
||||
"rack.url_scheme" => https? ? "https" : "http",
|
||||
"SCRIPT_NAME" => "",
|
||||
|
||||
"REQUEST_URI" => path,
|
||||
"PATH_INFO" => path,
|
||||
"HTTP_HOST" => host,
|
||||
"REMOTE_ADDR" => remote_addr,
|
||||
"SERVER_PORT" => (https? ? "443" : "80"),
|
||||
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
|
||||
"CONTENT_LENGTH" => data ? data.length.to_s : nil,
|
||||
"HTTP_COOKIE" => encode_cookies,
|
||||
"HTTPS" => https? ? "on" : "off",
|
||||
"HTTP_ACCEPT" => accept
|
||||
"HTTP_ACCEPT" => accept,
|
||||
|
||||
"rack.version" => [0,1],
|
||||
"rack.input" => data,
|
||||
"rack.errors" => StringIO.new,
|
||||
"rack.multithread" => true,
|
||||
"rack.multiprocess" => true,
|
||||
"rack.run_once" => false,
|
||||
|
||||
"rack.test" => true
|
||||
)
|
||||
|
||||
(headers || {}).each do |key, value|
|
||||
|
@ -269,54 +303,67 @@ module ActionController
|
|||
env[key] = value
|
||||
end
|
||||
|
||||
unless ActionController::Base.respond_to?(:clear_last_instantiation!)
|
||||
ActionController::Base.module_eval { include ControllerCapture }
|
||||
[ControllerCapture, ActionController::ProcessWithTest].each do |mod|
|
||||
unless ActionController::Base < mod
|
||||
ActionController::Base.class_eval { include mod }
|
||||
end
|
||||
end
|
||||
|
||||
ActionController::Base.clear_last_instantiation!
|
||||
|
||||
env['rack.input'] = data.is_a?(IO) ? data : StringIO.new(data || '')
|
||||
@status, @headers, result_body = ActionController::Dispatcher.new.mark_as_test_request!.call(env)
|
||||
app = @application
|
||||
# Rack::Lint doesn't accept String headers or bodies in Ruby 1.9
|
||||
unless RUBY_VERSION >= '1.9.0' && Rack.release <= '0.9.0'
|
||||
app = Rack::Lint.new(app)
|
||||
end
|
||||
|
||||
status, headers, body = app.call(env)
|
||||
@request_count += 1
|
||||
|
||||
@controller = ActionController::Base.last_instantiation
|
||||
@request = @controller.request
|
||||
@response = @controller.response
|
||||
|
||||
# Decorate the response with the standard behavior of the TestResponse
|
||||
# so that things like assert_response can be used in integration
|
||||
# tests.
|
||||
@response.extend(TestResponseBehavior)
|
||||
|
||||
@html_document = nil
|
||||
|
||||
# Inject status back in for backwords compatibility with CGI
|
||||
@headers['Status'] = @status
|
||||
@status = status.to_i
|
||||
@status_message = StatusCodes::STATUS_CODES[@status]
|
||||
|
||||
@status, @status_message = @status.split(/ /)
|
||||
@status = @status.to_i
|
||||
@headers = Rack::Utils::HeaderHash.new(headers)
|
||||
|
||||
cgi_headers = Hash.new { |h,k| h[k] = [] }
|
||||
@headers.each do |key, value|
|
||||
cgi_headers[key.downcase] << value
|
||||
end
|
||||
cgi_headers['set-cookie'] = cgi_headers['set-cookie'].first
|
||||
@headers = cgi_headers
|
||||
|
||||
@response.headers['cookie'] ||= []
|
||||
(@headers['set-cookie'] || []).each do |cookie|
|
||||
(@headers['Set-Cookie'] || []).each do |cookie|
|
||||
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
|
||||
@cookies[name] = value
|
||||
|
||||
# Fake CGI cookie header
|
||||
# DEPRECATE: Use response.headers["Set-Cookie"] instead
|
||||
@response.headers['cookie'] << CGI::Cookie::new("name" => name, "value" => value)
|
||||
end
|
||||
|
||||
return status
|
||||
@body = ""
|
||||
if body.is_a?(String)
|
||||
@body << body
|
||||
else
|
||||
body.each { |part| @body << part }
|
||||
end
|
||||
|
||||
if @controller = ActionController::Base.last_instantiation
|
||||
@request = @controller.request
|
||||
@response = @controller.response
|
||||
@controller.send(:set_test_assigns)
|
||||
else
|
||||
# Decorate responses from Rack Middleware and Rails Metal
|
||||
# as an Response for the purposes of integration testing
|
||||
@response = Response.new
|
||||
@response.status = status.to_s
|
||||
@response.headers.replace(@headers)
|
||||
@response.body = @body
|
||||
end
|
||||
|
||||
# Decorate the response with the standard behavior of the
|
||||
# TestResponse so that things like assert_response can be
|
||||
# used in integration tests.
|
||||
@response.extend(TestResponseBehavior)
|
||||
|
||||
return @status
|
||||
rescue MultiPartNeededException
|
||||
boundary = "----------XnJLe9ZIbbGUYtzPQJ16u1"
|
||||
status = process(method, path, multipart_body(parameters, boundary), (headers || {}).merge({"CONTENT_TYPE" => "multipart/form-data; boundary=#{boundary}"}))
|
||||
status = process(method, path,
|
||||
multipart_body(parameters, boundary),
|
||||
(headers || {}).merge(
|
||||
{"CONTENT_TYPE" => "multipart/form-data; boundary=#{boundary}"}))
|
||||
return status
|
||||
end
|
||||
|
||||
|
@ -338,7 +385,7 @@ module ActionController
|
|||
"SERVER_PORT" => https? ? "443" : "80",
|
||||
"HTTPS" => https? ? "on" : "off"
|
||||
}
|
||||
ActionController::UrlRewriter.new(ActionController::RackRequest.new(env), {})
|
||||
UrlRewriter.new(Request.new(env), {})
|
||||
end
|
||||
|
||||
def name_with_prefix(prefix, name)
|
||||
|
@ -352,9 +399,13 @@ module ActionController
|
|||
raise MultiPartNeededException
|
||||
elsif Hash === parameters
|
||||
return nil if parameters.empty?
|
||||
parameters.map { |k,v| requestify(v, name_with_prefix(prefix, k)) }.join("&")
|
||||
parameters.map { |k,v|
|
||||
requestify(v, name_with_prefix(prefix, k))
|
||||
}.join("&")
|
||||
elsif Array === parameters
|
||||
parameters.map { |v| requestify(v, name_with_prefix(prefix, "")) }.join("&")
|
||||
parameters.map { |v|
|
||||
requestify(v, name_with_prefix(prefix, ""))
|
||||
}.join("&")
|
||||
elsif prefix.nil?
|
||||
parameters
|
||||
else
|
||||
|
@ -380,7 +431,7 @@ module ActionController
|
|||
def multipart_body(params, boundary)
|
||||
multipart_requestify(params).map do |key, value|
|
||||
if value.respond_to?(:original_filename)
|
||||
File.open(value.path) do |f|
|
||||
File.open(value.path, "rb") do |f|
|
||||
f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding)
|
||||
|
||||
<<-EOF
|
||||
|
@ -460,8 +511,8 @@ EOF
|
|||
# By default, a single session is automatically created for you, but you
|
||||
# can use this method to open multiple sessions that ought to be tested
|
||||
# simultaneously.
|
||||
def open_session
|
||||
session = Integration::Session.new
|
||||
def open_session(application = nil)
|
||||
session = Integration::Session.new(application)
|
||||
|
||||
# delegate the fixture accessors back to the test instance
|
||||
extras = Module.new { attr_accessor :delegate, :test_result }
|
||||
|
@ -469,12 +520,16 @@ EOF
|
|||
self.class.fixture_table_names.each do |table_name|
|
||||
name = table_name.tr(".", "_")
|
||||
next unless respond_to?(name)
|
||||
extras.__send__(:define_method, name) { |*args| delegate.send(name, *args) }
|
||||
extras.__send__(:define_method, name) { |*args|
|
||||
delegate.send(name, *args)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# delegate add_assertion to the test case
|
||||
extras.__send__(:define_method, :add_assertion) { test_result.add_assertion }
|
||||
extras.__send__(:define_method, :add_assertion) {
|
||||
test_result.add_assertion
|
||||
}
|
||||
session.extend(extras)
|
||||
session.delegate = self
|
||||
session.test_result = @_result
|
||||
|
@ -602,7 +657,8 @@ EOF
|
|||
# would potentially have to set their values for both Test::Unit::TestCase
|
||||
# ActionController::IntegrationTest, since by the time the value is set on
|
||||
# TestCase, IntegrationTest has already been defined and cannot inherit
|
||||
# changes to those variables. So, we make those two attributes copy-on-write.
|
||||
# changes to those variables. So, we make those two attributes
|
||||
# copy-on-write.
|
||||
|
||||
class << self
|
||||
def use_transactional_fixtures=(flag) #:nodoc:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue