Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more integration tweaks

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3807 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 0fbe6837b1e7330f394e94a913fd58f0299a04b3 1 parent dc4b5cf
Jamis Buck jamis authored
Showing with 37 additions and 8 deletions.
  1. +37 −8 actionpack/lib/action_controller/integration_test.rb
45 actionpack/lib/action_controller/integration_test.rb
View
@@ -15,7 +15,6 @@ module Integration
class Session
include Test::Unit::Assertions
include ActionController::TestProcess
- include ActionController::Routing::NamedRoutes
# The integer HTTP status code of the last request.
attr_reader :status
@@ -56,13 +55,24 @@ def initialize
#
# session.reset!
def reset!
- @status = @path = @host = @headers = nil
+ @status = @path = @headers = nil
@result = @status_message = nil
@https = false
@cookies = {}
@controller = @request = @response = nil
- initialize_url_writer
+ host! "www.example.test"
+
+ unless @named_routes_configured
+ # install the named routes in this session instance.
+ klass = class<<self; self; end
+ Routing::NamedRoutes.install(klass)
+
+ # the helpers are made protected by default--we make them public for
+ # easier access during testing and troubleshooting.
+ klass.send(:public, *Routing::NamedRoutes::Helpers)
+ @named_routes_configured = true
+ end
end
# Specify whether or not the session should mimic a secure HTTPS request.
@@ -176,7 +186,7 @@ def initialize(env, input=nil)
# and the hostname.
def interpret_uri(path)
location = URI.parse(path)
- https! URI::HTTPS === location
+ https! URI::HTTPS === location if location.scheme
host! location.host if location.host
location.query ? "#{location.path}?#{location.query}" : location.path
end
@@ -269,14 +279,22 @@ def initialize_url_writer
@rewriter = ActionController::UrlRewriter.new(ActionController::CgiRequest.new(cgi), {})
end
+ def name_with_prefix(prefix, name)
+ prefix ? "#{prefix}[#{name}]" : name.to_s
+ end
+
# Convert the given parameters to a request string. The parameters may
# be a string, +nil+, or a Hash.
- def requestify(parameters)
+ def requestify(parameters, prefix=nil)
if Hash === parameters
- parameters.empty? ? nil :
- parameters.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
- else
+ return nil if parameters.empty?
+ 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("&")
+ elsif prefix.nil?
parameters
+ else
+ "#{CGI.escape(prefix)}=#{CGI.escape(parameters.to_s)}"
end
end
@@ -420,6 +438,17 @@ def reset!
# simultaneously.
def open_session
session = Integration::Session.new
+
+ # delegate the fixture accessors back to the test instance
+ klass = class<<session; self; end
+ tests = self
+
+ self.class.fixture_table_names.each do |table_name|
+ name = table_name.tr(".", "_")
+ next unless respond_to?(name)
+ klass.send(:define_method, name) { |*args| tests.send(name, *args) }
+ end
+
yield session if block_given?
session
end
Please sign in to comment.
Something went wrong with that request. Please try again.