2011-06-04 04:35:48 -04:00
|
|
|
require 'action_dispatch/middleware/cookies'
|
2010-02-16 16:54:56 -05:00
|
|
|
require 'action_dispatch/middleware/flash'
|
2010-04-21 00:58:58 -04:00
|
|
|
require 'active_support/core_ext/hash/indifferent_access'
|
2010-02-16 16:54:56 -05:00
|
|
|
|
2009-12-12 19:09:44 -05:00
|
|
|
module ActionDispatch
|
|
|
|
module TestProcess
|
|
|
|
def assigns(key = nil)
|
2011-10-15 05:38:28 -04:00
|
|
|
assigns = {}.with_indifferent_access
|
2013-04-08 15:13:13 -04:00
|
|
|
@controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) }
|
2010-04-17 15:52:37 -04:00
|
|
|
key.nil? ? assigns : assigns[key]
|
2009-12-12 19:09:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def session
|
|
|
|
@request.session
|
|
|
|
end
|
|
|
|
|
|
|
|
def flash
|
|
|
|
@request.flash
|
|
|
|
end
|
|
|
|
|
|
|
|
def cookies
|
2011-03-29 19:46:27 -04:00
|
|
|
@request.cookie_jar
|
2009-12-12 19:09:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_to_url
|
|
|
|
@response.redirect_url
|
|
|
|
end
|
|
|
|
|
2012-11-26 05:18:18 -05:00
|
|
|
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionController::TestCase.fixture_path, path), type)</tt>:
|
2009-12-12 19:09:44 -05:00
|
|
|
#
|
2012-11-26 05:18:18 -05:00
|
|
|
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')
|
2009-12-12 19:09:44 -05:00
|
|
|
#
|
|
|
|
# To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
|
|
|
|
# This will not affect other platforms:
|
|
|
|
#
|
2012-11-26 05:18:18 -05:00
|
|
|
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
|
2009-12-12 19:09:44 -05:00
|
|
|
def fixture_file_upload(path, mime_type = nil, binary = false)
|
2012-11-26 05:18:18 -05:00
|
|
|
if self.class.respond_to?(:fixture_path) && self.class.fixture_path
|
|
|
|
path = File.join(self.class.fixture_path, path)
|
|
|
|
end
|
|
|
|
Rack::Test::UploadedFile.new(path, mime_type, binary)
|
2009-12-12 19:09:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|