Upgraded to Rails 2.1. This can have wide ranging consequences, so please help track down any issues introduced by the upgrade. Requires environment.rb modifications.

Changes you will need to make:

 * In your environment.rb, you will need to update references to a few files per environment.rb.tmpl
 * In your environment.rb, you will need to specify the local time zone of the computer that is running your Tracks install.

Other notes on my changes:

 * Modified our code to take advantage of Rails 2.1's slick time zone support.
 * Upgraded will_paginate for compatibility
 * Hacked the Selenium on Rails plugin, which has not been updated in some time and does not support Rails 2.1
 * Verified that all tests pass on my machine, including Selenium tests -- I'd like confirmation from others, too.
This commit is contained in:
Luke Melia 2008-06-17 01:13:25 -04:00
parent f3bae73868
commit 901a58f8a3
1086 changed files with 51452 additions and 19526 deletions

View file

@ -1,8 +1,9 @@
require 'action_controller/assertions'
require 'action_controller/test_case'
module ActionController #:nodoc:
class Base
# Process a test request called with a +TestRequest+ object.
# Process a test request called with a TestRequest object.
def self.process_test(request)
new.process_test(request)
end
@ -48,7 +49,7 @@ module ActionController #:nodoc:
# Either the RAW_POST_DATA environment variable or the URL-encoded request
# parameters.
def raw_post
env['RAW_POST_DATA'] ||= url_encoded_request_parameters
env['RAW_POST_DATA'] ||= returning(url_encoded_request_parameters) { |b| b.force_encoding(Encoding::BINARY) if b.respond_to?(:force_encoding) }
end
def port=(number)
@ -154,12 +155,12 @@ module ActionController #:nodoc:
# A refactoring of TestResponse to allow the same behavior to be applied
# to the "real" CgiResponse class in integration tests.
module TestResponseBehavior #:nodoc:
# the response code of the request
# The response code of the request
def response_code
headers['Status'][0,3].to_i rescue 0
end
# returns a String to ensure compatibility with Net::HTTPResponse
# Returns a String to ensure compatibility with Net::HTTPResponse
def code
headers['Status'].to_s.split(' ')[0]
end
@ -168,34 +169,34 @@ module ActionController #:nodoc:
headers['Status'].to_s.split(' ',2)[1]
end
# was the response successful?
# Was the response successful?
def success?
response_code == 200
end
# was the URL not found?
# Was the URL not found?
def missing?
response_code == 404
end
# were we redirected?
# Were we redirected?
def redirect?
(300..399).include?(response_code)
end
# was there a server-side error?
# Was there a server-side error?
def error?
(500..599).include?(response_code)
end
alias_method :server_error?, :error?
# returns the redirection location or nil
# Returns the redirection location or nil
def redirect_url
headers['Location']
end
# does the redirect location match this regexp pattern?
# Does the redirect location match this regexp pattern?
def redirect_url_match?( pattern )
return false if redirect_url.nil?
p = Regexp.new(pattern) if pattern.class == String
@ -204,7 +205,7 @@ module ActionController #:nodoc:
p.match(redirect_url) != nil
end
# returns the template path of the file which was used to
# Returns the template path of the file which was used to
# render this response (or nil)
def rendered_file(with_controller=false)
unless template.first_render.nil?
@ -216,50 +217,49 @@ module ActionController #:nodoc:
end
end
# was this template rendered by a file?
# Was this template rendered by a file?
def rendered_with_file?
!rendered_file.nil?
end
# a shortcut to the flash (or an empty hash if no flash.. hey! that rhymes!)
# A shortcut to the flash. Returns an empyt hash if no session flash exists.
def flash
session['flash'] || {}
end
# do we have a flash?
# Do we have a flash?
def has_flash?
!session['flash'].empty?
end
# do we have a flash that has contents?
# Do we have a flash that has contents?
def has_flash_with_contents?
!flash.empty?
end
# does the specified flash object exist?
# Does the specified flash object exist?
def has_flash_object?(name=nil)
!flash[name].nil?
end
# does the specified object exist in the session?
# Does the specified object exist in the session?
def has_session_object?(name=nil)
!session[name].nil?
end
# a shortcut to the template.assigns
# A shortcut to the template.assigns
def template_objects
template.assigns || {}
end
# does the specified template object exist?
# Does the specified template object exist?
def has_template_object?(name=nil)
!template_objects[name].nil?
end
# Returns the response cookies, converted to a Hash of (name => CGI::Cookie) pairs
# Example:
#
# assert_equal ['AuthorOfNewPage'], r.cookies['author'].value
# assert_equal ['AuthorOfNewPage'], r.cookies['author'].value
def cookies
headers['cookie'].inject({}) { |hash, cookie| hash[cookie.name] = cookie; hash }
end
@ -286,7 +286,7 @@ module ActionController #:nodoc:
def initialize(attributes = nil)
@session_id = ''
@attributes = attributes
@attributes = attributes.nil? ? nil : attributes.stringify_keys
@saved_attributes = nil
end
@ -295,11 +295,11 @@ module ActionController #:nodoc:
end
def [](key)
data[key]
data[key.to_s]
end
def []=(key, value)
data[key] = value
data[key.to_s] = value
end
def update
@ -340,6 +340,7 @@ module ActionController #:nodoc:
@content_type = content_type
@original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 }
@tempfile = Tempfile.new(@original_filename)
@tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
@tempfile.binmode if binary
FileUtils.copy_file(path, @tempfile.path)
end
@ -357,7 +358,7 @@ module ActionController #:nodoc:
module TestProcess
def self.included(base)
# execute the request simulating a specific http method and set/volley the response
# execute the request simulating a specific HTTP method and set/volley the response
%w( get post put delete head ).each do |method|
base.class_eval <<-EOV, __FILE__, __LINE__
def #{method}(action, parameters = nil, session = nil, flash = nil)
@ -373,7 +374,7 @@ module ActionController #:nodoc:
# Sanity check for required instance variables so we can give an
# understandable error message.
%w(@controller @request @response).each do |iv_name|
if !(instance_variables.include?(iv_name) || instance_variables.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
end
end
@ -464,10 +465,13 @@ module ActionController #:nodoc:
return super
end
# Shortcut for ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + path, type). Example:
# Shortcut for <tt>ActionController::TestUploadedFile.new(Test::Unit::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 :binary as the last parameter. This will not affect other platforms.
# 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)
ActionController::TestUploadedFile.new(
@ -482,17 +486,17 @@ module ActionController #:nodoc:
# with a new RouteSet instance.
#
# The new instance is yielded to the passed block. Typically the block
# will create some routes using map.draw { map.connect ... }:
# 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
# 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