aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/testing/process.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-12 18:09:44 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-12 18:09:44 -0600
commitee395fe626760e897abd9e881b54d3cc3f407d31 (patch)
tree9d79bb4defa4c8a13009deb856e00c5125e63710 /actionpack/lib/action_controller/testing/process.rb
parent96deabace71d5cb3ee12c7b99e459db5e2acb1a6 (diff)
downloadrails-ee395fe626760e897abd9e881b54d3cc3f407d31.tar.gz
rails-ee395fe626760e897abd9e881b54d3cc3f407d31.tar.bz2
rails-ee395fe626760e897abd9e881b54d3cc3f407d31.zip
TestProcess belongs in AD
Diffstat (limited to 'actionpack/lib/action_controller/testing/process.rb')
-rw-r--r--actionpack/lib/action_controller/testing/process.rb111
1 files changed, 0 insertions, 111 deletions
diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb
deleted file mode 100644
index 323cce6a2f..0000000000
--- a/actionpack/lib/action_controller/testing/process.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require 'active_support/core_ext/object/conversions'
-require "rack/test"
-
-module ActionController #:nodoc:
- # Essentially generates a modified Tempfile object similar to the object
- # you'd get from the standard library CGI module in a multipart
- # request. This means you can use an ActionController::TestUploadedFile
- # object in the params of a test request in order to simulate
- # a file upload.
- #
- # Usage example, within a functional test:
- # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + '/files/spongebob.png', 'image/png')
- #
- # Pass a true third parameter to ensure the uploaded file is opened in binary mode (only required for Windows):
- # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + '/files/spongebob.png', 'image/png', :binary)
- TestUploadedFile = Rack::Test::UploadedFile
-
- module TestProcess
- def assigns(key = nil)
- assigns = {}
- @controller.instance_variable_names.each do |ivar|
- next if ActionController::Base.protected_instance_variables.include?(ivar)
- assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
- end
-
- key.nil? ? assigns : assigns[key.to_s]
- end
-
- def session
- @request.session
- end
-
- def flash
- @request.flash
- end
-
- def cookies
- @request.cookies.merge(@response.cookies)
- end
-
- def redirect_to_url
- @response.redirect_url
- end
-
- def html_document
- xml = @response.content_type =~ /xml$/
- @html_document ||= HTML::Document.new(@response.body, false, xml)
- end
-
- def find_tag(conditions)
- html_document.find(conditions)
- end
-
- def find_all_tag(conditions)
- html_document.find_all(conditions)
- end
-
- def method_missing(selector, *args, &block)
- if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector)
- @controller.send(selector, *args, &block)
- else
- super
- end
- end
-
- # Shortcut for <tt>ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + path, type)</tt>:
- #
- # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png')
- #
- # To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
- # This will not affect other platforms:
- #
- # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png', :binary)
- def fixture_file_upload(path, mime_type = nil, binary = false)
- fixture_path = ActionController::TestCase.send(:fixture_path) if ActionController::TestCase.respond_to?(:fixture_path)
- ActionController::TestUploadedFile.new("#{fixture_path}#{path}", mime_type, binary)
- end
-
- # A helper to make it easier to test different route configurations.
- # This method temporarily replaces ActionController::Routing::Routes
- # with a new RouteSet instance.
- #
- # The new instance is yielded to the passed block. Typically the block
- # will create some routes using <tt>map.draw { map.connect ... }</tt>:
- #
- # with_routing do |set|
- # set.draw do |map|
- # map.connect ':controller/:action/:id'
- # assert_equal(
- # ['/content/10/show', {}],
- # map.generate(:controller => 'content', :id => 10, :action => 'show')
- # end
- # end
- # end
- #
- def with_routing
- real_routes = ActionController::Routing::Routes
- ActionController::Routing.module_eval { remove_const :Routes }
-
- temporary_routes = ActionController::Routing::RouteSet.new
- ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
-
- yield temporary_routes
- ensure
- if ActionController::Routing.const_defined? :Routes
- ActionController::Routing.module_eval { remove_const :Routes }
- end
- ActionController::Routing.const_set(:Routes, real_routes) if real_routes
- end
- end
-end