diff options
author | Jamis Buck <jamis@37signals.com> | 2006-03-07 04:42:24 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-03-07 04:42:24 +0000 |
commit | 0fbe6837b1e7330f394e94a913fd58f0299a04b3 (patch) | |
tree | c6cb514dfc3cc8a70997033f2b7c3a6aeee01951 /actionpack/lib | |
parent | dc4b5cff39a532107354f55f292617ed7250cf6d (diff) | |
download | rails-0fbe6837b1e7330f394e94a913fd58f0299a04b3.tar.gz rails-0fbe6837b1e7330f394e94a913fd58f0299a04b3.tar.bz2 rails-0fbe6837b1e7330f394e94a913fd58f0299a04b3.zip |
more integration tweaks
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3807 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/integration_test.rb | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/integration_test.rb b/actionpack/lib/action_controller/integration_test.rb index 088992e13f..955b4a0f28 100644 --- a/actionpack/lib/action_controller/integration_test.rb +++ b/actionpack/lib/action_controller/integration_test.rb @@ -15,7 +15,6 @@ module ActionController 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 @@ module ActionController # # 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 @@ module ActionController # 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 @@ module ActionController @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 @@ module ActionController # 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 |